summaryrefslogtreecommitdiff
path: root/tests/test_regexopt.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2014-09-20 00:12:54 +0200
committerGeorg Brandl <georg@python.org>2014-09-20 00:12:54 +0200
commitf7219e7b8b5236db12e077ba36f54182cd665941 (patch)
tree7a65d7f54e5f9b36a1b3342c79a1eb06a8198878 /tests/test_regexopt.py
parentac4a2c47e625fdc12d83a07d360d678abd39af62 (diff)
parent33cb0a84a19b4e96d694eb99b490346f20e315d7 (diff)
downloadpygments-f7219e7b8b5236db12e077ba36f54182cd665941.tar.gz
Merged in pchaigno/pygments-main/prolog-ecl (pull request #374)
Diffstat (limited to 'tests/test_regexopt.py')
-rw-r--r--tests/test_regexopt.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/test_regexopt.py b/tests/test_regexopt.py
new file mode 100644
index 00000000..5dc8f9af
--- /dev/null
+++ b/tests/test_regexopt.py
@@ -0,0 +1,39 @@
+# -*- coding: utf-8 -*-
+"""
+ Tests for pygments.regexopt
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+import random
+import unittest
+import itertools
+
+from pygments.regexopt import regex_opt
+
+ALPHABET = ['a', 'b', 'c', 'd', 'e']
+N_TRIES = 15
+
+
+class RegexOptTestCase(unittest.TestCase):
+
+ def generate_keywordlist(self, length):
+ return [''.join(p) for p in
+ itertools.combinations_with_replacement(ALPHABET, length)]
+
+ def test_randomly(self):
+ # generate a list of all possible keywords of a certain length using
+ # a restricted alphabet, then choose some to match and make sure only
+ # those do
+ for n in range(3, N_TRIES):
+ kwlist = self.generate_keywordlist(n)
+ to_match = random.sample(kwlist,
+ random.randint(1, len(kwlist) - 1))
+ no_match = set(kwlist) - set(to_match)
+ rex = regex_opt(to_match, True)
+ for w in to_match:
+ self.assertTrue(rex.match(w))
+ for w in no_match:
+ self.assertFalse(rex.match(w))