summaryrefslogtreecommitdiff
path: root/tests/typ/base/data.typ
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-11-03 16:50:26 +0100
committerLaurenz <laurmaedje@gmail.com>2022-11-03 16:50:26 +0100
commit33928a00dc58250e24da1dae4e5db17e7b598d70 (patch)
tree451083aa64f57b442359875b0415541463cb1a0c /tests/typ/base/data.typ
parent46921a8c283718402322d4d09c0bd1d9194278b1 (diff)
Tidy up library
Diffstat (limited to 'tests/typ/base/data.typ')
-rw-r--r--tests/typ/base/data.typ58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/typ/base/data.typ b/tests/typ/base/data.typ
new file mode 100644
index 00000000..96b12ff5
--- /dev/null
+++ b/tests/typ/base/data.typ
@@ -0,0 +1,58 @@
+// 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()
+#table(columns: data(0).len(), ..cells)
+
+---
+// Error: 6-16 file not found (searched at typ/base/nope.csv)
+#csv("nope.csv")
+
+---
+// 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")
+
+---
+// Test reading XML data.
+#let data = xml("/res/data.xml")
+#test(data, ((
+ tag: "data",
+ attrs: (:),
+ children: (
+ "\n ",
+ (tag: "hello", attrs: (name: "hi"), children: ("1",)),
+ "\n ",
+ (
+ tag: "data",
+ attrs: (:),
+ children: (
+ "\n ",
+ (tag: "hello", attrs: (:), children: ("World",)),
+ "\n ",
+ (tag: "hello", attrs: (:), children: ("World",)),
+ "\n ",
+ ),
+ ),
+ "\n",
+ ),
+),))
+
+---
+// Error: 6-20 failed to parse xml file: found closing tag 'data' instead of 'hello' in line 3
+#xml("/res/bad.xml")