def test_BINAND(self): tree = parse(" 1 || 0 && 2 || 3 && 4") assert tree == Module.construct( body=( Operation.construct( op="&&", arguments=( Operation.construct( op="||", arguments=( Operation.construct( op="&&", arguments=( Operation.construct( op="||", arguments=(Int(value="1"), Int(value="0")), ), Int(value="2"), ), ), Int(value="3"), ), ), Int(value="4"), ), ), ) )
def test_IF(self): tree = parse(' if 1 && 10 || 101 - 77 {output("foobars are nutritious")}') assert tree == Module.construct( body=( IfStatement.construct( conditionals=( ( Operation.construct( op="||", arguments=( Operation.construct( op="&&", arguments=(Int(value="1"), Int(value="10")), ), Operation.construct( op="-", arguments=(Int(value="101"), Int(value="77")), ), ), ), ( Call.construct( target=Namespace(name="output", ctx="load"), args=(String(value="foobars are nutritious"),), kwargs={}, ), ), ), ), default=None, ), ) )
def test_PREFIX_SIGNS(self): tree = parse(" + ( 0 - -2 % -3 )") assert tree == Module( body=( Operation( op="+", arguments=( Operation( op="-", arguments=( Int(value="0"), Operation( op="-", arguments=( Operation( op="%", arguments=( Int(value="2"), Operation( op="-", arguments=(Int(value="3"),), ), ), ), ), ), ), ), ), ), ) )
def test_MINUS(self): tree = parse("1 - (2 - 3) -2 + 4") assert tree == Module.construct( body=( Operation.construct( op="+", arguments=( Operation.construct( op="-", arguments=( Operation.construct( op="-", arguments=( Int(value="1"), Operation.construct( op="-", arguments=(Int(value="2"), Int(value="3")), ), ), ), Int(value="2"), ), ), Int(value="4"), ), ), ) )
def test_IF_ELSE(self): tree = parse("if True {2} else {3} ") assert tree == Module( body=( IfStatement( conditionals=((Bool(value="True"), (Int(value="2"),)),), default=(Int(value="3"),), ), ) )
def test_TUPLE(self): tree = parse("((1,), (1), (1, ()))") assert tree == Module.construct( body=( Tuple( items=( Tuple(items=(Int(value="1"),)), Int(value="1"), Tuple(items=(Int(value="1"), Tuple(items=()))), ) ), ) )
def test_LIST(self): tree = parse("[1]; [1,2]; [1, [1, [1, [1]]]]; []") assert tree == Module.construct( body=( List(items=(Int(value="1"),)), List(items=(Int(value="1"), Int(value="2"))), List( items=( Int(value="1"), List( items=( Int(value="1"), List( items=( Int(value="1"), List(items=(Int(value="1"),)), ) ), ) ), ) ), List(items=()), ) )
def test_FOR(self): tree = parse("for _v1_ in [1,2,3,4,5,] {pass}") assert tree == Module.construct( body=( ForLoop.construct( target=Namespace(name="_v1_", ctx="store"), iterator=List( items=( Int(value="1"), Int(value="2"), Int(value="3"), Int(value="4"), Int(value="5"), ) ), orelse=None, body=(Pass(),), ), ) )
def test_DICT(self): tree = parse("{'a': {1: 2, 3: 4}, \"123\": {}}") assert tree == Module.construct( body=( Dict( items=( ( Char(value="a"), Dict( items=( (Int(value="1"), Int(value="2")), (Int(value="3"), Int(value="4")), ) ), ), (String(value="123"), Dict(items=())), ) ), ) )
def test_PLUS(self): tree = parse("1 + 2 + 3 + 4") assert tree == Module.construct( body=( Operation.construct( op="+", arguments=( Operation.construct( op="+", arguments=( Operation.construct( op="+", arguments=(Int(value="1"), Int(value="2")) ), Int(value="3"), ), ), Int(value="4"), ), ), ) )
def test_BINXOR(self): tree = parse("1010 ^ 10 ^ 123456789 || 2 && 3 - 2") assert tree == Module.construct( body=( Operation.construct( op="&&", arguments=( Operation.construct( op="||", arguments=( Operation.construct( op="^", arguments=( Operation.construct( op="^", arguments=( Int(value="1010"), Int(value="10"), ), ), Int(value="123456789"), ), ), Int(value="2"), ), ), Operation.construct( op="-", arguments=(Int(value="3"), Int(value="2")) ), ), ), ) )
def test_TIMES(self): tree = parse("2 * (2 - 5) + 4 * 3 + 7") assert tree == Module.construct( body=( Operation.construct( op="+", arguments=( Operation.construct( op="+", arguments=( Operation.construct( op="*", arguments=( Int(value="2"), Operation.construct( op="-", arguments=(Int(value="2"), Int(value="5")), ), ), ), Operation.construct( op="*", arguments=(Int(value="4"), Int(value="3")) ), ), ), Int(value="7"), ), ), ) )
def test_DIVIDE(self): tree = parse(" 1 / (1 + 2) * 4 - 3 / 7 ") assert tree == Module.construct( body=( Operation.construct( op="-", arguments=( Operation.construct( op="*", arguments=( Operation.construct( op="/", arguments=( Int(value="1"), Operation.construct( op="+", arguments=(Int(value="1"), Int(value="2")), ), ), ), Int(value="4"), ), ), Operation.construct( op="/", arguments=(Int(value="3"), Int(value="7")) ), ), ), ) )
def test_MOD(self): tree = parse(" 2 / 7 % 5 * 1 % 2 - 3 ") assert tree == Module.construct( body=( Operation.construct( op="-", arguments=( Operation.construct( op="*", arguments=( Operation.construct( op="/", arguments=( Int(value="2"), Operation.construct( op="%", arguments=(Int(value="7"), Int(value="5")), ), ), ), Operation.construct( op="%", arguments=(Int(value="1"), Int(value="2")) ), ), ), Int(value="3"), ), ), ) )
def test_GE(self): tree = parse('3 >= (2 >= (3 >= "1")) ') assert tree == Module.construct( body=( Comparison.construct( op=">=", arguments=( Int(value="3"), Comparison.construct( op=">=", arguments=( Int(value="2"), Comparison.construct( op=">=", arguments=(Int(value="3"), String(value="1")), ), ), ), ), ), ) )
def test_BINNOT(self): tree = parse(" ! ( 1 && 2 - 10 % ~ 2 ) % 2") assert tree == Module( body=( Operation( op="!", arguments=( Operation( op="%", arguments=( Operation( op="&&", arguments=( Int(value="1"), Operation( op="-", arguments=( Int(value="2"), Operation( op="%", arguments=( Int(value="10"), Operation( op="~", arguments=(Int(value="2"),), ), ), ), ), ), ), ), Int(value="2"), ), ), ), ), ) )
def test_EQ(self): tree = parse(" 2 == \"2\" == [2] == ('2', 2, \"2\") == '2' ") assert Module.construct( body=( Comparison( op="==", arguments=( Int(value="2"), Comparison( op="==", arguments=( String(value="2"), Comparison( op="==", arguments=( List(items=(Int(value="2"),)), Comparison( op="==", arguments=( Tuple( items=( Char(value="2"), Int(value="2"), String(value="2"), ) ), Char(value="2"), ), ), ), ), ), ), ), ), ) )
def test_LT(self): tree = parse("1000 < (2) < [10] >= a") assert tree == Module.construct( body=( MultiComparison.construct( comparisons=( Comparison.construct( op="<", arguments=(Int(value="1000"), Int(value="2")) ), Comparison.construct( op="<", arguments=(Int(value="2"), List(items=(Int(value="10"),))), ), Comparison.construct( op=">=", arguments=( List(items=(Int(value="10"),)), Namespace(name="a", ctx="load"), ), ), ) ), ) )
def test_POWER(self): tree = parse(" 2 ** 3 % 3 * 3 - 2 + 3 % 3 ** 2") assert tree == Module.construct( body=( Operation.construct( op="+", arguments=( Operation.construct( op="-", arguments=( Operation.construct( op="*", arguments=( Operation.construct( op="%", arguments=( Operation.construct( op="**", arguments=( Int(value="2"), Int(value="3"), ), ), Int(value="3"), ), ), Int(value="3"), ), ), Int(value="2"), ), ), Operation.construct( op="%", arguments=( Int(value="3"), Operation.construct( op="**", arguments=(Int(value="3"), Int(value="2")) ), ), ), ), ), ) )
def test_LE(self): tree = parse("3 % 2 ** 0.5 <= 1 <= 3 <= 2 * 2") assert tree == Module.construct( body=( MultiComparison.construct( comparisons=( Comparison.construct( op="<=", arguments=( Operation.construct( op="%", arguments=( Int(value="3"), Operation.construct( op="**", arguments=( Int(value="2"), Float(value="0.5"), ), ), ), ), Int(value="1"), ), ), Comparison.construct( op="<=", arguments=(Int(value="1"), Int(value="3")) ), Comparison.construct( op="<=", arguments=( Int(value="3"), Operation.construct( op="*", arguments=(Int(value="2"), Int(value="2")) ), ), ), ) ), ) )
def test_BINOR(self): tree = parse("1 || 2 || 3 || 4 || 0101010 || 1234567890") assert tree == Module.construct( body=( Operation.construct( op="||", arguments=( Operation.construct( op="||", arguments=( Operation.construct( op="||", arguments=( Operation.construct( op="||", arguments=( Operation.construct( op="||", arguments=( Int(value="1"), Int(value="2"), ), ), Int(value="3"), ), ), Int(value="4"), ), ), Int(value="0101010"), ), ), Int(value="1234567890"), ), ), ) )
def test_INT(self): tree = parse("1; 1; 1; 1") assert tree == Module( body=(Int(value="1"), Int(value="1"), Int(value="1"), Int(value="1")) )