| Index: tools/lexer_generator/automata_test.py
|
| diff --git a/tools/testrunner/local/junit_output.py b/tools/lexer_generator/automata_test.py
|
| similarity index 57%
|
| copy from tools/testrunner/local/junit_output.py
|
| copy to tools/lexer_generator/automata_test.py
|
| index 437adb178931f82364aa87e66315231b7b57a56d..42346a9100d0e3c8facf7b569701e030288b1e49 100644
|
| --- a/tools/testrunner/local/junit_output.py
|
| +++ b/tools/lexer_generator/automata_test.py
|
| @@ -25,25 +25,41 @@
|
| # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
| +import unittest
|
| +from regex_parser import RegexParser
|
| +from nfa import NfaBuilder
|
| +from dfa import Dfa
|
|
|
| -import xml.etree.ElementTree as xml
|
| +def build_automata(string):
|
| + parser = RegexParser()
|
| + parser.build()
|
| + graph = parser.parse(string)
|
| + nfa = NfaBuilder().nfa(graph)
|
| + (start_name, dfa_nodes, end_nodes) = nfa.compute_dfa()
|
| + dfa = Dfa(start_name, dfa_nodes, end_nodes)
|
| + return (nfa, dfa)
|
|
|
| +class AutomataTestCase(unittest.TestCase):
|
|
|
| -class JUnitTestOutput:
|
| - def __init__(self, test_suite_name):
|
| - self.root = xml.Element("testsuite")
|
| - self.root.attrib["name"] = test_suite_name
|
| + # (pattern, should match, shouldn't match)
|
| + __test_data = [
|
| + ("a", ["a"], ["b"]),
|
| + ("ab", ["ab"], ["bb"]),
|
| + ("a+b", ["ab", "aab", "aaab"], ["a", "b"]),
|
| + ("a?b", ["ab", "b"], ["a", "c"]),
|
| + ("a*b", ["ab", "aaab", "b"], ["a", "c"]),
|
| + ("a|b", ["a", "b"], ["ab", "c"]),
|
| + ]
|
|
|
| - def HasRunTest(self, test_name, test_duration, test_failure):
|
| - testCaseElement = xml.Element("testcase")
|
| - testCaseElement.attrib["name"] = " ".join(test_name)
|
| - testCaseElement.attrib["time"] = str(round(test_duration, 3))
|
| - if len(test_failure):
|
| - failureElement = xml.Element("failure")
|
| - failureElement.text = test_failure
|
| - testCaseElement.append(failureElement)
|
| - self.root.append(testCaseElement)
|
| -
|
| - def FinishAndWrite(self, file):
|
| - xml.ElementTree(self.root).write(file, "UTF-8")
|
| + def test_matches(self):
|
| + for (regex, matches, not_matches) in AutomataTestCase.__test_data:
|
| + (nfa, dfa) = build_automata(regex)
|
| + for string in matches:
|
| + self.assertTrue(nfa.matches(string))
|
| + self.assertTrue(dfa.matches(string))
|
| + for string in not_matches:
|
| + self.assertFalse(nfa.matches(string))
|
| + self.assertFalse(dfa.matches(string))
|
|
|
| +if __name__ == '__main__':
|
| + unittest.main()
|
|
|