Compare commits

..

No commits in common. "ab5d6b71817a0e8c8f515d8e13dc08ff7c609d51" and "7d4b991f4a5df54e4f87781152086e0a1938f6db" have entirely different histories.

5 changed files with 65 additions and 116 deletions

View File

@ -1,49 +0,0 @@
import pytest
from xbc import loads_xbc, ParseError
def test_key():
assert loads_xbc('a') == {'a': True}
def test_dot_key():
assert loads_xbc('a.a') == {'a.a': True}
def test_key_eq():
assert loads_xbc('a =') == {'a': True}
def test_keyvalue():
assert loads_xbc('a = 1') == {'a': '1'}
def test_keyvalue_space():
assert loads_xbc('a = a b') == {'a': 'a b'}
def test_dot_keyvalue():
assert loads_xbc('a.a = 1') == {'a.a': '1'}
def test_keys():
assert loads_xbc('a;b') == {'a': True, 'b': True}
def test_dot_keys():
assert loads_xbc('a.a;a.b') == {'a.a': True, 'a.b': True}
def test_quoted():
assert loads_xbc('a = "b"') == {'a': 'b'}
def test_quoted_space():
assert loads_xbc('a = "b "') == {'a': 'b '}
def test_array():
assert loads_xbc('a = 1, 2') == {'a': ['1', '2']}
def test_reassignment():
with pytest.raises(ParseError):
loads_xbc('a = 1\na = 2')
def test_reassignment_colon():
with pytest.raises(ParseError):
loads_xbc('a = 1;a = 2')
def test_ovewrite_nonexistent():
with pytest.raises(ParseError):
loads_xbc('a := 1')

62
tests/test_basic.py Normal file
View File

@ -0,0 +1,62 @@
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')

View File

@ -1,24 +0,0 @@
import pytest
from xbc import loads_xbc, ParseError
def test_empty():
assert loads_xbc('a {}') == {'a': True}
def test_keyvalue():
assert loads_xbc('a { a = 1 }') == {'a': False, 'a.a': '1'}
def test_nested_block():
assert loads_xbc('a { b { c = 1 } }') == {'a.b.c': '1', 'a': False, 'a.b': False}
def test_keyvalue_and_block():
assert loads_xbc('a = 1\na { a = 1 }') == {'a': '1', 'a.a': '1'}
def test_reassign_colon():
with pytest.raises(ParseError):
loads_xbc('a { a = 1; a = 2 }')
def test_assign_after_block():
with pytest.raises(ParseError):
loads_xbc('a { a = 1 }\na = 1')

View File

@ -1,29 +0,0 @@
import pytest
from pyparsing.exceptions import ParseException
from xbc import loads_xbc, ParseError
# this should fail but does not.
@pytest.mark.xfail
def test_whitespace_vc():
with pytest.raises(ParseError):
loads_xbc('x = a\n, b')
# this should fail but does not.
@pytest.mark.xfail
def test_extra_quote():
with pytest.raises(ParseException):
loads_xbc("x = '''")
def test_lone_plus():
with pytest.raises(ParseException):
loads_xbc('+')
def test_lone_rbrace():
with pytest.raises(ParseException):
loads_xbc('}')
def test_lone_lbrace():
with pytest.raises(ParseException):
loads_xbc('{')

View File

@ -111,9 +111,9 @@ class Block(Node):
key_fragment = Word(alphas + nums + '_-')
key = DelimitedList(key_fragment, delim='.', combine=True)
bareval = CharsNotIn('{}#=+:;,\n\'"')
strvals = QuotedString("'", multiline=True, unquote_results=False)
strvald = QuotedString('"', multiline=True, unquote_results=False)
bareval = CharsNotIn(' {}#=+:;,\n\'"')
strvals = QuotedString("'", multiline=True, unquote_results=True)
strvald = QuotedString('"', multiline=True, unquote_results=True)
value = bareval | strvald | strvals
assign = Literal('=')
@ -159,11 +159,6 @@ def lex(data):
tree = XBCParser.parseString(data).asList()
return tree
def unquote(val):
if val[0] in '\'"' and val[0] == val[-1]:
return val[1:-1]
return val.strip()
def parse_block(key, seq):
if isinstance(seq, list) and len(seq) == 1 and isinstance(seq[0], list):
seq = seq[0]
@ -205,12 +200,6 @@ def parse_block(key, seq):
else:
assign = value
if isinstance(assign, list):
for i in range(len(assign)):
assign[i] = unquote(assign[i])
else:
assign = unquote(assign)
if isinstance(assign, list) and len(assign) == 1:
assign = assign[0]