예제 #1
0
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)
예제 #2
0
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')
예제 #3
0
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)
예제 #4
0
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)
예제 #5
0
def oper(x):
    t = type(x)
    if t == ast.primary_expr:
        return ast.operand(x)
    elif t == ast.expression:
        return ast.operand(ast.primary_expr(x))
    elif t == ast.unary_expr:
        return ast.operand(x)
    else:
        raise Exception(str(t))
예제 #6
0
def test_expression():
    pe1 = ast.primary_expr(True)
    op1 = ast.operand(pe1)
    e1 = ast.expression(op1)

    op2 = ast.operation(ast.optoken.op_plus, op1)
    e1.rest.append(op2)
    test_serialization(e1)

    e1.rest.append([op2, op2])
    test_serialization(e1)
예제 #7
0
 def __init__(self,ident):
     self.value = ast.primary_expr(ident)