コード例 #1
0
class BashSessionTest(unittest.TestCase):
    def setUp(self):
        self.lexer = BashSessionLexer()
        self.maxDiff = None

    def testNeedsName(self):
        fragment = u'$ echo \\\nhi\nhi\n'
        tokens = [
            (Token.Text, u''),
            (Token.Generic.Prompt, u'$'),
            (Token.Text, u' '),
            (Token.Name.Builtin, u'echo'),
            (Token.Text, u' '),
            (Token.Literal.String.Escape, u'\\\n'),
            (Token.Text, u'hi'),
            (Token.Text, u'\n'),
            (Token.Generic.Output, u'hi\n'),
        ]
        self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))
コード例 #2
0
ファイル: test_shell.py プロジェクト: sol/pygments
class BashSessionTest(unittest.TestCase):

    def setUp(self):
        self.lexer = BashSessionLexer()
        self.maxDiff = None

    def testNeedsName(self):
        fragment = u'$ echo \\\nhi\nhi\n'
        tokens = [
            (Token.Text, u''),
            (Token.Generic.Prompt, u'$'),
            (Token.Text, u' '),
            (Token.Name.Builtin, u'echo'),
            (Token.Text, u' '),
            (Token.Literal.String.Escape, u'\\\n'),
            (Token.Text, u'hi'),
            (Token.Text, u'\n'),
            (Token.Generic.Output, u'hi\n'),
        ]
        self.assertEqual(tokens, list(self.lexer.get_tokens(fragment)))
コード例 #3
0
ファイル: bash_tokens.py プロジェクト: johanvergeer/purdy
#!/usr/bin/env python

import argparse

from pygments.lexers import BashSessionLexer

# =============================================================================

parser = argparse.ArgumentParser(
    description=('Prints out the tokens '
                 'generated by pygments.lexers.BashSessionLexer'))
parser.add_argument('files',
                    type=str,
                    nargs='+',
                    help='One or more file names to lex and parse')

args = parser.parse_args()

# --- Do the parsing

lexer = BashSessionLexer()
with open(args.files[0]) as f:
    contents = f.read()

for token, text in lexer.get_tokens(contents):
    if text == '\n':
        text = '\\n'

    print('%s: %s' % (token, text))