summaryrefslogtreecommitdiff
path: root/tests/suite/scripting/methods.typ
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2024-04-13 10:39:45 +0200
committerGitHub <noreply@github.com>2024-04-13 08:39:45 +0000
commit020294fca9a7065d4b9cf4e677f606ebaaa29b00 (patch)
treec0027ad22046e2726c22298461327823d6b88d53 /tests/suite/scripting/methods.typ
parent72dd79210602ecc799726fc096b078afbb47f299 (diff)
Better test runner (#3922)
Diffstat (limited to 'tests/suite/scripting/methods.typ')
-rw-r--r--tests/suite/scripting/methods.typ51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/suite/scripting/methods.typ b/tests/suite/scripting/methods.typ
new file mode 100644
index 00000000..5deea2cf
--- /dev/null
+++ b/tests/suite/scripting/methods.typ
@@ -0,0 +1,51 @@
+// Test method calls.
+
+--- method-whitespace ---
+// Test whitespace around dot.
+#test( "Hi there" . split() , ("Hi", "there"))
+
+--- method-mutating ---
+// Test mutating indexed value.
+#{
+ let matrix = (((1,), (2,)), ((3,), (4,)))
+ matrix.at(1).at(0).push(5)
+ test(matrix, (((1,), (2,)), ((3, 5), (4,))))
+}
+
+--- method-multiline ---
+// Test multiline chain in code block.
+#{
+ let rewritten = "Hello. This is a sentence. And one more."
+ .split(".")
+ .map(s => s.trim())
+ .filter(s => s != "")
+ .map(s => s + "!")
+ .join("\n ")
+
+ test(rewritten, "Hello!\n This is a sentence!\n And one more!")
+}
+
+--- method-unknown ---
+// Error: 2:10-2:13 type array has no method `fun`
+#let numbers = ()
+#numbers.fun()
+
+--- method-unknown-but-field-exists ---
+// Error: 2:4-2:10 type content has no method `stroke`
+// Hint: 2:4-2:10 did you mean to access the field `stroke`?
+#let l = line(stroke: red)
+#l.stroke()
+
+--- method-mutate-on-temporary ---
+// Error: 2:2-2:43 cannot mutate a temporary value
+#let numbers = (1, 2, 3)
+#numbers.map(v => v / 2).sorted().map(str).remove(4)
+
+--- assign-to-method-invalid ---
+// Error: 2:3-2:19 cannot mutate a temporary value
+#let numbers = (1, 2, 3)
+#(numbers.sorted() = 1)
+
+--- method-mutate-on-std-constant ---
+// Error: 2-5 cannot mutate a constant: box
+#box.push(1)