Skip to content

Commit

Permalink
Test no whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
nineteendo committed Sep 23, 2024
1 parent a270691 commit b69f3ad
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/jsonyx/_manipulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""JSON manipulator."""
# TODO(Nice Zombies): add error messages
# TODO(Nice Zombies): raise JSONSyntaxError
# TODO(Nice Zombies): remove value comparison
# TODO(Nice Zombies): update schema ID
from __future__ import annotations

Expand Down
1 change: 1 addition & 0 deletions src/jsonyx/_speedups.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* JSON speedups */
// TODO(Nice Zombies): speed up decoding
// https://github.com/benfred/py-spy#can-py-spy-profile-native-extensions

#include <Python.h>
#include <structmember.h>
Expand Down
6 changes: 6 additions & 0 deletions src/jsonyx/test/test_dumps.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,11 @@ def test_list_indent(


@pytest.mark.parametrize(("indent", "expected"), [
# Integer
(0, ""),
(1, " "),
# String
("\t", "\t"),
])
def test_list_indent_leaves(
Expand Down Expand Up @@ -394,8 +397,11 @@ def test_dict_indent(


@pytest.mark.parametrize(("indent", "expected"), [
# Integer
(0, ""),
(1, " "),
# String
("\t", "\t"),
])
def test_dict_indent_leaves(
Expand Down
2 changes: 1 addition & 1 deletion src/jsonyx/test/test_load_query_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def test_invalid_string(s: str, msg: str, colno: int, end_colno: int) -> None:
check_syntax_err(exc_info, msg, colno, end_colno)


@pytest.mark.parametrize("s", ["", "foo"])
@pytest.mark.parametrize("s", ["", "NaN"])
def test_expecting_value(s: str) -> None:
"""Test expecting JSON value."""
with pytest.raises(JSONSyntaxError) as exc_info:
Expand Down
11 changes: 11 additions & 0 deletions src/jsonyx/test/test_loads.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ def test_array(json: ModuleType, s: str, expected: list[object]) -> None:


@pytest.mark.parametrize(("s", "expected"), [
# No whitespace
("[]", []),
("[1,2,3]", [1, 2, 3]),
# In empty array
("[ ]", []),
Expand Down Expand Up @@ -360,6 +364,10 @@ def test_object(json: ModuleType, s: str, expected: dict[str, object]) -> None:


@pytest.mark.parametrize(("s", "expected"), [
# No whitespace
("{}", {}),
('{"a":1,"b":2,"c":3}', {"a": 1, "b": 2, "c": 3}),
# In empty object
("{ }", {}),
Expand Down Expand Up @@ -534,6 +542,9 @@ def test_recursion(json: ModuleType, start: str) -> None:


@pytest.mark.parametrize("s", [
# No whitespace
"0",
# Before value
" 0",
Expand Down
7 changes: 4 additions & 3 deletions src/jsonyx/test/test_run_filter_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ def test_operator(query: str, keep: bool) -> None: # noqa: FBT001


@pytest.mark.parametrize("query", [
# No whitespace
"@==0",
# Before operator
"@ ==0",
Expand All @@ -86,7 +89,7 @@ def test_operator(query: str, keep: bool) -> None: # noqa: FBT001
])
def test_operator_whitespace(query: str) -> None:
"""Test whitespace around operator."""
assert run_filter_query([], query) == []
assert not run_filter_query([], query)


@pytest.mark.parametrize(("obj", "keep"), [
Expand Down Expand Up @@ -131,11 +134,9 @@ def test_whitespace(query: str) -> None:
("$", "Expecting a relative query", 1, -1),
("!", "Expecting a relative query", 2, -1),
("@?", "Optional marker is not allowed", 2, 3),
("@[@]", "Filter is not allowed", 3, -1),
("@ == ", "Expecting value", 6, -1),
("@ == $", "Expecting value", 6, -1),
("@ == @?", "Optional marker is not allowed", 7, 8),
("@ == @[@]", "Filter is not allowed", 8, -1),
("@ && ", "Expecting a relative query", 6, -1),
("!@ == @", "Unexpected operator", 4, 6),
("@ @ @", "Expecting end of file", 2, -1),
Expand Down

0 comments on commit b69f3ad

Please sign in to comment.