summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPg Biel <9021226+PgBiel@users.noreply.github.com>2023-05-03 09:20:53 -0300
committerGitHub <noreply@github.com>2023-05-03 14:20:53 +0200
commitf88ef45ee6e285df59c7aa5cec935de331b4b6e0 (patch)
treeeab5481d4b50d1d57adb4d122d7fa023dee2dcec /tests
parentdb6a710638cf26ddcd09b8fba74b9d1caf6cb4b8 (diff)
Function scopes (#1032)
Diffstat (limited to 'tests')
-rw-r--r--tests/ref/compiler/import.pngbin4446 -> 5941 bytes
-rw-r--r--tests/ref/layout/enum.pngbin16078 -> 18946 bytes
-rw-r--r--tests/typ/compiler/field.typ24
-rw-r--r--tests/typ/compiler/import.typ45
-rw-r--r--tests/typ/compute/foundations.typ26
-rw-r--r--tests/typ/layout/enum.typ12
6 files changed, 106 insertions, 1 deletions
diff --git a/tests/ref/compiler/import.png b/tests/ref/compiler/import.png
index bf95f45d..5c6132d2 100644
--- a/tests/ref/compiler/import.png
+++ b/tests/ref/compiler/import.png
Binary files differ
diff --git a/tests/ref/layout/enum.png b/tests/ref/layout/enum.png
index fb2c2a63..94a9ed51 100644
--- a/tests/ref/layout/enum.png
+++ b/tests/ref/layout/enum.png
Binary files differ
diff --git a/tests/typ/compiler/field.typ b/tests/typ/compiler/field.typ
index d1e4a31a..dd8499ce 100644
--- a/tests/typ/compiler/field.typ
+++ b/tests/typ/compiler/field.typ
@@ -23,6 +23,30 @@
- C
---
+// Test fields on function scopes.
+#enum.item
+#assert.eq
+#assert.ne
+
+---
+// Error: 9-16 function `assert` does not contain field `invalid`
+#assert.invalid
+
+---
+// Error: 7-14 function `enum` does not contain field `invalid`
+#enum.invalid
+
+---
+// Error: 7-14 function `enum` does not contain field `invalid`
+#enum.invalid()
+
+---
+// Closures cannot have fields.
+#let f(x) = x
+// Error: 4-11 cannot access fields on user-defined functions
+#f.invalid
+
+---
// Error: 6-13 dictionary does not contain key "invalid" and no default value was specified
#(:).invalid
diff --git a/tests/typ/compiler/import.typ b/tests/typ/compiler/import.typ
index 68b6af2e..0f161766 100644
--- a/tests/typ/compiler/import.typ
+++ b/tests/typ/compiler/import.typ
@@ -1,4 +1,4 @@
-// Test module imports.
+// Test function and module imports.
// Ref: false
---
@@ -35,6 +35,20 @@
#test(d, 3)
---
+// Test importing from function scopes.
+// Ref: true
+
+#import enum: item
+#import assert.with(true): *
+
+#enum(
+ item(1)[First],
+ item(5)[Fifth]
+)
+#eq(10, 10)
+#ne(5, 6)
+
+---
// A module import without items.
#import "module.typ"
#test(module.b, 1)
@@ -60,6 +74,35 @@
#import "module.typ": a, c,
---
+// Usual importing syntax also works for function scopes
+#import enum
+#let d = (e: enum)
+#import d.e
+#import d.e: item
+
+#item(2)[a]
+
+---
+// Can't import from closures.
+#let f(x) = x
+// Error: 9-10 cannot import from user-defined functions
+#import f: x
+
+---
+// Can't import from closures, despite modifiers.
+#let f(x) = x
+// Error: 9-18 cannot import from user-defined functions
+#import f.with(5): x
+
+---
+// Error: 9-18 cannot import from user-defined functions
+#import () => {5}: x
+
+---
+// Error: 9-10 expected path, module or function, found integer
+#import 5: something
+
+---
// Error: 9-11 failed to load file (is a directory)
#import "": name
diff --git a/tests/typ/compute/foundations.typ b/tests/typ/compute/foundations.typ
index c74a4cd6..9c7b13ca 100644
--- a/tests/typ/compute/foundations.typ
+++ b/tests/typ/compute/foundations.typ
@@ -41,6 +41,32 @@
#assert("true")
---
+// Test failing assertions.
+// Error: 11-19 equality assertion failed: value 10 was not equal to 11
+#assert.eq(10, 11)
+
+---
+// Test failing assertions.
+// Error: 11-55 equality assertion failed: 10 and 12 are not equal
+#assert.eq(10, 12, message: "10 and 12 are not equal")
+
+---
+// Test failing assertions.
+// Error: 11-19 inequality assertion failed: value 11 was equal to 11
+#assert.ne(11, 11)
+
+---
+// Test failing assertions.
+// Error: 11-57 inequality assertion failed: must be different from 11
+#assert.ne(11, 11, message: "must be different from 11")
+
+---
+// Test successful assertions.
+#assert(5 > 3)
+#assert.eq(15, 15)
+#assert.ne(10, 12)
+
+---
// Test the `type` function.
#test(type(1), "integer")
#test(type(ltr), "direction")
diff --git a/tests/typ/layout/enum.typ b/tests/typ/layout/enum.typ
index 2606a64d..a90e1896 100644
--- a/tests/typ/layout/enum.typ
+++ b/tests/typ/layout/enum.typ
@@ -36,6 +36,18 @@ Empty \
a + 0.
---
+// Test item number overriding.
+1. first
++ second
+5. fifth
+
+#enum(
+ enum.item(1)[First],
+ [Second],
+ enum.item(5)[Fifth]
+)
+
+---
// Alignment shouldn't affect number
#set align(horizon)