def test_if_elif():
    ast = ctrl([
        _if(_is(v("a"), c(8)), blk([asg(v("b"), c(3))])),
        _if(_is(v("a"), c(4)), blk([asg(v("b"), c(2))]))
    ], blk())
    parser = Parser(Tokenizer("if a is 8 { b = 3 } elif a is 4 { b = 2 }"))
    assert parser.statement() == ast
Exemplo n.º 2
0
def test_if():
    ast = ctrl(
        [_if(_is(getitem(v("a"), c(0)), c(8)), blk([asg(v("b"), c(3))]))],
        blk())
    parser = Parser(Tokenizer("if a[0] is 8 { b = 3 }"))
    assert parser.statement() == ast
def test_empty_if_with_new_line():
    ast = ctrl([_if(_is(v("a"), c(8)), blk())], blk())
    parser = Parser(Tokenizer("if a is 8 { \n }"))
    assert parser.statement() == ast
def test_if_with_new_lines():
    ast = ctrl([_if(_is(v("a"), c(8)), blk([asg(v("b"), c(3))]))], blk())
    parser = Parser(Tokenizer("if a is 8 {\nb = 3\n}"))
    assert parser.statement() == ast