Beispiel #1
0
    def test_string_lit_in_expr(self):
        string = '@#%$^&*()'
        string_node1 = AST.StringNode(string)
        self.validate_node(self.exp_parser, '"{}"'.format(string),
                           string_node1)

        string = 'Hello world'
        string_node2 = AST.StringNode(string)
        self.validate_node(self.exp_parser, '"{}"'.format(string),
                           string_node2)

        self.check_parse_exception(self.exp_parser, '"Hello',
                                   pp.ParseException)
Beispiel #2
0
    def test_binops(self):
        binop1 = ["1000", ">", "100.0"]
        binop_node1 = AST.GTNode(AST.IntNode(int(binop1[0])),
                                 AST.DecimalNode(Decimal(binop1[2])))
        self.validate_node(self.exp_parser, "".join(binop1), binop_node1)

        binop2 = binop1 + ["==", "true"]
        binop_node2 = AST.EqNode(binop_node1, AST.BoolNode(True))
        self.validate_node(self.exp_parser, "".join(binop2), binop_node2)

        # (100 + var) * (true) + "String"
        lit_bool = AST.BoolNode(True)
        lit_int = AST.IntNode(int("100"))
        lit_var = AST.VarNode("var")
        lit_string = AST.StringNode("String")

        binop_node3 = AST.AddNode(lit_int, lit_var)
        binop_node3 = AST.MulNode(binop_node3, lit_bool)
        binop_node3 = AST.AddNode(binop_node3, lit_string)
        self.validate_node(self.exp_parser, "(100 + var) * true + \"String\"",
                           binop_node3)

        self.check_parse_exception(self.exp_parser, '20 +', pp.ParseException)
        self.check_parse_exception(self.exp_parser, '20 ** 30',
                                   pp.ParseException)
        self.check_parse_exception(self.exp_parser, '30 // 40',
                                   pp.ParseException)