diff options
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | pygments/cmdline.py | 7 | ||||
-rw-r--r-- | pygments/lexer.py | 10 | ||||
-rw-r--r-- | tests/test_cmdline.py | 4 | ||||
-rw-r--r-- | tests/test_token.py | 51 |
5 files changed, 68 insertions, 7 deletions
@@ -5,6 +5,9 @@ Version 0.8 (in development) ---------------------------- (codename to be selected, released Apr XX, 2007) +- Fixed a bug in the command line code that disallowed ``-O`` options + when using the ``-S`` option. + - The `get_style_defs` method of HTML formatters now uses the `cssclass` option as the default selector if it was given. diff --git a/pygments/cmdline.py b/pygments/cmdline.py index 26586ec5..0801eab0 100644 --- a/pygments/cmdline.py +++ b/pygments/cmdline.py @@ -239,8 +239,7 @@ def main(args): # parse -O options O_opts = _parse_options(O_opts) - # parse -F options - F_opts = _parse_filters(F_opts) + opts.pop('-O', None) # handle ``pygmentize -S`` S_opt = opts.pop('-S', None) @@ -270,6 +269,10 @@ def main(args): print >>sys.stderr, usage return 2 + # parse -F options + F_opts = _parse_filters(F_opts) + opts.pop('-F', None) + # select formatter outfn = opts.pop('-o', None) fmter = opts.pop('-f', None) diff --git a/pygments/lexer.py b/pygments/lexer.py index 709587d7..0c28cf3e 100644 --- a/pygments/lexer.py +++ b/pygments/lexer.py @@ -364,7 +364,7 @@ class RegexLexerMeta(LexerMeta): assert type(tdef) is tuple, "wrong rule def %r" % tdef - rex = re.compile(tdef[0], rflags) + rex = re.compile(tdef[0], rflags).match assert type(tdef[1]) is _TokenType or callable(tdef[1]), \ 'token type must be simple type or callable, not %r' % tdef[1] @@ -457,8 +457,8 @@ class RegexLexer(Lexer): statestack = list(stack) statetokens = self._tokens[statestack[-1]] while 1: - for rex, action, new_state in statetokens: - m = rex.match(text, pos) + for rexmatch, action, new_state in statetokens: + m = rexmatch(text, pos) if m: # print rex.pattern if type(action) is _TokenType: @@ -529,8 +529,8 @@ class ExtendedRegexLexer(RegexLexer): statetokens = self._tokens[ctx.stack[-1]] text = ctx.text while 1: - for rex, action, new_state in statetokens: - m = rex.match(text, ctx.pos, ctx.end) + for rexmatch, action, new_state in statetokens: + m = rexmatch(text, ctx.pos, ctx.end) if m: if type(action) is _TokenType: yield ctx.pos, action, m.group() diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index f524e976..00572d96 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -62,6 +62,10 @@ class CmdLineTest(unittest.TestCase): self.assertEquals(c, 0) self.assert_('HTML' in o) + def test_S_opt(self): + c, o, e = run_cmdline("-S", "default", "-f", "html", "-O", "linenos=1") + self.assertEquals(c, 0) + def test_invalid_opts(self): for opts in [("-L", "-lpy"), ("-L", "-fhtml"), ("-L", "-Ox"), ("-a",), ("-Sst", "-lpy"), ("-H",), diff --git a/tests/test_token.py b/tests/test_token.py new file mode 100644 index 00000000..ac57126c --- /dev/null +++ b/tests/test_token.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +""" + Test suite for the token module + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + :copyright: 2006-2007 by Georg Brandl. + :license: BSD, see LICENSE for more details. +""" + +import unittest +import StringIO +import sys + +from pygments import token + + +class TokenTest(unittest.TestCase): + + def test_tokentype(self): + e = self.assertEquals + r = self.assertRaises + + t = token.String + + e(t.split(), [token.Token, token.Literal, token.String]) + + e(t.__class__, token._TokenType) + + def test_functions(self): + self.assert_(token.is_token_subtype(token.String, token.String)) + self.assert_(token.is_token_subtype(token.String, token.Literal)) + self.failIf(token.is_token_subtype(token.Literal, token.String)) + + self.assert_(token.string_to_tokentype(token.String) is token.String) + self.assert_(token.string_to_tokentype('') is token.Token) + self.assert_(token.string_to_tokentype('String') is token.String) + + def test_sanity_check(self): + try: + try: + old_stdout = sys.stdout + sys.stdout = StringIO.StringIO() + execfile(token.__file__.rstrip('c'), {'__name__': '__main__'}) + finally: + sys.stdout = old_stdout + except SystemExit: + pass + + +if __name__ == '__main__': + unittest.main() |