def test_monops(self): monop_node1 = AST.NegNode(AST.BoolNode(True)) self.validate_node(self.exp_parser, "!true", monop_node1) monop_node2 = AST.NegNode(monop_node1) self.validate_node(self.exp_parser, "!!true", monop_node2) monop_node3 = AST.MinNode(AST.IntNode(int("30"))) self.validate_node(self.exp_parser, "-30", monop_node3) monop_node4 = AST.PlusNode(AST.IntNode(int("40"))) self.validate_node(self.exp_parser, "+40", monop_node4)
def test_expression_combinations(self): # !(5.0 + +10 / var1 / 2 - !var2 && (19. * .12) || false) # = invalid eq but is parseable. int1 = AST.IntNode(int("10")) int2 = AST.IntNode(int("2")) dec1 = AST.DecimalNode(Decimal("5.0")) dec2 = AST.DecimalNode(Decimal("19.")) dec3 = AST.DecimalNode(Decimal(".12")) var1 = AST.VarNode("var1") var2 = AST.VarNode("var2") bool1 = AST.BoolNode(False) # First prefix +, then division expr = AST.DivNode(AST.PlusNode(int1), var1) expr = AST.DivNode(expr, int2) # Secondly + and - expr = AST.AddNode(dec1, expr) expr = AST.SubNode(expr, AST.NegNode(var2)) # Thirdly &&, last || and the very last ! expr = AST.AndNode(expr, AST.MulNode(dec2, dec3)) expr = AST.NegNode(AST.OrNode(expr, bool1)) string_expr = "!(5.0 + +10 / var1 / 2 - !var2 && (19. * .12) || false)" self.validate_node(self.exp_parser, string_expr, expr)