summaryrefslogtreecommitdiff
path: root/tests/typ
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-03-10 20:47:23 +0100
committerLaurenz <laurmaedje@gmail.com>2023-03-10 21:19:50 +0100
commita9fdff244aef859449a76e5f762ee7c343a8ddcc (patch)
tree172b543183296b4bc30b3008650f594688467914 /tests/typ
parent62f35602a87574dcc607f1637aeae1be574981ff (diff)
Expose content representation more
Diffstat (limited to 'tests/typ')
-rw-r--r--tests/typ/compiler/content-field.typ41
-rw-r--r--tests/typ/compiler/field.typ2
-rw-r--r--tests/typ/compiler/label.typ2
-rw-r--r--tests/typ/compiler/ops.typ10
-rw-r--r--tests/typ/compiler/repr.typ7
-rw-r--r--tests/typ/compiler/show-node.typ2
6 files changed, 52 insertions, 12 deletions
diff --git a/tests/typ/compiler/content-field.typ b/tests/typ/compiler/content-field.typ
new file mode 100644
index 00000000..0eeee458
--- /dev/null
+++ b/tests/typ/compiler/content-field.typ
@@ -0,0 +1,41 @@
+// Integrated test for content fields.
+
+#let compute(formula, ..vars) = {
+ let vars = vars.named()
+ let f(node) = {
+ let func = node.func()
+ if func == text {
+ let text = node.text
+ if regex("^\d+$") in text {
+ int(text)
+ } else if text in vars {
+ int(vars.at(text))
+ } else {
+ panic("unknown math variable: " + text)
+ }
+ } else if func == math.attach {
+ let value = f(node.base)
+ if node.has("top") {
+ value = calc.pow(value, f(node.top))
+ }
+ value
+ } else if node.has("children") {
+ node
+ .children
+ .filter(v => v != [ ])
+ .split[+]
+ .map(xs => xs.fold(1, (prod, v) => prod * f(v)))
+ .fold(0, (sum, v) => sum + v)
+ }
+ }
+ let result = f(formula.body)
+ [With ]
+ vars
+ .pairs()
+ .map(p => $#p.first() = #p.last()$)
+ .join(", ", last: " and ")
+ [ we have:]
+ $ formula = result $
+}
+
+#compute($x y + y^2$, x: 2, y: 3)
diff --git a/tests/typ/compiler/field.typ b/tests/typ/compiler/field.typ
index 27b31f7d..342ae75b 100644
--- a/tests/typ/compiler/field.typ
+++ b/tests/typ/compiler/field.typ
@@ -31,7 +31,7 @@
#false.ok
---
-// Error: 29-32 unknown field `fun`
+// Error: 29-32 content does not contain field "fun"
#show heading: node => node.fun
= A
diff --git a/tests/typ/compiler/label.typ b/tests/typ/compiler/label.typ
index d4ff15d7..58b0dee9 100644
--- a/tests/typ/compiler/label.typ
+++ b/tests/typ/compiler/label.typ
@@ -22,7 +22,7 @@ The end.
---
// Test labelled text.
#show "t": it => {
- set text(blue) if it.label == <last>
+ set text(blue) if it.has("label") and it.label == <last>
it
}
diff --git a/tests/typ/compiler/ops.typ b/tests/typ/compiler/ops.typ
index baa2898a..a29003ed 100644
--- a/tests/typ/compiler/ops.typ
+++ b/tests/typ/compiler/ops.typ
@@ -152,11 +152,13 @@
#test(test == test, true)
#test((() => {}) == (() => {}), false)
-// Content cannot be compared.
+// Content compares field by field.
#let t = [a]
-#test(t == t, false)
-#test([] == [], false)
-#test([a] == [a], false)
+#test(t == t, true)
+#test([] == [], true)
+#test([a] == [a], true)
+#test(grid[a] == grid[a], true)
+#test(grid[a] == grid[b], false)
---
// Test comparison operators.
diff --git a/tests/typ/compiler/repr.typ b/tests/typ/compiler/repr.typ
index ed6cd84a..cfe428eb 100644
--- a/tests/typ/compiler/repr.typ
+++ b/tests/typ/compiler/repr.typ
@@ -30,16 +30,13 @@
#rgb("f7a205") \
#(2pt + rgb("f7a205"))
----
// Strings and escaping.
-#raw(repr("hi"), lang: "typc") \
+#raw(repr("hi"), lang: "typc")
#repr("a\n[]\"\u{1F680}string")
----
// Content.
-#raw(repr[*{"H" + "i"} there*])
+#raw(lang: "typc", repr[*Hey*])
----
// Functions are invisible.
Nothing
#let f(x) = x
diff --git a/tests/typ/compiler/show-node.typ b/tests/typ/compiler/show-node.typ
index f87b1971..0c1c1f52 100644
--- a/tests/typ/compiler/show-node.typ
+++ b/tests/typ/compiler/show-node.typ
@@ -78,7 +78,7 @@ Another text.
= Heading
---
-// Error: 25-29 unknown field `page`
+// Error: 25-29 content does not contain field "page"
#show heading: it => it.page
= Heading