summaryrefslogtreecommitdiffstats
path: root/lang/python/python-orjson/test.sh
blob: 0854b353e903e08e9381a6ecd2b56a21e46a7131 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/sh

[ "$1" = python3-orjson ] || exit 0

python3 - << 'EOF'
import faulthandler
faulthandler.enable()

print("importing orjson...", flush=True)
import orjson
print("import OK", flush=True)

# Basic encode/decode
data = {"key": "value", "number": 42, "flag": True, "empty": None}
encoded = orjson.dumps(data)
assert isinstance(encoded, bytes)
decoded = orjson.loads(encoded)
assert decoded == data
print("basic encode/decode OK", flush=True)

# List roundtrip
lst = [1, 2, 3, "hello"]
assert orjson.loads(orjson.dumps(lst)) == lst
print("list roundtrip OK", flush=True)

# Nested structures
nested = {"a": {"b": {"c": 1}}}
assert orjson.loads(orjson.dumps(nested)) == nested
print("nested OK", flush=True)

# OPT_SORT_KEYS option
obj = {"z": 1, "a": 2, "m": 3}
sorted_json = orjson.dumps(obj, option=orjson.OPT_SORT_KEYS)
assert sorted_json == b'{"a":2,"m":3,"z":1}'
print("sort_keys OK", flush=True)

print("orjson OK")
EOF