# Path: pycket/pycket_json.py
# def loads(s):
#     if not we_are_translated():
#         import json
#         from pycket.util import PerfRegion
#         data = json.loads(s)
#         with PerfRegion("json_convert"):
#             return _convert(data)
#     decoder = OwnJSONDecoder(s)
#     try:
#         w_res = decoder.decode_any(0)
#         i = decoder.skip_whitespace(decoder.pos)
#         if i < len(s):
#             start = i
#             end = len(s) - 1
#             raise ValueError("Extra data: char %d - %d" % (start, end))
#         return w_res
#     finally:
#         decoder.close()


import pytest
import json as pyjson
from pycket.pycket_json import loads
def _compare(string, expected):
    json = loads(string)
    val = json._unpack_deep()
    assert val == expected
    #assert val == pyjson.loads(string)

def test_simple():
    _compare("1", 1)
    _compare("\"abc\"", "abc")
    _compare("1.2", 1.2)

def test_array():
    _compare("[]", [])
    _compare("[1]", [1])
    _compare("[1, 2.0, 3.0, \"abc\", [10.0, \"def\"]]", [1, 2.0, 3.0, "abc", [10.0, "def"]])

def test_object():
    _compare("{}", {})
    _compare("{\"a\": 1}", {"a": 1})
    _compare("{\"a\": 1, \"123\": \"ab\", \"subobj\": {\"d\": 12.0}, \"subarr\": [1]}", {"a": 1, "123": "ab", "subobj": {"d": 12.0}, "subarr": [1]})

def test_escaped_string():
    _compare('"\\n"', "\n")
    _compare('"\\n\\t\\b\\f\\r\\\\"', "\n\t\b\f\r\\")
    _compare('"\\n\\t\\b\\f\\r\\\\"', "\n\t\b\f\r\\")
    _compare('["\\\\"]', ["\\"])
    _compare('["\\\\\\\\"]', ["\\\\"])
    _compare('"\\""', '"')

def test_tostring_string_escaping():

# Path: pycket/pycket_json.py
# def loads(s):
#     if not we_are_translated():
#         import json
#         from pycket.util import PerfRegion
#         data = json.loads(s)
#         with PerfRegion("json_convert"):
#             return _convert(data)
#     decoder = OwnJSONDecoder(s)
#     try:
#         w_res = decoder.decode_any(0)
#         i = decoder.skip_whitespace(decoder.pos)
#         if i < len(s):
#             start = i
#             end = len(s) - 1
#             raise ValueError("Extra data: char %d - %d" % (start, end))
#         return w_res
#     finally:
#         decoder.close()


# Path: pycket/test/test_json.py
import pytest
import json as pyjson
from pycket.pycket_json import loads

def _compare(string, expected):
    json = loads(string)
    val = json._unpack_deep()
    assert val == expected
    #assert val == pyjson.loads(string)

def test_simple():
    _compare("1", 1)
    _compare("\"abc\"", "abc")
    _compare("1.2", 1.2)

def test_array():
    _compare("[]", [])
    _compare("[1]", [1])
    _compare("[1, 2.0, 3.0, \"abc\", [10.0, \"def\"]]", [1, 2.0, 3.0, "abc", [10.0, "def"]])

def test_object():
    _compare("{}", {})
    _compare("{\"a\": 1}", {"a": 1})
    _compare("{\"a\": 1, \"123\": \"ab\", \"subobj\": {\"d\": 12.0}, \"subarr\": [1]}", {"a": 1, "123": "ab", "subobj": {"d": 12.0}, "subarr": [1]})

def test_escaped_string():
    _compare('"\\n"', "\n")
    _compare('"\\n\\t\\b\\f\\r\\\\"', "\n\t\b\f\r\\")
    _compare('"\\n\\t\\b\\f\\r\\\\"', "\n\t\b\f\r\\")
    _compare('["\\\\"]', ["\\"])
    _compare('["\\\\\\\\"]', ["\\\\"])
    _compare('"\\""', '"')

def test_tostring_string_escaping():

    json = loads('"\\n"')