tests/test_basic.py: more tests

current
Síle Ekaterin Liszka 2024-01-12 13:31:07 -08:00
parent e78a89d7aa
commit 91a1434b49
Signed by: VulpineAmethyst
SSH Key Fingerprint: SHA256:VcHwQ6SUfi/p0Csfxe3SabX/TImWER0PhoJqkt+GlmE
1 changed files with 51 additions and 23 deletions

View File

@ -3,35 +3,63 @@ import pytest
from xbc import loads_xbc, ParseError from xbc import loads_xbc, ParseError
def test_key(): class TestBare:
def test_key(self):
assert loads_xbc('a') == {'a': True} assert loads_xbc('a') == {'a': True}
def test_keyvalue(): def test_dot_key(self):
assert loads_xbc('a.a') == {'a.a': True}
def test_key_eq(self):
assert loads_xbc('a =') == {'a': True}
def test_keyvalue(self):
assert loads_xbc('a = 1') == {'a': '1'} assert loads_xbc('a = 1') == {'a': '1'}
def test_keys(): def test_dot_keyvalue(self):
assert loads_xbc('a.a = 1') == {'a.a': '1'}
def test_keys(self):
assert loads_xbc('a;b') == {'a': True, 'b': True} assert loads_xbc('a;b') == {'a': True, 'b': True}
def test_string(): def test_dot_keys(self):
assert loads_xbc('a.a;a.b') == {'a.a': True, 'a.b': True}
def test_string(self):
assert loads_xbc('a = "b"') == {'a': '"b"'} assert loads_xbc('a = "b"') == {'a': '"b"'}
def test_array(): def test_array(self):
assert loads_xbc('a = 1, 2') == {'a': ['1', '2']} assert loads_xbc('a = 1, 2') == {'a': ['1', '2']}
def test_block(): def test_reassignment(self):
assert loads_xbc('a { a = 1 }') == {'a': False, 'a.a': '1'}
def test_block2():
assert loads_xbc('a = 1\na { a = 1 }') == {'a': '1', 'a.a': '1'}
def test_reassignment():
with pytest.raises(ParseError): with pytest.raises(ParseError):
loads_xbc('a = 1\na = 2') loads_xbc('a = 1\na = 2')
def test_ovewrite_nonexistent(): # currently the lexer doesn't correctly parse keyvalues with semis
# outside of blocks. no idea why.
@pytest.mark.xfail
def test_reassignment_colon(self):
with pytest.raises(ParseError):
loads_xbc('a = 1;a = 2')
def test_ovewrite_nonexistent(self):
with pytest.raises(ParseError): with pytest.raises(ParseError):
loads_xbc('a := 1') loads_xbc('a := 1')
def test_assign_after_block(): class TestBlock:
def test_keyvalue(self):
assert loads_xbc('a { a = 1 }') == {'a': False, 'a.a': '1'}
def test_nested_block(self):
assert loads_xbc('a { b { c = 1 } }') == {'a.b.c': '1', 'a': False, 'a.b': False}
def test_keyvalue_and_block(self):
assert loads_xbc('a = 1\na { a = 1 }') == {'a': '1', 'a.a': '1'}
def test_reassign_colon(self):
with pytest.raises(ParseError):
loads_xbc('a { a = 1; a = 2 }')
def test_assign_after_block(self):
with pytest.raises(ParseError): with pytest.raises(ParseError):
loads_xbc('a { a = 1 }\na = 1') loads_xbc('a { a = 1 }\na = 1')