From 020294fca9a7065d4b9cf4e677f606ebaaa29b00 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sat, 13 Apr 2024 10:39:45 +0200 Subject: Better test runner (#3922) --- tests/suite/loading/csv.typ | 27 +++++++++++++++++++++++++++ tests/suite/loading/json.typ | 16 ++++++++++++++++ tests/suite/loading/read.typ | 12 ++++++++++++ tests/suite/loading/toml.typ | 41 +++++++++++++++++++++++++++++++++++++++++ tests/suite/loading/xml.typ | 28 ++++++++++++++++++++++++++++ tests/suite/loading/yaml.typ | 17 +++++++++++++++++ 6 files changed, 141 insertions(+) create mode 100644 tests/suite/loading/csv.typ create mode 100644 tests/suite/loading/json.typ create mode 100644 tests/suite/loading/read.typ create mode 100644 tests/suite/loading/toml.typ create mode 100644 tests/suite/loading/xml.typ create mode 100644 tests/suite/loading/yaml.typ (limited to 'tests/suite/loading') diff --git a/tests/suite/loading/csv.typ b/tests/suite/loading/csv.typ new file mode 100644 index 00000000..415488fc --- /dev/null +++ b/tests/suite/loading/csv.typ @@ -0,0 +1,27 @@ +--- csv --- +// Test reading CSV data. +#set page(width: auto) +#let data = csv("/assets/data/zoo.csv") +#let cells = data.at(0).map(strong) + data.slice(1).flatten() +#table(columns: data.at(0).len(), ..cells) + +--- csv-row-type-dict --- +// Test reading CSV data with dictionary rows enabled. +#let data = csv("/assets/data/zoo.csv", row-type: dictionary) +#test(data.len(), 3) +#test(data.at(0).Name, "Debby") +#test(data.at(2).Weight, "150kg") +#test(data.at(1).Species, "Tiger") + +--- csv-file-not-found --- +// Error: 6-16 file not found (searched at tests/suite/loading/nope.csv) +#csv("nope.csv") + +--- csv-invalid --- +// Error: 6-28 failed to parse CSV (found 3 instead of 2 fields in line 3) +#csv("/assets/data/bad.csv") + +--- csv-invalid-row-type-dict --- +// Test error numbering with dictionary rows. +// Error: 6-28 failed to parse CSV (found 3 instead of 2 fields in line 3) +#csv("/assets/data/bad.csv", row-type: dictionary) diff --git a/tests/suite/loading/json.typ b/tests/suite/loading/json.typ new file mode 100644 index 00000000..3ebeaf2f --- /dev/null +++ b/tests/suite/loading/json.typ @@ -0,0 +1,16 @@ +--- json --- +// Test reading JSON data. +#let data = json("/assets/data/zoo.json") +#test(data.len(), 3) +#test(data.at(0).name, "Debby") +#test(data.at(2).weight, 150) + +--- json-invalid --- +// Error: 7-30 failed to parse JSON (expected value at line 3 column 14) +#json("/assets/data/bad.json") + +--- issue-3363-json-large-number --- +// Big numbers (larger than what i64 can store) should just lose some precision +// but not overflow +#let bignum = json("/assets/data/big-number.json") +#bignum diff --git a/tests/suite/loading/read.typ b/tests/suite/loading/read.typ new file mode 100644 index 00000000..b5c9c089 --- /dev/null +++ b/tests/suite/loading/read.typ @@ -0,0 +1,12 @@ +--- read-text --- +// Test reading plain text files +#let data = read("/assets/text/hello.txt") +#test(data, "Hello, world!\n") + +--- read-file-not-found --- +// Error: 18-44 file not found (searched at assets/text/missing.txt) +#let data = read("/assets/text/missing.txt") + +--- read-invalid-utf-8 --- +// Error: 18-40 file is not valid utf-8 +#let data = read("/assets/text/bad.txt") diff --git a/tests/suite/loading/toml.typ b/tests/suite/loading/toml.typ new file mode 100644 index 00000000..855ca995 --- /dev/null +++ b/tests/suite/loading/toml.typ @@ -0,0 +1,41 @@ +--- toml --- +// Test reading TOML data. +#let data = toml("/assets/data/toml-types.toml") +#test(data.string, "wonderful") +#test(data.integer, 42) +#test(data.float, 3.14) +#test(data.boolean, true) +#test(data.array, (1, "string", 3.0, false)) +#test(data.inline_table, ("first": "amazing", "second": "greater") ) +#test(data.table.element, 5) +#test(data.table.others, (false, "indeed", 7)) +#test(data.date_time, datetime( + year: 2023, + month: 2, + day: 1, + hour: 15, + minute: 38, + second: 57, +)) +#test(data.date_time2, datetime( + year: 2023, + month: 2, + day: 1, + hour: 15, + minute: 38, + second: 57, +)) +#test(data.date, datetime( + year: 2023, + month: 2, + day: 1, +)) +#test(data.time, datetime( + hour: 15, + minute: 38, + second: 57, +)) + +--- toml-invalid --- +// Error: 7-30 failed to parse TOML (expected `.`, `=` at line 1 column 16) +#toml("/assets/data/bad.toml") diff --git a/tests/suite/loading/xml.typ b/tests/suite/loading/xml.typ new file mode 100644 index 00000000..41cd20e7 --- /dev/null +++ b/tests/suite/loading/xml.typ @@ -0,0 +1,28 @@ +--- xml --- +// Test reading XML data. +#let data = xml("/assets/data/hello.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", + ), +),)) + +--- xml-invalid --- +// Error: 6-28 failed to parse XML (found closing tag 'data' instead of 'hello' in line 3) +#xml("/assets/data/bad.xml") diff --git a/tests/suite/loading/yaml.typ b/tests/suite/loading/yaml.typ new file mode 100644 index 00000000..bbfea41c --- /dev/null +++ b/tests/suite/loading/yaml.typ @@ -0,0 +1,17 @@ +--- yaml --- +// Test reading YAML data +#let data = yaml("/assets/data/yaml-types.yaml") +#test(data.len(), 9) +#test(data.null_key, (none, none)) +#test(data.string, "text") +#test(data.integer, 5) +#test(data.float, 1.12) +#test(data.mapping, ("1": "one", "2": "two")) +#test(data.seq, (1,2,3,4)) +#test(data.bool, false) +#test(data.keys().contains("true"), true) +#test(data.at("1"), "ok") + +--- yaml-invalid --- +// Error: 7-30 failed to parse YAML (did not find expected ',' or ']' at line 2 column 1, while parsing a flow sequence at line 1 column 18) +#yaml("/assets/data/bad.yaml") -- cgit v1.2.3