summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2020-07-10 17:33:17 -0700
committerScott Shawcroft <scott@tannewt.org>2020-07-10 17:33:17 -0700
commit372bcf8a956c8b20c423333114d7aa061dd54751 (patch)
treea27b619d18dbc54ff97128f9ee01a55a8ab991a1 /tests
parent734661e79cc2b108079377642ef24fab1217c484 (diff)
Fix stream version and add basic readinto test
Diffstat (limited to 'tests')
-rw-r--r--tests/extmod/ujson_load_readinto.py22
-rw-r--r--tests/extmod/ujson_load_readinto.py.exp4
2 files changed, 26 insertions, 0 deletions
diff --git a/tests/extmod/ujson_load_readinto.py b/tests/extmod/ujson_load_readinto.py
new file mode 100644
index 000000000..a277f40ef
--- /dev/null
+++ b/tests/extmod/ujson_load_readinto.py
@@ -0,0 +1,22 @@
+import ujson as json
+
+# Test that json can load from any object with readinto
+
+class Buffer:
+ def __init__(self, data):
+ self._data = data
+ self._i = 0
+
+ def readinto(self, buf):
+ end = self._i + len(buf)
+ remaining = len(self._data) - self._i
+ end = min(end, len(self._data))
+ l = min(len(buf), remaining)
+ buf[:l] = self._data[self._i:end]
+ self._i += l
+ return l
+
+print(json.load(Buffer(b'null')))
+print(json.load(Buffer(b'"abc\\u0064e"')))
+print(json.load(Buffer(b'[false, true, 1, -2]')))
+print(json.load(Buffer(b'{"a":true}')))
diff --git a/tests/extmod/ujson_load_readinto.py.exp b/tests/extmod/ujson_load_readinto.py.exp
new file mode 100644
index 000000000..f8c3c693b
--- /dev/null
+++ b/tests/extmod/ujson_load_readinto.py.exp
@@ -0,0 +1,4 @@
+None
+abcde
+[False, True, 1, -2]
+{'a': True}