summaryrefslogtreecommitdiff
path: root/tests/typ/code
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-06-18 11:59:05 +0200
committerLaurenz <laurmaedje@gmail.com>2021-06-18 11:59:05 +0200
commitbca035172c463e6ac4aaf2591d7d4af2da51c522 (patch)
treed17ba4c0208caab1d30f6f2d19821cbd203e37fa /tests/typ/code
parent8b6391040e3fb2ab5f739e26f88621d63ad5d3cc (diff)
Join semantics
Diffstat (limited to 'tests/typ/code')
-rw-r--r--tests/typ/code/block-invalid.typ5
-rw-r--r--tests/typ/code/block.typ28
-rw-r--r--tests/typ/code/for.typ31
-rw-r--r--tests/typ/code/while.typ10
4 files changed, 49 insertions, 25 deletions
diff --git a/tests/typ/code/block-invalid.typ b/tests/typ/code/block-invalid.typ
index d98bf06b..ba3f02d3 100644
--- a/tests/typ/code/block-invalid.typ
+++ b/tests/typ/code/block-invalid.typ
@@ -7,8 +7,9 @@
{1u}
// Should output `1`.
-// Error: 3 expected semicolon or line break
-{0 1}
+// Error: 2:3 expected semicolon or line break
+// Error: 1:4-1:5 cannot join integer with integer
+{1 2}
// Should output `2`.
// Error: 2:12 expected semicolon or line break
diff --git a/tests/typ/code/block.typ b/tests/typ/code/block.typ
index 196e6c14..8c30fa64 100644
--- a/tests/typ/code/block.typ
+++ b/tests/typ/code/block.typ
@@ -9,7 +9,7 @@ All none
// Let evaluates to none.
{ let v = 0 }
-// Trailing none evaluates to none.
+// Type is joined with trailing none, evaluates to string.
{
type("")
none
@@ -19,16 +19,36 @@ All none
// Evaluates to single expression.
{ "Hello" }
-// Evaluates to trailing expression.
+// Evaluates to string.
{ let x = "Hel"; x + "lo" }
-// Evaluates to concatenation of for loop bodies.
+// Evaluates to join of none, [He] and the two loop bodies.
{
- let parts = ("Hel", "lo")
+ let parts = ("l", "lo")
+ [He]
for s in parts [{s}]
}
---
+// Evaluates to join of the templates and strings.
+{
+ [Hey, ]
+ if true {
+ "there!"
+ }
+ [ ]
+ if false [Nope]
+ [How are ] + "you?"
+}
+
+{
+ [A]
+ // Error: 5-6 cannot join template with integer
+ 1
+ [B]
+}
+
+---
// Works the same way in code environment.
// Ref: false
#test(3, {
diff --git a/tests/typ/code/for.typ b/tests/typ/code/for.typ
index 321b08cf..e6bcf269 100644
--- a/tests/typ/code/for.typ
+++ b/tests/typ/code/for.typ
@@ -20,14 +20,13 @@
// String.
{
- let out = ""
let first = true
- for c in "abc" {
+ let out = for c in "abc" {
if not first {
- out += ", "
+ ", "
}
+ c
first = false
- out += c
}
test(out, "a, b, c")
}
@@ -36,14 +35,16 @@
// Block body.
// Should output `[1st, 2nd, 3rd, 4th, 5th, 6th]`.
{
- "[" + for v in (1, 2, 3, 4, 5, 6) {
- (if v > 1 [, ]
- + [{v}]
- + if v == 1 [st]
- + if v == 2 [nd]
- + if v == 3 [rd]
- + if v >= 4 [th])
- } + "]"
+ "["
+ for v in (1, 2, 3, 4, 5, 6) {
+ if v > 1 [, ]
+ [#v]
+ if v == 1 [st]
+ if v == 2 [nd]
+ if v == 3 [rd]
+ if v >= 4 [th]
+ }
+ "]"
}
// Template body.
@@ -53,8 +54,8 @@
---
// Value of for loops.
// Ref: false
-#test(type(for v in () {}), "template")
-#test(type(for v in () []), "template")
+#test(for v in "" [], none)
+#test(type(for v in "1" []), "template")
---
// Ref: false
@@ -67,7 +68,7 @@
// Error: 11-18 cannot add integer and string
#for v in 1 + "2" {}
-// A single error stops iteration.
+// Errors taint everything.
#test(error, for v in (1, 2, 3) {
if v < 2 [Ok] else {error}
})
diff --git a/tests/typ/code/while.typ b/tests/typ/code/while.typ
index e55f8f10..306c1e45 100644
--- a/tests/typ/code/while.typ
+++ b/tests/typ/code/while.typ
@@ -23,8 +23,10 @@
// Value of while loops.
// Ref: false
-#test(type(while false {}), "template")
-#test(type(while false []), "template")
+#test(while false {}, none)
+
+#let i = 0
+#test(type(while i < 1 [{ i += 1 }]), "template")
---
// Ref: false
@@ -37,13 +39,13 @@
// Error: 8-15 unknown variable
#while nothing {}
-// A single error stops iteration.
+// Errors taint everything.
#let i = 0
#test(error, while i < 10 {
i += 1
if i < 5 [nope] else { error }
})
-#test(i, 5)
+#test(i, 10)
---
// Error: 7 expected expression