Skip to content

Commit 89dbc65

Browse files
committed
accel: add tests for pyon parser
1 parent e923934 commit 89dbc65

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

tests/accel/test_pyon.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from lenskit import _accel
2+
3+
4+
def test_parse_json():
5+
json = """
6+
{"name": "FOOBIE BLETCH", "tags": ["foo", "bar"]}
7+
"""
8+
obj = _accel.data.pyon_loads(json)
9+
assert obj == {"name": "FOOBIE BLETCH", "tags": ["foo", "bar"]}
10+
11+
12+
def test_parse_single_quotes():
13+
json = """
14+
{'name': 'FOOBIE BLETCH', 'tags': ['foo', 'bar'], 'count': 7, 'active': false, 'value': 1.0}
15+
"""
16+
obj = _accel.data.pyon_loads(json)
17+
assert obj == {
18+
"name": "FOOBIE BLETCH",
19+
"tags": ["foo", "bar"],
20+
"count": 7,
21+
"active": False,
22+
"value": 1.0,
23+
}
24+
25+
26+
def test_parse_escape_dquote():
27+
json = r"""{"name": "foo\"bob"}"""
28+
obj = _accel.data.pyon_loads(json)
29+
assert obj == {"name": 'foo"bob'}
30+
31+
32+
def test_parse_escape_squote():
33+
json = r"""{"name": 'pe\'taq'}"""
34+
obj = _accel.data.pyon_loads(json)
35+
assert obj == {"name": "pe'taq"}
36+
37+
38+
def test_parse_escape_tab():
39+
json = r"""{"name": '\t'}"""
40+
obj = _accel.data.pyon_loads(json)
41+
assert obj == {"name": "\t"}
42+
43+
44+
def test_parse_escape_lf():
45+
json = r"""{"name": '\n'}"""
46+
obj = _accel.data.pyon_loads(json)
47+
assert obj == {"name": "\n"}
48+
49+
50+
def test_parse_escape_cr():
51+
json = r"""{"name": '\r'}"""
52+
obj = _accel.data.pyon_loads(json)
53+
assert obj == {"name": "\r"}
54+
55+
56+
def test_parse_escape_unicode():
57+
json = r"""{"name": '\u2230'}"""
58+
obj = _accel.data.pyon_loads(json)
59+
assert obj == {"name": "\u2230"}

0 commit comments

Comments
 (0)