summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-01-03 12:29:35 +0100
committerLaurenz <laurmaedje@gmail.com>2023-01-03 12:32:17 +0100
commit29b31c4a5ac4cde311c4d38b3d70130e7d27ba76 (patch)
treefe4e5dbd2166a69af90e69578ad4602725cdb63c /tests
parent54962e6dcd002fd27918827996155fd7dc4e1cff (diff)
New import syntax
Diffstat (limited to 'tests')
-rw-r--r--tests/ref/compiler/import.pngbin4538 -> 4091 bytes
-rw-r--r--tests/src/benches.rs3
-rw-r--r--tests/src/tests.rs2
-rw-r--r--tests/typ/compiler/block.typ2
-rw-r--r--tests/typ/compiler/closure.typ2
-rw-r--r--tests/typ/compiler/field.typ2
-rw-r--r--tests/typ/compiler/import.typ120
-rw-r--r--tests/typ/compiler/modules/cycle1.typ2
-rw-r--r--tests/typ/compiler/modules/cycle2.typ2
-rw-r--r--tests/typ/compiler/show-node.typ2
10 files changed, 70 insertions, 67 deletions
diff --git a/tests/ref/compiler/import.png b/tests/ref/compiler/import.png
index dddbe408..89880086 100644
--- a/tests/ref/compiler/import.png
+++ b/tests/ref/compiler/import.png
Binary files differ
diff --git a/tests/src/benches.rs b/tests/src/benches.rs
index 2c693c7c..610b89a8 100644
--- a/tests/src/benches.rs
+++ b/tests/src/benches.rs
@@ -72,7 +72,8 @@ fn bench_typeset(iai: &mut Iai) {
let world = BenchWorld::new();
let route = typst::model::Route::default();
let module = typst::model::eval(world.track(), route.track(), &world.source).unwrap();
- iai.run(|| typst::model::typeset(world.track(), &module.content));
+ let content = module.content();
+ iai.run(|| typst::model::typeset(world.track(), &content));
}
fn bench_compile(iai: &mut Iai) {
diff --git a/tests/src/tests.rs b/tests/src/tests.rs
index 9dc7aa6d..16dea380 100644
--- a/tests/src/tests.rs
+++ b/tests/src/tests.rs
@@ -432,7 +432,7 @@ fn test_part(
let world = (world as &dyn World).track();
let route = typst::model::Route::default();
let module = typst::model::eval(world, route.track(), source).unwrap();
- println!("Model:\n{:#?}\n", module.content);
+ println!("Model:\n{:#?}\n", module.content());
}
let (mut frames, errors) = match typst::compile(world, source) {
diff --git a/tests/typ/compiler/block.typ b/tests/typ/compiler/block.typ
index 45f63f8e..7cf1f8be 100644
--- a/tests/typ/compiler/block.typ
+++ b/tests/typ/compiler/block.typ
@@ -79,7 +79,7 @@
---
// Double block creates a scope.
{{
- import b from "module.typ"
+ import "module.typ": b
test(b, 1)
}}
diff --git a/tests/typ/compiler/closure.typ b/tests/typ/compiler/closure.typ
index 2c6c1ea0..c7321204 100644
--- a/tests/typ/compiler/closure.typ
+++ b/tests/typ/compiler/closure.typ
@@ -62,7 +62,7 @@
{
let b = "module.typ"
let f() = {
- import b from b
+ import b: b
b
}
test(f(), 1)
diff --git a/tests/typ/compiler/field.typ b/tests/typ/compiler/field.typ
index 1235c84e..78439ae0 100644
--- a/tests/typ/compiler/field.typ
+++ b/tests/typ/compiler/field.typ
@@ -31,7 +31,7 @@
{false.ok}
---
-// Error: 29-32 unknown field "fun"
+// Error: 29-32 unknown field `fun`
#show heading: node => node.fun
= A
diff --git a/tests/typ/compiler/import.typ b/tests/typ/compiler/import.typ
index 0620403d..6f2ac459 100644
--- a/tests/typ/compiler/import.typ
+++ b/tests/typ/compiler/import.typ
@@ -1,116 +1,118 @@
// Test module imports.
+// Ref: false
---
-// Test importing semantics.
-
-// A named import.
-#import item from "module.typ"
-#test(item(1, 2), 3)
+// Test basic syntax and semantics.
+// Ref: true
// Test that this will be overwritten.
#let value = [foo]
// Import multiple things.
-#import fn, value from "module.typ"
+#import "module.typ": fn, value
#fn[Like and Subscribe!]
#value
+// Should output `bye`.
+// Stop at semicolon.
+#import "module.typ": a, c;bye
+
+---
+// An item import.
+#import "module.typ": item
+#test(item(1, 2), 3)
+
// Code mode
{
- import b from "module.typ"
+ import "module.typ": b
test(b, 1)
}
// A wildcard import.
-#import * from "module.typ"
+#import "module.typ": *
// It exists now!
-#d
+#test(d, 3)
-// Who needs whitespace anyways?
-#import*from"module.typ"
+---
+// A module import without items.
+#import "module.typ"
+#test(module.b, 1)
+#test((module.item)(1, 2), 3)
-// Should output `bye`.
-// Stop at semicolon.
-#import a, c from "module.typ";bye
+---
+// Who needs whitespace anyways?
+#import"module.typ":*
// Allow the trailing comma.
-#import a, c, from "module.typ"
+#import "module.typ": a, c,
---
-// Error: 19-21 failed to load file (is a directory)
-#import name from ""
+// Error: 9-11 failed to load file (is a directory)
+#import "": name
---
-// Error: 16-27 file not found (searched at typ/compiler/lib/0.2.1)
-#import * from "lib/0.2.1"
+// Error: 9-20 file not found (searched at typ/compiler/lib/0.2.1)
+#import "lib/0.2.1"
---
// Some non-text stuff.
-// Error: 16-37 file is not valid utf-8
-#import * from "../../res/rhino.png"
+// Error: 9-30 file is not valid utf-8
+#import "../../res/rhino.png"
---
// Unresolved import.
-// Error: 9-21 unresolved import
-#import non_existing from "module.typ"
+// Error: 23-35 unresolved import
+#import "module.typ": non_existing
---
// Cyclic import of this very file.
-// Error: 16-30 cyclic import
-#import * from "./import.typ"
+// Error: 9-23 cyclic import
+#import "./import.typ"
---
// Cyclic import in other file.
-#import * from "./modules/cycle1.typ"
+#import "./modules/cycle1.typ": *
This is never reached.
---
-// Error: 8 expected import items
-// Error: 8 expected keyword `from`
+// Error: 8 expected expression
#import
-// Error: 9-19 expected identifier, found string
-// Error: 19 expected keyword `from`
-#import "file.typ"
-
-// Error: 16-19 expected identifier, found string
-// Error: 22 expected keyword `from`
-#import afrom, "b", c
-
-// Error: 9 expected import items
-#import from "module.typ"
+---
+// Error: 26-29 expected identifier, found string
+#import "module.typ": a, "b", c
-// Error: 9-10 expected expression, found assignment operator
-// Error: 10 expected import items
-#import = from "module.typ"
+---
+// Error: 22 expected import items
+#import "module.typ":
-// Error: 15 expected expression
-#import * from
+---
+// Error: 23-24 expected expression, found assignment operator
+// Error: 24 expected import items
+#import "module.typ": =
+---
// An additional trailing comma.
-// Error: 17-18 expected expression, found comma
-#import a, b, c,, from "module.typ"
-
-// Error: 1-6 unexpected keyword `from`
-#from "module.typ"
+// Error: 31-32 expected expression, found comma
+#import "module.typ": a, b, c,,
+---
// Error: 2:2 expected semicolon or line break
-#import * from "module.typ
-"target
-
-// Error: 28 expected semicolon or line break
-#import * from "module.typ" ยง 0.2.1
+#import "module.typ
+"stuff
+---
// A star in the list.
-// Error: 12-13 expected expression, found star
-#import a, *, b from "module.typ"
+// Error: 26-27 expected expression, found star
+#import "module.typ": a, *, b
+---
// An item after a star.
-// Error: 10 expected keyword `from`
-#import *, a from "module.typ"
+// Error: 24 expected semicolon or line break
+#import "module.typ": *, a
---
-// Error: 9-13 expected identifier, found named pair
-#import a: 1 from ""
+// Error: 13-17 expected identifier, found named pair
+#import "": a: 1
diff --git a/tests/typ/compiler/modules/cycle1.typ b/tests/typ/compiler/modules/cycle1.typ
index a9c00f5e..02067b71 100644
--- a/tests/typ/compiler/modules/cycle1.typ
+++ b/tests/typ/compiler/modules/cycle1.typ
@@ -1,6 +1,6 @@
// Ref: false
-#import * from "cycle2.typ"
+#import "cycle2.typ": *
#let inaccessible = "wow"
This is the first element of an import cycle.
diff --git a/tests/typ/compiler/modules/cycle2.typ b/tests/typ/compiler/modules/cycle2.typ
index 204da519..191647db 100644
--- a/tests/typ/compiler/modules/cycle2.typ
+++ b/tests/typ/compiler/modules/cycle2.typ
@@ -1,6 +1,6 @@
// Ref: false
-#import * from "cycle1.typ"
+#import "cycle1.typ": *
#let val = "much cycle"
This is the second element of an import cycle.
diff --git a/tests/typ/compiler/show-node.typ b/tests/typ/compiler/show-node.typ
index 5dd7ad98..46663c68 100644
--- a/tests/typ/compiler/show-node.typ
+++ b/tests/typ/compiler/show-node.typ
@@ -78,7 +78,7 @@ Another text.
= Heading
---
-// Error: 25-29 unknown field "page"
+// Error: 25-29 unknown field `page`
#show heading: it => it.page
= Heading