diff options
author | gbrandl <devnull@localhost> | 2007-05-03 18:23:03 +0200 |
---|---|---|
committer | gbrandl <devnull@localhost> | 2007-05-03 18:23:03 +0200 |
commit | e130dbff2eb591c7cdca4a0bef90b63502cd3d4e (patch) | |
tree | fcb7f3140464f1be96ff5a119c154b3ace677df4 /tests/test_basic_api.py | |
parent | 2af8e713b4d89c8961c419db4818f11d43030643 (diff) | |
download | pygments-e130dbff2eb591c7cdca4a0bef90b63502cd3d4e.tar.gz |
[svn] Add whitespace filter. Add a few more filter unit tests.
Diffstat (limited to 'tests/test_basic_api.py')
-rw-r--r-- | tests/test_basic_api.py | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/tests/test_basic_api.py b/tests/test_basic_api.py index d05a29c5..805f3104 100644 --- a/tests/test_basic_api.py +++ b/tests/test_basic_api.py @@ -71,15 +71,43 @@ class LexersTest(unittest.TestCase): a(isinstance(x, lexers.PythonLexer)) ae(x.options["opt"], "val") - def test_filters(self): + +class FiltersTest(unittest.TestCase): + + def test_basic(self): + filter_args = { + 'whitespace': {'spaces': True, 'tabs': True, 'newlines': True}, + 'highlight': {'names': ['isinstance', 'lexers', 'x']}, + } for x in filters.FILTERS.keys(): lx = lexers.PythonLexer() - lx.add_filter(x) + lx.add_filter(x, **filter_args.get(x, {})) text = file(os.path.join(testdir, testfile)).read().decode('utf-8') tokens = list(lx.get_tokens(text)) roundtext = ''.join([t[1] for t in tokens]) - self.assertEquals(roundtext, text, - "lexer roundtrip with %s filter failed" % x) + if x not in ('whitespace', 'keywordcase'): + # these filters change the text + self.assertEquals(roundtext, text, + "lexer roundtrip with %s filter failed" % x) + + def test_raiseonerror(self): + lx = lexers.PythonLexer() + lx.add_filter('raiseonerror', excclass=RuntimeError) + self.assertRaises(RuntimeError, list, lx.get_tokens('$')) + + def test_whitespace(self): + lx = lexers.PythonLexer() + lx.add_filter('whitespace', spaces='%') + text = file(os.path.join(testdir, testfile)).read().decode('utf-8') + lxtext = ''.join([t[1] for t in list(lx.get_tokens(text))]) + self.failIf(' ' in lxtext) + + def test_keywordcase(self): + lx = lexers.PythonLexer() + lx.add_filter('keywordcase', case='capitalize') + text = file(os.path.join(testdir, testfile)).read().decode('utf-8') + lxtext = ''.join([t[1] for t in list(lx.get_tokens(text))]) + self.assert_('Def' in lxtext and 'Class' in lxtext) class FormattersTest(unittest.TestCase): |