Commit a3f51c06 authored by Igor Dejanovic's avatar Igor Dejanovic

Updating tests

parent 8f2ef644
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)*-45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
45-4*(23+7.45-67*32.3)/67*45.56-129.67*(343-56+33.4/45)
# -*- coding: utf-8 -*-
#######################################################################
# Name: test_speed
# Purpose: Performance test of arpeggio parser
# Author: Igor R. Dejanović <igor DOT dejanovic AT gmail DOT com>
# Copyright: (c) 2014 Igor R. Dejanović <igor DOT dejanovic AT gmail DOT com>
# License: MIT License
#######################################################################
import timeit, sys
if __name__ == "__main__":
setup = '''
from arpeggio import OneOrMore, ZeroOrMore, EndOfFile, ParserPython, Optional
from arpeggio import RegExMatch as _
def number(): return _(r'\d*\.\d*|\d+')
def factor(): return [(Optional(["+","-"]), number), ("(", expression, ")")]
def term(): return factor, ZeroOrMore(["*","/"], factor)
def expression(): return term, ZeroOrMore(["+", "-"], term)
def calcfile(): return OneOrMore(expression), EndOfFile
parser = ParserPython(calcfile, reduce_tree=True)
with open("input.txt", "r") as f:
input = f.read()
'''
print timeit.timeit("parser.parse(input)", setup=setup, number=20)
# 7.06 s
......@@ -22,7 +22,7 @@ class TestDecoratorCombine(TestCase):
# This will result in Terminal node
def my_rule(): return Combine(ZeroOrMore("a"), OneOrMore("b"))
parser = ParserPython(root, debug=True)
parser = ParserPython(root)
input1 = "abbb."
......
......@@ -12,7 +12,7 @@ from unittest import TestCase
from arpeggio.export import PMDOTExporter, PTDOTExporter
# Grammar
from arpeggio import Optional, ZeroOrMore, OneOrMore, EndOfFile, ParserPython, Sequence, NonTerminal
from arpeggio import Optional, ZeroOrMore, OneOrMore, EOF , ParserPython, Sequence, NonTerminal
from arpeggio import RegExMatch as _
......@@ -21,7 +21,7 @@ def factor(): return Optional(["+","-"]), [number,
("(", expression, ")")]
def term(): return factor, ZeroOrMore(["*","/"], factor)
def expression(): return term, ZeroOrMore(["+", "-"], term)
def calc(): return OneOrMore(expression), EndOfFile
def calc(): return OneOrMore(expression), EOF
class TestPythonParser(TestCase):
......
......@@ -21,7 +21,7 @@ class TestParsingExpression(TestCase):
parsed = parser.parse("a b c")
self.assertEqual(str(parsed), "abc")
self.assertEqual(str(parsed), "a | b | c")
self.assertEqual(repr(parsed), "[ 'a' [0], 'b' [2], 'c' [4] ]")
def test_ordered_choice(self):
......@@ -32,11 +32,11 @@ class TestParsingExpression(TestCase):
parsed = parser.parse("b")
self.assertEqual(str(parsed), "b")
self.assertEqual(str(parsed), "b | ")
self.assertEqual(repr(parsed), "[ 'b' [0], EOF [1] ]")
parsed = parser.parse("c")
self.assertEqual(str(parsed), "c")
self.assertEqual(str(parsed), "c | ")
self.assertEqual(repr(parsed), "[ 'c' [0], EOF [1] ]")
self.assertRaises(NoMatch, lambda: parser.parse("ab"))
......@@ -50,13 +50,13 @@ class TestParsingExpression(TestCase):
parsed = parser.parse("aaaaaaa")
self.assertEqual(str(parsed), "aaaaaaa")
self.assertEqual(str(parsed), "a | a | a | a | a | a | a | ")
self.assertEqual(repr(parsed), "[ 'a' [0], 'a' [1], 'a' [2], 'a' [3], 'a' [4], 'a' [5], 'a' [6], EOF [7] ]")
parsed = parser.parse("")
self.assertEqual(str(parsed), "")
self.assertEqual(repr(parsed), "[ EOF [0] ]")
self.assertEqual(repr(parsed), "EOF [0]")
self.assertRaises(NoMatch, lambda: parser.parse("bbb"))
......@@ -68,7 +68,7 @@ class TestParsingExpression(TestCase):
parsed = parser.parse("aaaaaaa")
self.assertEqual(str(parsed), "aaaaaaa")
self.assertEqual(str(parsed), "a | a | a | a | a | a | a")
self.assertEqual(repr(parsed), "[ 'a' [0], 'a' [1], 'a' [2], 'a' [3], 'a' [4], 'a' [5], 'a' [6] ]")
self.assertRaises(NoMatch, lambda: parser.parse(""))
......@@ -82,12 +82,12 @@ class TestParsingExpression(TestCase):
parsed = parser.parse("ab")
self.assertEqual(str(parsed), "ab")
self.assertEqual(str(parsed), "a | b | ")
self.assertEqual(repr(parsed), "[ 'a' [0], 'b' [1], EOF [2] ]")
parsed = parser.parse("b")
self.assertEqual(str(parsed), "b")
self.assertEqual(str(parsed), "b | ")
self.assertEqual(repr(parsed), "[ 'b' [0], EOF [1] ]")
self.assertRaises(NoMatch, lambda: parser.parse("aab"))
......@@ -103,7 +103,7 @@ class TestParsingExpression(TestCase):
parser = ParserPython(grammar)
parsed = parser.parse("ab")
self.assertEqual(str(parsed), "ab")
self.assertEqual(str(parsed), "a | b | ")
self.assertEqual(repr(parsed), "[ 'a' [0], 'b' [1], EOF [2] ]")
# 'And' will try to match 'b' and fail so 'c' will never get matched
......@@ -119,7 +119,7 @@ class TestParsingExpression(TestCase):
parsed = parser.parse("ac")
self.assertEqual(str(parsed), "ac")
self.assertEqual(str(parsed), "a | c | ")
self.assertEqual(repr(parsed), "[ 'a' [0], 'c' [1], EOF [2] ]")
# Not will will fail on 'b'
......
......@@ -37,8 +37,8 @@ class TestPEGParser(TestCase):
result = parser.parse(input)
self.assertTrue(isinstance(result, NonTerminal))
self.assertEqual(str(result), "4+5*7/3.45*-45*(2.56+32)/-56*(2-1.34)")
self.assertEqual(repr(result), "[ [ [ [ number '4' [0] ] ], '+' [1], [ [ number '5' [2] ], '*' [3], [ number '7' [4] ], '/' [5], [ number '3.45' [6] ], '*' [10], [ '-' [11], number '45' [12] ], '*' [14], [ '(' [15], [ [ [ number '2.56' [16] ] ], '+' [20], [ [ number '32' [21] ] ] ], ')' [23] ], '/' [24], [ '-' [25], number '56' [26] ], '*' [28], [ '(' [29], [ [ [ number '2' [30] ] ], '-' [31], [ [ number '1.34' [32] ] ] ], ')' [36] ] ] ], EOF [37] ]")
self.assertEqual(str(result), "4 | + | 5 | * | 7 | / | 3.45 | * | - | 45 | * | ( | 2.56 | + | 32 | ) | / | - | 56 | * | ( | 2 | - | 1.34 | ) | ")
self.assertEqual(repr(result),"[ [ number '4' [0], '+' [1], [ number '5' [2], '*' [3], number '7' [4], '/' [5], number '3.45' [6], '*' [10], [ '-' [11], number '45' [12] ], '*' [14], [ '(' [15], [ number '2.56' [16], '+' [20], number '32' [21] ], ')' [23] ], '/' [24], [ '-' [25], number '56' [26] ], '*' [28], [ '(' [29], [ number '2' [30], '-' [31], number '1.34' [32] ], ')' [36] ] ] ], EOF [37] ]")
def test_reduce_tree(self):
......@@ -48,5 +48,5 @@ class TestPEGParser(TestCase):
self.assertTrue(isinstance(result, NonTerminal))
self.assertEqual(str(result),"4+5*7/3.45*-45*(2.56+32)/-56*(2-1.34)")
self.assertEqual(str(result),"4 | + | 5 | * | 7 | / | 3.45 | * | - | 45 | * | ( | 2.56 | + | 32 | ) | / | - | 56 | * | ( | 2 | - | 1.34 | ) | ")
self.assertEqual(repr(result), "[ [ number '4' [0], '+' [1], [ number '5' [2], '*' [3], number '7' [4], '/' [5], number '3.45' [6], '*' [10], [ '-' [11], number '45' [12] ], '*' [14], [ '(' [15], [ number '2.56' [16], '+' [20], number '32' [21] ], ')' [23] ], '/' [24], [ '-' [25], number '56' [26] ], '*' [28], [ '(' [29], [ number '2' [30], '-' [31], number '1.34' [32] ], ')' [36] ] ] ], EOF [37] ]")
......@@ -10,7 +10,8 @@
from unittest import TestCase
# Grammar
from arpeggio import Optional, ZeroOrMore, OneOrMore, EndOfFile, ParserPython, Sequence, NonTerminal
from arpeggio import Optional, ZeroOrMore, OneOrMore, EOF, ParserPython,\
Sequence, NonTerminal
from arpeggio import RegExMatch as _
......@@ -19,7 +20,7 @@ def factor(): return Optional(["+","-"]), [number,
("(", expression, ")")]
def term(): return factor, ZeroOrMore(["*","/"], factor)
def expression(): return term, ZeroOrMore(["+", "-"], term)
def calc(): return OneOrMore(expression), EndOfFile
def calc(): return OneOrMore(expression), EOF
class TestPythonParser(TestCase):
......@@ -41,8 +42,8 @@ class TestPythonParser(TestCase):
result = parser.parse(input)
self.assertTrue(isinstance(result, NonTerminal))
self.assertEqual(str(result), "4+5*7/3.45*-45*(2.56+32)/-56*(2-1.34)")
self.assertEqual(repr(result), "[ [ [ [ number '4' [0] ] ], '+' [1], [ [ number '5' [2] ], '*' [3], [ number '7' [4] ], '/' [5], [ number '3.45' [6] ], '*' [10], [ '-' [11], number '45' [12] ], '*' [14], [ '(' [15], [ [ [ number '2.56' [16] ] ], '+' [20], [ [ number '32' [21] ] ] ], ')' [23] ], '/' [24], [ '-' [25], number '56' [26] ], '*' [28], [ '(' [29], [ [ [ number '2' [30] ] ], '-' [31], [ [ number '1.34' [32] ] ] ], ')' [36] ] ] ], EOF [37] ]")
self.assertEqual(str(result), "4 | + | 5 | * | 7 | / | 3.45 | * | - | 45 | * | ( | 2.56 | + | 32 | ) | / | - | 56 | * | ( | 2 | - | 1.34 | ) | ")
self.assertEqual(repr(result), "[ [ number '4' [0], '+' [1], [ number '5' [2], '*' [3], number '7' [4], '/' [5], number '3.45' [6], '*' [10], [ '-' [11], number '45' [12] ], '*' [14], [ '(' [15], [ number '2.56' [16], '+' [20], number '32' [21] ], ')' [23] ], '/' [24], [ '-' [25], number '56' [26] ], '*' [28], [ '(' [29], [ number '2' [30], '-' [31], number '1.34' [32] ], ')' [36] ] ] ], EOF [37] ]")
def test_reduce_tree(self):
......@@ -52,6 +53,6 @@ class TestPythonParser(TestCase):
self.assertTrue(isinstance(result, NonTerminal))
self.assertEqual(str(result),"4+5*7/3.45*-45*(2.56+32)/-56*(2-1.34)")
self.assertEqual(str(result),"4 | + | 5 | * | 7 | / | 3.45 | * | - | 45 | * | ( | 2.56 | + | 32 | ) | / | - | 56 | * | ( | 2 | - | 1.34 | ) | ")
self.assertEqual(repr(result), "[ [ number '4' [0], '+' [1], [ number '5' [2], '*' [3], number '7' [4], '/' [5], number '3.45' [6], '*' [10], [ '-' [11], number '45' [12] ], '*' [14], [ '(' [15], [ number '2.56' [16], '+' [20], number '32' [21] ], ')' [23] ], '/' [24], [ '-' [25], number '56' [26] ], '*' [28], [ '(' [29], [ number '2' [30], '-' [31], number '1.34' [32] ], ')' [36] ] ] ], EOF [37] ]")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment