Ejemplo n.º 1
0
def check_token(code, tokens):
    """Make sure that all tokens appears in code in order"""
    lx = XonshLexer()
    tks = list(lx.get_tokens(code))

    for tk in tokens:
        while tks:
            if tk == tks[0]:
                break
            tks = tks[1:]
        else:
            msg = "Token {!r} missing: {!r}".format(tk, list(lx.get_tokens(code)))
            pytest.fail(msg)
            break
Ejemplo n.º 2
0
def check_token(code, tokens):
    """Make sure that all tokens appears in code in order"""
    lx = XonshLexer()
    tks = list(lx.get_tokens(code))

    for tk in tokens:
        while tks:
            if tk == tks[0]:
                break
            tks = tks[1:]
        else:
            msg = "Token {!r} missing: {!r}".format(tk, list(lx.get_tokens(code)))
            pytest.fail(msg)
            break
Ejemplo n.º 3
0
    def factory(code, tokens):
        """Make sure that all tokens appears in code in order"""
        lx = XonshLexer()
        tks = list(lx.get_tokens(code))

        for tk in tokens:
            while tks:
                if tk == tks[0]:
                    break
                tks = tks[1:]
            else:
                msg = f"Token {tk!r} missing: {list(lx.get_tokens(code))!r}"
                pytest.fail(msg)
                break
Ejemplo n.º 4
0
def render_colors():
    source = ("import sys\n"
              'echo "Welcome $USER on" @(sys.platform)\n\n'
              "def func(x=42):\n"
              '    d = {"xonsh": True}\n'
              '    return d.get("xonsh") and you\n\n'
              "# This is a comment\n"
              "![env | uniq | sort | grep PATH]\n")
    lexer = XonshLexer()
    lexer.add_filter("tokenmerge")
    token_stream = list(pygments.lex(source, lexer=lexer))
    token_stream = [(t, s.replace("\n", "\\n")) for t, s in token_stream]
    styles = sorted(get_all_styles())
    styles.insert(0, styles.pop(styles.index("default")))
    for style in styles:
        try:
            display = html_format(token_stream, style=style)
        except Exception as ex:
            logging.error(f"Failed to format Xonsh code {ex!r}. {style!r}",
                          exc_info=True)
            display = source
        yield style, escape(display)