summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPg Biel <9021226+PgBiel@users.noreply.github.com>2023-08-30 08:36:02 -0300
committerGitHub <noreply@github.com>2023-08-30 13:36:02 +0200
commit19b91d59d1467956f8175146a16b63d303eee0d7 (patch)
treee2099ccec6fd1fa260597cb9700cbff43e747199 /tests
parent8a0dd88f1073f8fac9b2db022027eae3752dffd7 (diff)
Allow renaming imports with `as` (#1923)
Diffstat (limited to 'tests')
-rw-r--r--tests/typ/compiler/import.typ91
1 files changed, 91 insertions, 0 deletions
diff --git a/tests/typ/compiler/import.typ b/tests/typ/compiler/import.typ
index 7f6baee0..e5a7a858 100644
--- a/tests/typ/compiler/import.typ
+++ b/tests/typ/compiler/import.typ
@@ -35,6 +35,16 @@
#test(d, 3)
---
+// A renamed item import.
+#import "module.typ": item as something
+#test(something(1, 2), 3)
+
+// Mixing renamed and not renamed items.
+#import "module.typ": fn, b as val, item as other
+#test(val, 1)
+#test(other(1, 2), 3)
+
+---
// Test importing from function scopes.
// Ref: true
@@ -49,6 +59,11 @@
#ne(5, 6)
---
+// Test renaming items imported from function scopes.
+#import assert: eq as aseq
+#aseq(10, 10)
+
+---
// A module import without items.
#import "module.typ"
#test(module.b, 1)
@@ -56,6 +71,32 @@
#test(module.push(2), 3)
---
+// A renamed module import without items.
+#import "module.typ" as other
+#test(other.b, 1)
+#test(other.item(1, 2), 3)
+#test(other.push(2), 3)
+
+---
+// Mixing renamed module and items.
+#import "module.typ" as newname: b as newval, item
+#test(newname.b, 1)
+#test(newval, 1)
+#test(item(1, 2), 3)
+#test(newname.item(1, 2), 3)
+
+---
+// Renamed module import with function scopes.
+#import enum as othernum
+#test(enum, othernum)
+
+---
+// Mixing renamed module import from function with renamed item import.
+#import assert as asrt
+#import asrt: ne as asne
+#asne(1, 2)
+
+---
// Edge case for module access that isn't fixed.
#import "module.typ"
@@ -78,17 +119,43 @@
#import enum
#let d = (e: enum)
#import d.e
+#import d.e as renamed
#import d.e: item
#item(2)[a]
---
+// Warning: 23-27 unnecessary import rename to same name
+#import enum: item as item
+
+---
+// Warning: 17-21 unnecessary import rename to same name
+#import enum as enum
+
+---
+// Warning: 17-21 unnecessary import rename to same name
+#import enum as enum: item
+// Warning: 17-21 unnecessary import rename to same name
+// Warning: 31-35 unnecessary import rename to same name
+#import enum as enum: item as item
+
+---
+// No warning on a case that isn't obviously pathological
+#import "module.typ" as module
+
+---
// 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 renaming.
+#let f(x) = x
+// Error: 9-10 cannot import from user-defined functions
+#import f as g
+
+---
// Can't import from closures, despite modifiers.
#let f(x) = x
// Error: 9-18 cannot import from user-defined functions
@@ -103,14 +170,26 @@
#import 5: something
---
+// Error: 9-10 expected path, module or function, found integer
+#import 5 as x
+
+---
// Error: 9-11 failed to load file (is a directory)
#import "": name
---
+// Error: 9-11 failed to load file (is a directory)
+#import "" as x
+
+---
// Error: 9-20 file not found (searched at typ/compiler/lib/0.2.1)
#import "lib/0.2.1"
---
+// Error: 9-20 file not found (searched at typ/compiler/lib/0.2.1)
+#import "lib/0.2.1" as x
+
+---
// Some non-text stuff.
// Error: 9-27 file is not valid utf-8
#import "/files/rhino.png"
@@ -132,6 +211,18 @@
This is never reached.
---
+// Renaming does not import the old name (without items).
+#import "module.typ" as something
+// Error: 7-13 unknown variable: module
+#test(module.b, 1)
+
+---
+// Renaming does not import the old name (with items).
+#import "module.typ" as something: b as other
+// Error: 7-13 unknown variable: module
+#test(module.b, 1)
+
+---
// Error: 8 expected expression
#import