diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-03-18 23:36:18 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-03-18 23:43:58 +0100 |
| commit | beca01c826ee51c9ee6d5eadd7e5ef10f7fb9f58 (patch) | |
| tree | e0ebb40b8775bba3b4be7bc47dceda3d349e2ac0 /tests/typ/code/methods.typ | |
| parent | 77d153d315a2a5909840ebcd47491e4cef14428b (diff) | |
Methods
Diffstat (limited to 'tests/typ/code/methods.typ')
| -rw-r--r-- | tests/typ/code/methods.typ | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/typ/code/methods.typ b/tests/typ/code/methods.typ new file mode 100644 index 00000000..b5eff78d --- /dev/null +++ b/tests/typ/code/methods.typ @@ -0,0 +1,50 @@ +// Test method calls. +// Ref: false + +--- +// Test whitespace around dot. +#test( "Hi there" . split() , ("Hi", "there")) + +--- +// Test mutating indexed value. +{ + let matrix = (((1,), (2,)), ((3,), (4,))) + matrix(1)(0).push(5) + test(matrix, (((1,), (2,)), ((3, 5), (4,)))) +} + +--- +// 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([\ ]) + + test(rewritten, [Hello!\ This is a sentence!\ And one more!]) +} + +--- +// Error: 2:3-2:16 type array has no method `fun` +#let numbers = () +{ numbers.fun() } + +--- +// Error: 2:3-2:44 cannot mutate a temporary value +#let numbers = (1, 2, 3) +{ numbers.map(v => v / 2).sorted().map(str).remove(4) } + +--- +// Error: 2:3-2:19 cannot mutate a temporary value +#let numbers = (1, 2, 3) +{ numbers.sorted() = 1 } + +--- +// Error: 3-6 cannot mutate a constant +{ box = 1 } + +--- +// Error: 3-6 cannot mutate a constant +{ box.push(1) } |
