def test_if_elif_block(self): 'If-elif block chaining test' data = 'if a > 1:\n f()\n 1+2\nelif b < 2:\n 3 + 4' self.assertEqual( parser.parse(data), [('if', ('comparison', ['>'], ['a', 1]), [ ('func', 'f', [], []), ('+', 1, 2) ], [('if', ('comparison', ['<'], ['b', 2]), [('+', 3, 4)], [])])])
def test_if_block(self): 'If block parsing test' data = 'if a > 1:\n f()\n 1+2' self.assertEqual( parser.parse(data), [('if', ('comparison', ['>'], ['a', 1]), [('func', 'f', [], []), ('+', 1, 2)], [])])
def test_while_block_2(self): 'While block parsing test' data = 'while (a > 1):\n f()\n 1+2' self.assertEqual(parser.parse(data), [( 'while', ('comparison', ['>'], ['a', 1]), [('func', 'f', [], []), ('+', 1, 2)], )])
def test_comparison(self): 'Comparison parsing test' data = '1 < 2 + 3' self.assertEqual(parser.parse(data), [( 'comparison', ['<'], [1, ('+', 2, 3)], )])
def test_comparison_chain(self): 'Comparison chain parsing test' data = '1 < 2 + 3 <= 4 * 5 > 2' self.assertEqual(parser.parse(data), [( 'comparison', ['<', '<=', '>'], [1, ('+', 2, 3), ('*', 4, 5), 2], )])
def test_block(self): 'Block parsing test' data = 'f(a)\nb=1+2\nc\nreturn d' self.assertEqual(parser.parse(data), [ ('func', 'f', ['a'], []), ('assign', 'b', ('+', 1, 2)), 'c', ('return', 'd'), ])
def test_block(self): 'Block parsing test' data = 'f(a)\nb=1+2\nc\nreturn d' self.assertEqual( parser.parse(data), [ ('func', 'f', ['a'], []), ('assign', 'b', ('+', 1, 2)), 'c', ('return', 'd'), ])
def test_while_block_2(self): 'While block parsing test' data = 'while (a > 1):\n f()\n 1+2' self.assertEqual( parser.parse(data), [('while', ('comparison', ['>'], ['a', 1]), [ ('func', 'f', [], []), ('+', 1, 2) ], )])
def test_funcparam(self): 'Function parameters test' data = 'f()\nf(1)\nf(1,)\nf(1,2)\nf(a=1)\nf(a=1,)\nf(a=1,b=2)\nf(1,2,a=1,b=2)' self.assertEqual(parser.parse(data), [ ('func', 'f', [], []), ('func', 'f', [1], []), ('func', 'f', [1], []), ('func', 'f', [1, 2], []), ('func', 'f', [], [('assign', 'a', 1)]), ('func', 'f', [], [('assign', 'a', 1)]), ('func', 'f', [], [('assign', 'a', 1), ('assign', 'b', 2)]), ('func', 'f', [1, 2], [('assign', 'a', 1), ('assign', 'b', 2)]), ])
def test_if_block(self): 'If block parsing test' data = 'if a > 1:\n f()\n 1+2' self.assertEqual( parser.parse(data), [('if', ('comparison', ['>'], ['a', 1]), [ ('func', 'f', [], []), ('+', 1, 2) ], [] )])
def test_comparison(self): 'Comparison parsing test' data = '1 < 2 + 3' self.assertEqual( parser.parse(data), [('comparison', ['<'], [ 1, ('+', 2, 3 ) ], )])
def test_funcparam(self): 'Function parameters test' data = 'f()\nf(1)\nf(1,)\nf(1,2)\nf(a=1)\nf(a=1,)\nf(a=1,b=2)\nf(1,2,a=1,b=2)' self.assertEqual( parser.parse(data), [ ('func', 'f', [], []), ('func', 'f', [1], []), ('func', 'f', [1], []), ('func', 'f', [1, 2], []), ('func', 'f', [], [('assign', 'a', 1)]), ('func', 'f', [], [('assign', 'a', 1)]), ('func', 'f', [], [('assign', 'a', 1), ('assign', 'b', 2)]), ('func', 'f', [1, 2], [('assign', 'a', 1), ('assign', 'b', 2)]), ])
def test_expression(self): 'Expression parsing test' data = '1 + (2 + 3) * -4 + f(5) + ()' self.assertEqual( parser.parse(data), [('+', ('+', ('+', 1, ('*', ('+', 2, 3), ('neg', 4) ) ), ('func', 'f', [5], []) ), ('tuple', []) )])
def test_comparison_chain(self): 'Comparison chain parsing test' data = '1 < 2 + 3 <= 4 * 5 > 2' self.assertEqual( parser.parse(data), [('comparison', ['<', '<=', '>'], [ 1, ('+', 2, 3 ), ('*', 4, 5 ), 2 ], )])
def test_if_elif_block(self): 'If-elif block chaining test' data = 'if a > 1:\n f()\n 1+2\nelif b < 2:\n 3 + 4' self.assertEqual( parser.parse(data), [('if', ('comparison', ['>'], ['a', 1]), [ ('func', 'f', [], []), ('+', 1, 2) ], [ ('if', ('comparison', ['<'], ['b', 2]), [ ('+', 3, 4) ], [] ) ] )])
def test_expression(self): 'Expression parsing test' data = '1 + (2 + 3) * -4 + f(5) + ()' self.assertEqual(parser.parse(data), [('+', ('+', ('+', 1, ('*', ('+', 2, 3), ('neg', 4))), ('func', 'f', [5], [])), ('tuple', []))])