Exemple #1
0
 def test_VARIABLE_DECLARATION(self):
     tree = parse(
         "_zeb_likes_his_10_daily_foobars :bool = True or (False and True) or False"
     )
     assert tree == Module.construct(
         body=(
             VariableDeclaration(
                 target=Namespace(
                     name="_zeb_likes_his_10_daily_foobars", ctx="store"
                 ),
                 annotation=TypeHint(type_value="bool", type_structure=None),
                 value=Operation.construct(
                     op="or",
                     arguments=(
                         Operation.construct(
                             op="or",
                             arguments=(
                                 Bool(value="True"),
                                 Operation.construct(
                                     op="and",
                                     arguments=(
                                         Bool(value="False"),
                                         Bool(value="True"),
                                     ),
                                 ),
                             ),
                         ),
                         Bool(value="False"),
                     ),
                 ),
             ),
         )
     )
Exemple #2
0
 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"))
                     ),
                 ),
             ),
         )
     )
Exemple #3
0
 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,
             ),
         )
     )
Exemple #4
0
 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"),),
                                             ),
                                         ),
                                     ),
                                 ),
                             ),
                         ),
                     ),
                 ),
             ),
         )
     )
Exemple #5
0
 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"),
                 ),
             ),
         )
     )
Exemple #6
0
 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"),
                 ),
             ),
         )
     )
Exemple #7
0
 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"))
                     ),
                 ),
             ),
         )
     )
Exemple #8
0
 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"),
                 ),
             ),
         )
     )
Exemple #9
0
 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"),
                 ),
             ),
         )
     )
Exemple #10
0
 def test_NAMESPACE(self):
     tree = parse("(zeb + nate) ** partnership % challenges*success/ the_sdi")
     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=(
                                                     Namespace(
                                                         name="zeb", ctx="load"
                                                     ),
                                                     Namespace(
                                                         name="nate", ctx="load"
                                                     ),
                                                 ),
                                             ),
                                             Namespace(
                                                 name="partnership", ctx="load"
                                             ),
                                         ),
                                     ),
                                     Namespace(name="challenges", ctx="load"),
                                 ),
                             ),
                             Namespace(name="success", ctx="load"),
                         ),
                     ),
                     Namespace(name="the_sdi", ctx="load"),
                 ),
             ),
         )
     )
Exemple #11
0
 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"))
                             ),
                         ),
                     ),
                 )
             ),
         )
     )
Exemple #12
0
 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"),
                 ),
             ),
         )
     )
Exemple #13
0
 def test_FLOAT(self):
     tree = parse("0.0123456789; 0.0987654321 - 0.1")
     assert tree == Module.construct(
         body=(
             Float(value="0.0123456789"),
             Operation.construct(
                 op="-",
                 arguments=(
                     Float(value="0.0987654321"),
                     Float(value="0.1"),
                 ),
             ),
         )
     )
Exemple #14
0
 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"),
                 ),
             ),
         )
     )
Exemple #15
0
 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"))
                             ),
                         ),
                     ),
                 ),
             ),
         )
     )
Exemple #16
0
 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"),
                         ),
                     ),
                 ),
             ),
         )
     )