示例#1
0
def test_scan_keywords():
    scanner=Scanner('''TrAnsFer transfer 
                       OPEN BALANCE balance''')
    toks = [Token(Type.TRANSFER,"TrAnsFer"), Token(Type.TRANSFER,"transfer"),
            Token(Type.OPEN,"OPEN"),
            Token(Type.BALANCE,"BALANCE"),  Token(Type.BALANCE,"balance")]

    assert [tok for tok in scanner] == toks
    # iterate a second time
    assert [tok for tok in scanner] == toks
示例#2
0
def test_token():
    token=Token(Type.IDENT,"hello")
    assert token.type==Type.IDENT
    assert token.value=="hello"
示例#3
0
def test_scan_currency():
    scanner=Scanner("100 100.00 100.42 -123.45")
    assert list(scanner) == [Token(Type.CURRENCY,10000),
                             Token(Type.CURRENCY,10000),
                             Token(Type.CURRENCY,10042),
                             Token(Type.CURRENCY,-12345)]
示例#4
0
def test_scan_identifiers():
    scanner=Scanner("equity cash end_of_the_world_fund")
    assert list(scanner) == [Token(Type.IDENT,"equity"),
                                        Token(Type.IDENT,"cash"),
                                        Token(Type.IDENT,"end_of_the_world_fund")]
示例#5
0
def test_equal_bad():
    '''test for class mismatch'''
    assert Token(Type.CURRENCY,1000) != '[Type.CURRENCY, 10.00]'
示例#6
0
def test_equal_currency():
    assert Token(Type.CURRENCY,1000) == Token(Type.CURRENCY,1000)
    assert Token(Type.CURRENCY,1000) != Token(Type.CURRENCY,1001)
示例#7
0
def test_equal_keywords():
    assert Token(Type.TRANSFER,"transfer") != Token(Type.OPEN,"open")
    assert Token(Type.OPEN,"OPEN") == Token(Type.OPEN,"open")
    assert Token(Type.BALANCE,"BALANCE") == Token(Type.BALANCE,"balance")
示例#8
0
def test_equal_ident():
    assert Token(Type.IDENT,"Bob") == Token(Type.IDENT,"Bob")
    assert Token(Type.IDENT,"Bob") != Token(Type.IDENT,"bOb")
示例#9
0
def test_str():
    id=Token(Type.IDENT,"hello")
    assert str(id) == '[IDENT: hello]'
    money=Token(Type.CURRENCY,10042)
    assert str(money) == '[CURRENCY: 100.42]'