summaryrefslogtreecommitdiff
path: root/tests/typ/code
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-07-30 18:37:04 +0200
committerLaurenz <laurmaedje@gmail.com>2021-07-30 18:49:20 +0200
commite35fca54a0c5b3cd5251a58837e9c1ef2b6c3c6d (patch)
tree21afd717101000209cd35d07df8034864f29c41f /tests/typ/code
parent1ee1d078e2480ddd08d40915bc7a74a8352acff0 (diff)
Change indent from 4 to 2 spaces
Diffstat (limited to 'tests/typ/code')
-rw-r--r--tests/typ/code/block.typ74
-rw-r--r--tests/typ/code/call.typ14
-rw-r--r--tests/typ/code/closure.typ66
-rw-r--r--tests/typ/code/for.typ40
-rw-r--r--tests/typ/code/if.typ50
-rw-r--r--tests/typ/code/import.typ4
-rw-r--r--tests/typ/code/include.typ4
-rw-r--r--tests/typ/code/ops-assoc.typ10
-rw-r--r--tests/typ/code/ops.typ68
-rw-r--r--tests/typ/code/while.typ14
10 files changed, 172 insertions, 172 deletions
diff --git a/tests/typ/code/block.typ b/tests/typ/code/block.typ
index ac289abf..a54df461 100644
--- a/tests/typ/code/block.typ
+++ b/tests/typ/code/block.typ
@@ -6,20 +6,20 @@
// Evaluates to join of none, [My ] and the two loop bodies.
{
- let parts = ("my fri", "end.")
- [Hello, ]
- for s in parts [{s}]
+ let parts = ("my fri", "end.")
+ [Hello, ]
+ for s in parts [{s}]
}
// Evaluates to join of the templates and strings.
{
- [How]
- if true {
- " are"
- }
- [ ]
- if false [Nope]
- [you] + "?"
+ [How]
+ if true {
+ " are"
+ }
+ [ ]
+ if false [Nope]
+ [you] + "?"
}
---
@@ -37,24 +37,24 @@
// Evaluated to int.
#test({
- let x = 1
- let y = 2
- x + y
+ let x = 1
+ let y = 2
+ x + y
}, 3)
// String is joined with trailing none, evaluates to string.
#test({
- type("")
- none
+ type("")
+ none
}, "string")
---
// Some things can't be joined.
{
- [A]
- // Error: 5-6 cannot join template with integer
- 1
- [B]
+ [A]
+ // Error: 3-4 cannot join template with integer
+ 1
+ [B]
}
---
@@ -65,8 +65,8 @@
---
// Block in expression does create a scope.
#let a = {
- let b = 1
- b
+ let b = 1
+ b
}
#test(a, 1)
@@ -77,8 +77,8 @@
---
// Double block creates a scope.
{{
- import b from "target.typ"
- test(b, 1)
+ import b from "target.typ"
+ test(b, 1)
}}
// Error: 2-3 unknown variable
@@ -87,17 +87,17 @@
---
// Multiple nested scopes.
{
- let a = "a1"
+ let a = "a1"
+ {
+ let a = "a2"
{
- let a = "a2"
- {
- test(a, "a2")
- let a = "a3"
- test(a, "a3")
- }
- test(a, "a2")
+ test(a, "a2")
+ let a = "a3"
+ test(a, "a3")
}
- test(a, "a1")
+ test(a, "a2")
+ }
+ test(a, "a1")
}
---
@@ -117,13 +117,13 @@
// Should output `3`.
{
- // Error: 9-12 expected identifier, found string
- for "v"
+ // Error: 7-10 expected identifier, found string
+ for "v"
- // Error: 10 expected keyword `in`
- for v let z = 1 + 2
+ // Error: 8 expected keyword `in`
+ for v let z = 1 + 2
- z
+ z
}
---
diff --git a/tests/typ/code/call.typ b/tests/typ/code/call.typ
index 28ce860c..118382e4 100644
--- a/tests/typ/code/call.typ
+++ b/tests/typ/code/call.typ
@@ -25,8 +25,8 @@
// Test multiple wide calls in separate expressions inside a template.
[
- #font!(fill: eastern) - First
- #font!(fill: forest) - Second
+ #font!(fill: eastern) - First
+ #font!(fill: forest) - Second
]
// Test wide call in heading.
@@ -59,12 +59,12 @@ C
// Callee expressions.
{
- // Wrapped in parens.
- test((type)("hi"), "string")
+ // Wrapped in parens.
+ test((type)("hi"), "string")
- // Call the return value of a function.
- let adder(dx) = x => x + dx
- test(adder(2)(5), 7)
+ // Call the return value of a function.
+ let adder(dx) = x => x + dx
+ test(adder(2)(5), 7)
}
---
diff --git a/tests/typ/code/closure.typ b/tests/typ/code/closure.typ
index 75241f32..dcd35586 100644
--- a/tests/typ/code/closure.typ
+++ b/tests/typ/code/closure.typ
@@ -13,73 +13,73 @@
---
// Basic closure without captures.
{
- let adder = (x, y) => x + y
- test(adder(2, 3), 5)
+ let adder = (x, y) => x + y
+ test(adder(2, 3), 5)
}
---
// Pass closure as argument and return closure.
// Also uses shorthand syntax for a single argument.
{
- let chain = (f, g) => (x) => f(g(x))
- let f = x => x + 1
- let g = x => 2 * x
- let h = chain(f, g)
- test(h(2), 5)
+ let chain = (f, g) => (x) => f(g(x))
+ let f = x => x + 1
+ let g = x => 2 * x
+ let h = chain(f, g)
+ test(h(2), 5)
}
---
// Capture environment.
{
- let mark = "?"
- let greet = {
- let hi = "Hi"
- name => {
- hi + ", " + name + mark
- }
+ let mark = "?"
+ let greet = {
+ let hi = "Hi"
+ name => {
+ hi + ", " + name + mark
}
+ }
- test(greet("Typst"), "Hi, Typst?")
+ test(greet("Typst"), "Hi, Typst?")
- mark = "!"
- test(greet("Typst"), "Hi, Typst!")
+ mark = "!"
+ test(greet("Typst"), "Hi, Typst!")
}
---
// Redefined variable.
{
- let x = 1
- let f() = {
- let x = x + 2
- x
- }
- test(f(), 3)
+ let x = 1
+ let f() = {
+ let x = x + 2
+ x
+ }
+ test(f(), 3)
}
---
// Don't leak environment.
{
- // Error: 18-19 unknown variable
- let func() = x
- let x = "hi"
- func()
+ // Error: 16-17 unknown variable
+ let func() = x
+ let x = "hi"
+ func()
}
---
// Too few arguments.
{
- let types(x, y) = "[" + type(x) + ", " + type(y) + "]"
- test(types(14%, 12pt), "[relative, length]")
+ let types(x, y) = "[" + type(x) + ", " + type(y) + "]"
+ test(types(14%, 12pt), "[relative, length]")
- // Error: 16-22 missing argument: y
- test(types("nope"), "[string, none]")
+ // Error: 14-20 missing argument: y
+ test(types("nope"), "[string, none]")
}
---
// Too many arguments.
{
- let f(x) = x + 1
+ let f(x) = x + 1
- // Error: 10-15 unexpected argument
- f(1, "two", () => x)
+ // Error: 8-13 unexpected argument
+ f(1, "two", () => x)
}
diff --git a/tests/typ/code/for.typ b/tests/typ/code/for.typ
index 62cb0bb5..0785be71 100644
--- a/tests/typ/code/for.typ
+++ b/tests/typ/code/for.typ
@@ -10,22 +10,22 @@
// Dictionary is not traversed in insertion order.
// Should output `Age: 2. Name: Typst.`.
#for k, v in (Name: "Typst", Age: 2) [
- {k}: {v}.
+ {k}: {v}.
]
// Block body.
// Should output `[1st, 2nd, 3rd, 4th, 5th]`.
{
- "["
- for v in (1, 2, 3, 4, 5) {
- 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) {
+ if v > 1 [, ]
+ [#v]
+ if v == 1 [st]
+ if v == 2 [nd]
+ if v == 3 [rd]
+ if v >= 4 [th]
+ }
+ "]"
}
// Template body.
@@ -37,23 +37,23 @@
// Values of array.
#for v in (1, 2, 3) {
- out += (v,)
+ out += (v,)
}
// Indices and values of array.
#for i, v in ("1", "2", "3") {
- test(repr(i + 1), v)
+ test(repr(i + 1), v)
}
// Values of dictionary.
#for v in (a: 4, b: 5) {
- out += (v,)
+ out += (v,)
}
// Keys and values of dictionary.
#for k, v in (a: 6, b: 7) {
- out += (k,)
- out += (v,)
+ out += (k,)
+ out += (v,)
}
#test(out, (1, 2, 3, 4, 5, "a", 6, "b", 7))
@@ -61,9 +61,9 @@
// Chars of string.
#let first = true
#let joined = for c in "abc" {
- if not first { ", " }
- first = false
- c
+ if not first { ", " }
+ first = false
+ c
}
#test(joined, "a, b, c")
@@ -81,7 +81,7 @@
// Keys and values of strings.
// Error: 6-10 mismatched pattern
#for k, v in "hi" {
- dont-care
+ dont-care
}
---
diff --git a/tests/typ/code/if.typ b/tests/typ/code/if.typ
index db8b059e..174e6978 100644
--- a/tests/typ/code/if.typ
+++ b/tests/typ/code/if.typ
@@ -3,46 +3,46 @@
---
// Test condition evaluation.
#if 1 < 2 [
- One.
+ One.
]
#if true == false [
- {Bad}, but we {dont-care}!
+ {Bad}, but we {dont-care}!
]
---
// Braced condition.
#if {true} [
- One.
+ One.
]
// Template in condition.
#if [] != none [
- Two.
+ Two.
]
// Multi-line condition with parens.
#if (
- 1 + 1
- == 1
+ 1 + 1
+ == 1
) [
- Nope.
+ Nope.
] #else {
- "Three."
+ "Three."
}
// Multiline.
#if false [
- Bad.
+ Bad.
] #else {
- let point = "."
- "Four" + point
+ let point = "."
+ "Four" + point
}
// Template can be argument or body depending on whitespace.
{
- if "template" == type[b] [Fi] else [Nope]
- if "template" == type [Nope] else [ve.]
+ if "template" == type[b] [Fi] else [Nope]
+ if "template" == type [Nope] else [ve.]
}
---
@@ -50,21 +50,21 @@
// Ref: false
{
- let x = 1
- let y = 2
- let z
+ let x = 1
+ let y = 2
+ let z
- // Returns if branch.
- z = if x < y { "ok" }
- test(z, "ok")
+ // Returns if branch.
+ z = if x < y { "ok" }
+ test(z, "ok")
- // Returns else branch.
- z = if x > y { "bad" } else { "ok" }
- test(z, "ok")
+ // Returns else branch.
+ z = if x > y { "bad" } else { "ok" }
+ test(z, "ok")
- // Missing else evaluates to none.
- z = if x > y { "bad" }
- test(z, none)
+ // Missing else evaluates to none.
+ z = if x > y { "bad" }
+ test(z, none)
}
---
diff --git a/tests/typ/code/import.typ b/tests/typ/code/import.typ
index 93d4d168..26a3404c 100644
--- a/tests/typ/code/import.typ
+++ b/tests/typ/code/import.typ
@@ -17,8 +17,8 @@
// Code mode
{
- import b from "target.typ"
- test(b, 1)
+ import b from "target.typ"
+ test(b, 1)
}
#test(b, 1)
diff --git a/tests/typ/code/include.typ b/tests/typ/code/include.typ
index 0d1abc08..8a9d0a30 100644
--- a/tests/typ/code/include.typ
+++ b/tests/typ/code/include.typ
@@ -14,8 +14,8 @@
---
{
- // Error: 21-43 file not found
- let x = include "importable/chap3.typ"
+ // Error: 19-41 file not found
+ let x = include "importable/chap3.typ"
}
---
diff --git a/tests/typ/code/ops-assoc.typ b/tests/typ/code/ops-assoc.typ
index 19c56951..ec128c61 100644
--- a/tests/typ/code/ops-assoc.typ
+++ b/tests/typ/code/ops-assoc.typ
@@ -10,9 +10,9 @@
---
// Assignment is right-associative.
{
- let x = 1
- let y = 2
- x = y = "ok"
- test(x, none)
- test(y, "ok")
+ let x = 1
+ let y = 2
+ x = y = "ok"
+ test(x, none)
+ test(y, "ok")
}
diff --git a/tests/typ/code/ops.typ b/tests/typ/code/ops.typ
index d8e87308..ca328e75 100644
--- a/tests/typ/code/ops.typ
+++ b/tests/typ/code/ops.typ
@@ -11,15 +11,15 @@
// Test plus and minus.
#for v in (1, 3.14, 12pt, 45deg, 90%, 13% + 10pt, 6.3fr) {
- // Test plus.
- test(+v, v)
+ // Test plus.
+ test(+v, v)
- // Test minus.
- test(-v, -1 * v)
- test(--v, v)
+ // Test minus.
+ test(-v, -1 * v)
+ test(--v, v)
- // Test combination.
- test(-++ --v, -v)
+ // Test combination.
+ test(-++ --v, -v)
}
#test(-(4 + 2), 6-12)
@@ -50,24 +50,24 @@
// Mathematical identities.
#let nums = (1, 3.14, 12pt, 45deg, 90%, 13% + 10pt)
#for v in nums {
- // Test plus and minus.
- test(v + v - v, v)
- test(v - v - v, -v)
-
- // Test plus/minus and multiplication.
- test(v - v, 0 * v)
- test(v + v, 2 * v)
-
- // Integer addition does not give a float.
- if type(v) != "integer" {
- test(v + v, 2.0 * v)
- }
-
- // Linears cannot be divided by themselves.
- if type(v) != "linear" {
- test(v / v, 1.0)
- test(v / v == 1, true)
- }
+ // Test plus and minus.
+ test(v + v - v, v)
+ test(v - v - v, -v)
+
+ // Test plus/minus and multiplication.
+ test(v - v, 0 * v)
+ test(v + v, 2 * v)
+
+ // Integer addition does not give a float.
+ if type(v) != "integer" {
+ test(v + v, 2.0 * v)
+ }
+
+ // Linears cannot be divided by themselves.
+ if type(v) != "linear" {
+ test(v / v, 1.0)
+ test(v / v == 1, true)
+ }
}
// Make sure length, relative and linear
@@ -76,15 +76,15 @@
// - divided by floats.
#let dims = (10pt, 30%, 50% + 3cm)
#for a in dims {
- for b in dims {
- test(type(a + b), type(a - b))
- }
-
- for b in (7, 3.14) {
- test(type(a * b), type(a))
- test(type(b * a), type(a))
- test(type(a / b), type(a))
- }
+ for b in dims {
+ test(type(a + b), type(a - b))
+ }
+
+ for b in (7, 3.14) {
+ test(type(a * b), type(a))
+ test(type(b * a), type(a))
+ test(type(a / b), type(a))
+ }
}
---
diff --git a/tests/typ/code/while.typ b/tests/typ/code/while.typ
index 2f0984d2..ccb67968 100644
--- a/tests/typ/code/while.typ
+++ b/tests/typ/code/while.typ
@@ -4,19 +4,19 @@
// Should output `2 4 6 8 10`.
#let i = 0
#while i < 10 [
- { i += 2 }
- #i
+ { i += 2 }
+ #i
]
// Should output `Hi`.
#let iter = true
#while iter {
- iter = false
- "Hi."
+ iter = false
+ "Hi."
}
#while false {
- dont-care
+ dont-care
}
---
@@ -36,8 +36,8 @@
---
// Make sure that we terminate and don't complain multiple times.
#while true {
- // Error: 5-9 unknown variable
- nope
+ // Error: 3-7 unknown variable
+ nope
}
---