def test_STRING(self): tree = parse(r' "abc"; "acdef"; "1234"; "\\\n\v\t"; "~pass" ') assert tree == Module.construct( body=( String(value="abc"), String(value="acdef"), String(value="1234"), String(value="\\\n\x0b\t"), String(value="~pass"), ) )
def test_NE(self): tree = parse(' \'a\' != "" != "b" ') assert tree == Module.construct( body=( Comparison( op="!=", arguments=( Char(value="a"), Comparison( op="!=", arguments=(String(value=""), String(value="b")) ), ), ), ) )
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_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_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_FUNCTION(self): tree = parse( "def zeb_is_awesome(" "friend1 :str, " "friend2 :list[:int], " 'friend3 :str = "nate"' ") -> :bool {return True}" ) assert tree == Module.construct( body=( FunctionDeclaration.construct( target=Namespace(name="zeb_is_awesome", ctx="store"), annotation=TypeHint(type_value="bool", type_structure=None), arguments=( Arg( arg="friend1", annotation=TypeHint(type_value="str", type_structure=None), ), Arg( arg="friend2", annotation=TypeHint( type_value="list", type_structure=( TypeHint(type_value="int", type_structure=None), ), ), ), ), default_arguments=( DefaultArg.construct( arg="friend3", value=String(value="nate"), annotation=TypeHint(type_value="str", type_structure=None), ), ), body=(Return.construct(value=Bool(value="True")),), ), ) )
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_IF_ELIF_ELSE(self): tree = parse( 'if True {output("foo")} elif True {return False} else {return True}' ) assert tree == Module.construct( body=( IfStatement.construct( conditionals=( ( Bool(value="True"), ( Call.construct( target=Namespace(name="output", ctx="load"), args=(String(value="foo"),), kwargs={}, ), ), ), (Bool(value="True"), (Return(value=Bool(value="False")),)), ), default=(Return(value=Bool(value="True")),), ), ) )
def test_MULTI_PART_STRING(self): tree = parse(r""" "1" '\n' "abc" """) assert tree == Module.construct(body=(String(value="1\nabc"),))