def test_identifier(): ident1 = ast.identifier('ident1') assert(ident1.name == 'ident1') ident2 = ast.identifier('ident1') assert(ident2.name == 'ident1') assert(ident1 == ident2) ident3 = ast.identifier('ident3') assert(ident3.name == 'ident3') assert(ident1 != ident3)
def test_primary_expr(): pe1 = ast.primary_expr(False) assert(pe1.value == False) ident1 = ast.identifier('ident1') pe2 = ast.primary_expr(ident1) assert(pe2.value == ident1)
def test_operand(): pe1 = ast.primary_expr(True) op1 = ast.operand(pe1) assert(op1.value == pe1) assert(op1.value.value == True) id2 = ast.identifier('ident') pe2 = ast.primary_expr(id2) op2 = ast.operand(pe2) assert(op2.value == pe2) assert(op2.value.value.name == 'ident')
def test_operation(): pe1 = ast.primary_expr(True) op1 = ast.operand(pe1) op2 = ast.operation(ast.optoken.op_plus, op1) assert(op2.operator == ast.optoken.op_plus) assert(op2.operand == op1) id2 = ast.identifier('ident') pe2 = ast.primary_expr(id2) op3 = ast.operand(pe2) op4 = ast.unary_expr(ast.optoken.op_minus, op3) assert(op4.operator == ast.optoken.op_minus) assert(op4.operand == op3)
def test_unary_expr(): pe1 = ast.primary_expr(True) op1 = ast.operand(pe1) ue1 = ast.unary_expr(ast.optoken.op_not, op1) assert(ue1.operator == ast.optoken.op_not) assert(ue1.operand == op1) id2 = ast.identifier('ident') pe2 = ast.primary_expr(id2) op2 = ast.operand(pe2) ue2 = ast.unary_expr(ast.optoken.op_negative, op2) assert(ue2.operator == ast.optoken.op_negative) assert(ue2.operand == op2)