summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ref/markup/heading.pngbin6611 -> 6406 bytes
-rw-r--r--tests/ref/markup/math.pngbin0 -> 2448 bytes
-rw-r--r--tests/typ/code/closure.typ46
-rw-r--r--tests/typ/code/import.typ2
-rw-r--r--tests/typ/code/let.typ2
-rw-r--r--tests/typ/code/spread.typ6
-rw-r--r--tests/typ/markup/heading.typ4
-rw-r--r--tests/typ/markup/math.typ12
-rw-r--r--tests/typ/markup/raw.typ2
-rw-r--r--tests/typeset.rs14
10 files changed, 73 insertions, 15 deletions
diff --git a/tests/ref/markup/heading.png b/tests/ref/markup/heading.png
index ca52644b..c33da420 100644
--- a/tests/ref/markup/heading.png
+++ b/tests/ref/markup/heading.png
Binary files differ
diff --git a/tests/ref/markup/math.png b/tests/ref/markup/math.png
new file mode 100644
index 00000000..426f3dbf
--- /dev/null
+++ b/tests/ref/markup/math.png
Binary files differ
diff --git a/tests/typ/code/closure.typ b/tests/typ/code/closure.typ
index 3b8b4261..14e74e7e 100644
--- a/tests/typ/code/closure.typ
+++ b/tests/typ/code/closure.typ
@@ -57,6 +57,52 @@
}
---
+// Import bindings.
+{
+ let b = "target.typ"
+ let f() = {
+ import b from b
+ b
+ }
+ test(f(), 1)
+}
+
+---
+// For loop bindings.
+{
+ let v = (1, 2, 3)
+ let s = 0
+ let f() = {
+ for v in v { s += v }
+ }
+ f()
+ test(s, 6)
+}
+
+---
+// Let + closure bindings.
+{
+ let g = "hi"
+ let f() = {
+ let g() = "bye"
+ g()
+ }
+ test(f(), "bye")
+}
+
+---
+// Parameter bindings.
+{
+ let x = 5
+ let g() = {
+ let f(x, y: x) = x + y
+ f
+ }
+
+ test(g()(8), 13)
+}
+
+---
// Don't leak environment.
{
// Error: 16-17 unknown variable
diff --git a/tests/typ/code/import.typ b/tests/typ/code/import.typ
index bc96e80c..683bb52a 100644
--- a/tests/typ/code/import.typ
+++ b/tests/typ/code/import.typ
@@ -79,7 +79,7 @@ This is never reached.
// Error: 22 expected keyword `from`
#import afrom, "b", c
-// Error: 8 expected import items
+// Error: 9 expected import items
#import from "target.typ"
// Error: 9-10 expected expression, found assignment operator
diff --git a/tests/typ/code/let.typ b/tests/typ/code/let.typ
index 3f3f9d35..cd7531b7 100644
--- a/tests/typ/code/let.typ
+++ b/tests/typ/code/let.typ
@@ -56,7 +56,7 @@ Three
#let v4 = 4 Four
// Terminated by semicolon even though we are in a paren group.
-// Error: 19 expected expression
+// Error: 18 expected expression
// Error: 19 expected closing paren
#let v5 = (1, 2 + ; Five
diff --git a/tests/typ/code/spread.typ b/tests/typ/code/spread.typ
index 8a9491d0..41e790a4 100644
--- a/tests/typ/code/spread.typ
+++ b/tests/typ/code/spread.typ
@@ -62,7 +62,7 @@
#min(.."nope")
---
-// Error: 10-14 expected identifier
+// Error: 8-14 expected identifier
#let f(..true) = none
---
@@ -70,9 +70,9 @@
#let f(..a, ..b) = none
---
-// Error: 5-6 spreading is not allowed here
+// Error: 3-6 spreading is not allowed here
{(..x)}
---
-// Error: 11-17 spreading is not allowed here
+// Error: 9-17 spreading is not allowed here
{(1, 2, ..(1, 2))}
diff --git a/tests/typ/markup/heading.typ b/tests/typ/markup/heading.typ
index 4647e7a6..cb022617 100644
--- a/tests/typ/markup/heading.typ
+++ b/tests/typ/markup/heading.typ
@@ -8,8 +8,8 @@
=== Level 2
====== Level 6
-// Too many hashtags.
-======= Level 7
+// At some point, it should stop shrinking.
+=========== Level 11
---
// Heading vs. no heading.
diff --git a/tests/typ/markup/math.typ b/tests/typ/markup/math.typ
new file mode 100644
index 00000000..cad01d10
--- /dev/null
+++ b/tests/typ/markup/math.typ
@@ -0,0 +1,12 @@
+// Test math formulas.
+
+---
+The sum of $a$ and $b$ is $a + b$.
+
+---
+We will show that:
+$[ a^2 + b^2 = c^2 ]$
+
+---
+// Error: 2:1 expected closing bracket and dollar sign
+$[a
diff --git a/tests/typ/markup/raw.typ b/tests/typ/markup/raw.typ
index d48432f7..0e053a9b 100644
--- a/tests/typ/markup/raw.typ
+++ b/tests/typ/markup/raw.typ
@@ -55,5 +55,5 @@ The keyword ```rust let```.
---
// Unterminated.
-// Error: 2:1 expected backtick(s)
+// Error: 2:1 expected 1 backtick
`endless
diff --git a/tests/typeset.rs b/tests/typeset.rs
index bde383c4..68e56343 100644
--- a/tests/typeset.rs
+++ b/tests/typeset.rs
@@ -24,7 +24,7 @@ use typst::loading::FsLoader;
use typst::parse::Scanner;
use typst::source::SourceFile;
use typst::style::Style;
-use typst::syntax::{Pos, Span};
+use typst::syntax::Span;
use typst::Context;
const TYP_DIR: &str = "./typ";
@@ -355,12 +355,12 @@ fn parse_metadata(source: &SourceFile) -> (Option<bool>, Vec<Error>) {
let comments =
lines[i ..].iter().take_while(|line| line.starts_with("//")).count();
- let pos = |s: &mut Scanner| -> Pos {
+ let pos = |s: &mut Scanner| -> usize {
let first = num(s) - 1;
let (delta, column) =
if s.eat_if(':') { (first, num(s) - 1) } else { (0, first) };
let line = (i + comments) + delta;
- source.line_column_to_byte(line, column).unwrap().into()
+ source.line_column_to_byte(line, column).unwrap()
};
let mut s = Scanner::new(rest);
@@ -375,10 +375,10 @@ fn parse_metadata(source: &SourceFile) -> (Option<bool>, Vec<Error>) {
}
fn print_error(source: &SourceFile, line: usize, error: &Error) {
- let start_line = 1 + line + source.byte_to_line(error.span.start.to_usize()).unwrap();
- let start_col = 1 + source.byte_to_column(error.span.start.to_usize()).unwrap();
- let end_line = 1 + line + source.byte_to_line(error.span.end.to_usize()).unwrap();
- let end_col = 1 + source.byte_to_column(error.span.end.to_usize()).unwrap();
+ let start_line = 1 + line + source.byte_to_line(error.span.start).unwrap();
+ let start_col = 1 + source.byte_to_column(error.span.start).unwrap();
+ let end_line = 1 + line + source.byte_to_line(error.span.end).unwrap();
+ let end_col = 1 + source.byte_to_column(error.span.end).unwrap();
println!(
"Error: {}:{}-{}:{}: {}",
start_line, start_col, end_line, end_col, error.message