summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-09-25 17:35:56 +0200
committerLaurenz <laurmaedje@gmail.com>2022-09-25 17:37:16 +0200
commitfffb55f79a3369fa2dcf39371091c48ff61f55a8 (patch)
tree6d48f81b7edd5f70a1eadf3ada88379646ebbe10 /tests
parentddd3b6a82b8c0353c942bfba8b89ca5476eedc58 (diff)
JSON reading
Diffstat (limited to 'tests')
-rw-r--r--tests/ref/utility/data.png (renamed from tests/ref/utility/csv.png)bin8603 -> 8603 bytes
-rw-r--r--tests/res/bad.json4
-rw-r--r--tests/res/zoo.json20
-rw-r--r--tests/typ/utility/data.typ (renamed from tests/typ/utility/csv.typ)16
4 files changed, 39 insertions, 1 deletions
diff --git a/tests/ref/utility/csv.png b/tests/ref/utility/data.png
index 69e0ae38..69e0ae38 100644
--- a/tests/ref/utility/csv.png
+++ b/tests/ref/utility/data.png
Binary files differ
diff --git a/tests/res/bad.json b/tests/res/bad.json
new file mode 100644
index 00000000..cd5d0366
--- /dev/null
+++ b/tests/res/bad.json
@@ -0,0 +1,4 @@
+{
+ "valid": true,
+ "invalid": True
+}
diff --git a/tests/res/zoo.json b/tests/res/zoo.json
new file mode 100644
index 00000000..3b5a7ffc
--- /dev/null
+++ b/tests/res/zoo.json
@@ -0,0 +1,20 @@
+[
+ {
+ "name": "Debby",
+ "species": "Rhinoceros",
+ "weight": 1900,
+ "length": 390
+ },
+ {
+ "name": "Fluffy",
+ "species": "Tiger",
+ "weight": 115,
+ "length": 310
+ },
+ {
+ "name": "Sleepy",
+ "species": "Dolphin",
+ "weight": 150,
+ "length": 180
+ }
+]
diff --git a/tests/typ/utility/csv.typ b/tests/typ/utility/data.typ
index 146cafae..4fdb84c2 100644
--- a/tests/typ/utility/csv.typ
+++ b/tests/typ/utility/data.typ
@@ -1,6 +1,9 @@
-// Test reading structured CSV data.
+// Test reading structured data.
+// Ref: false
---
+// Test reading CSV data.
+// Ref: true
#set page(width: auto)
#let data = csv("/res/zoo.csv")
#let cells = data(0).map(strong) + data.slice(1).flatten()
@@ -13,3 +16,14 @@
---
// Error: 6-20 failed to parse csv file: found 3 instead of 2 fields in line 3
#csv("/res/bad.csv")
+
+---
+// Test reading JSON data.
+#let data = json("/res/zoo.json")
+#test(data.len(), 3)
+#test(data(0).name, "Debby")
+#test(data(2).weight, 150)
+
+---
+// Error: 7-22 failed to parse json file: syntax error in line 3
+#json("/res/bad.json")