Skip to content

Commit

Permalink
Test too big numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
nineteendo committed Sep 18, 2024
1 parent 6334e2c commit f931887
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
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 @@ -71,7 +71,7 @@ def test_too_big_int() -> None:
"""Test too big integer."""
s: str = "1" + "0" * sys.get_int_max_str_digits()
with pytest.raises(JSONSyntaxError) as exc_info:
load_query_value(s, use_decimal=True)
load_query_value(s)

check_syntax_err(exc_info, "Number is too big", 1, len(s) + 1)

Expand Down
2 changes: 1 addition & 1 deletion src/jsonyx/test/test_loads.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def test_too_big_int(json: ModuleType) -> None:
"""Test too big integer."""
s: str = "1" + "0" * sys.get_int_max_str_digits()
with pytest.raises(json.JSONSyntaxError) as exc_info:
json.loads(s, use_decimal=True)
json.loads(s)

check_syntax_err(exc_info, "Number is too big", 1, len(s) + 1)

Expand Down
54 changes: 53 additions & 1 deletion src/jsonyx/test/test_run_select_query.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Copyright (C) 2024 Nice Zombies
"""JSON run_select_query tests."""
# TODO(Nice Zombies): add more tests
# TODO(Nice Zombies): test integer conversion
from __future__ import annotations

__all__: list[str] = []

import sys
from typing import TYPE_CHECKING, Any

import pytest
Expand Down Expand Up @@ -122,6 +122,45 @@ def test_slice(query: str, expected: slice) -> None:
assert run_select_query(node, query, allow_slice=True) == [([], expected)]


@pytest.mark.skipif(
not hasattr(sys, "get_int_max_str_digits"),
reason="requires integer string conversion length limit",
)
def test_too_big_start() -> None:
"""Test too big start."""
num: str = "1" + "0" * sys.get_int_max_str_digits()
with pytest.raises(JSONSyntaxError) as exc_info:
run_select_query(([[]], 0), f"$[{num}::]")

check_syntax_err(exc_info, "Start is too big", 3, 3 + len(num))


@pytest.mark.skipif(
not hasattr(sys, "get_int_max_str_digits"),
reason="requires integer string conversion length limit",
)
def test_too_big_stop() -> None:
"""Test too big stop."""
num: str = "1" + "0" * sys.get_int_max_str_digits()
with pytest.raises(JSONSyntaxError) as exc_info:
run_select_query(([[]], 0), f"$[:{num}:]")

check_syntax_err(exc_info, "Stop is too big", 4, 4 + len(num))


@pytest.mark.skipif(
not hasattr(sys, "get_int_max_str_digits"),
reason="requires integer string conversion length limit",
)
def test_too_big_step() -> None:
"""Test too big step."""
num: str = "1" + "0" * sys.get_int_max_str_digits()
with pytest.raises(JSONSyntaxError) as exc_info:
run_select_query(([[]], 0), f"$[::{num}]")

check_syntax_err(exc_info, "Step is too big", 5, 5 + len(num))


@pytest.mark.parametrize("num", [
# Sign
"-1",
Expand All @@ -134,6 +173,19 @@ def test_index(num: str) -> None:
assert run_select_query(([[]], 0), f"$[{num}]") == [([], int(num))]


@pytest.mark.skipif(
not hasattr(sys, "get_int_max_str_digits"),
reason="requires integer string conversion length limit",
)
def test_too_big_int() -> None:
"""Test too big integer."""
num: str = "1" + "0" * sys.get_int_max_str_digits()
with pytest.raises(JSONSyntaxError) as exc_info:
run_select_query(([[]], 0), f"$[{num}]")

check_syntax_err(exc_info, "Index is too big", 3, 3 + len(num))


@pytest.mark.parametrize(("obj", "query", "keys"), [
([1, 2, 3], "$[@]", [0, 1, 2]),
({"a": 1, "b": 2, "c": 3}, "$[@]", ["a", "b", "c"]),
Expand Down

0 comments on commit f931887

Please sign in to comment.