py-xbc/tests/test_basic.py

63 lines
1.5 KiB
Python

import pytest
from xbc import loads_xbc, ParseError
class TestBareLoad:
def test_key(self):
assert loads_xbc('a') == {'a': True}
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'}
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}
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'}
def test_array(self):
assert loads_xbc('a = 1, 2') == {'a': ['1', '2']}
def test_reassignment(self):
with pytest.raises(ParseError):
loads_xbc('a = 1\na = 2')
def test_reassignment_colon(self):
with pytest.raises(ParseError):
loads_xbc('a = 1;a = 2')
def test_ovewrite_nonexistent(self):
with pytest.raises(ParseError):
loads_xbc('a := 1')
class TestBlockLoad:
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):
loads_xbc('a { a = 1 }\na = 1')