diff options
| author | Martin <mhaug@live.de> | 2021-12-22 20:37:34 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-22 20:37:34 +0100 |
| commit | f6c7a8292dc1ab0560408fca9d74505e9d7cf13a (patch) | |
| tree | badd3076f6146cec34c55764600df5124c408521 /tests | |
| parent | 738ff7e1f573bef678932b313be9969a17af8d22 (diff) | |
| parent | 438255519e88bb790480306b9a9b452aaf054519 (diff) | |
Merge pull request #51 from typst/set-rules
Set rules
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/README.md | 35 | ||||
| -rw-r--r-- | tests/ref/elements/circle.png | bin | 18873 -> 0 bytes | |||
| -rw-r--r-- | tests/ref/elements/ellipse.png | bin | 9597 -> 0 bytes | |||
| -rw-r--r-- | tests/ref/layout/box-block.png (renamed from tests/ref/layout/containers.png) | bin | 5194 -> 5194 bytes | |||
| -rw-r--r-- | tests/ref/layout/image.png (renamed from tests/ref/elements/image.png) | bin | 186196 -> 186196 bytes | |||
| -rw-r--r-- | tests/ref/layout/pagebreak.png | bin | 3145 -> 3788 bytes | |||
| -rw-r--r-- | tests/ref/layout/place-background.png (renamed from tests/ref/layout/background.png) | bin | 80160 -> 80160 bytes | |||
| -rw-r--r-- | tests/ref/layout/place.png (renamed from tests/ref/layout/placed.png) | bin | 31901 -> 33917 bytes | |||
| -rw-r--r-- | tests/ref/layout/shape-aspect.png (renamed from tests/ref/layout/aspect.png) | bin | 3601 -> 3601 bytes | |||
| -rw-r--r-- | tests/ref/layout/shape-circle.png | bin | 0 -> 18861 bytes | |||
| -rw-r--r-- | tests/ref/layout/shape-ellipse.png | bin | 0 -> 9455 bytes | |||
| -rw-r--r-- | tests/ref/layout/shape-fill-stroke.png (renamed from tests/ref/elements/fill-stroke.png) | bin | 1942 -> 1942 bytes | |||
| -rw-r--r-- | tests/ref/layout/shape-rect.png (renamed from tests/ref/elements/rect.png) | bin | 2914 -> 2914 bytes | |||
| -rw-r--r-- | tests/ref/layout/shape-square.png (renamed from tests/ref/elements/square.png) | bin | 6585 -> 6585 bytes | |||
| -rw-r--r-- | tests/ref/layout/spacing.png | bin | 1827 -> 2927 bytes | |||
| -rw-r--r-- | tests/ref/layout/transform.png | bin | 54558 -> 54712 bytes | |||
| -rw-r--r-- | tests/ref/markup/heading.png | bin | 6406 -> 9141 bytes | |||
| -rw-r--r-- | tests/ref/style/set-block.png | bin | 0 -> 812 bytes | |||
| -rw-r--r-- | tests/ref/style/set-site.png | bin | 0 -> 4252 bytes | |||
| -rw-r--r-- | tests/ref/style/set-toggle.png | bin | 0 -> 968 bytes | |||
| -rw-r--r-- | tests/ref/text/em.png | bin | 0 -> 878 bytes | |||
| -rw-r--r-- | tests/ref/text/links.png | bin | 10708 -> 22561 bytes | |||
| -rw-r--r-- | tests/ref/text/par.png | bin | 5732 -> 8169 bytes | |||
| -rw-r--r-- | tests/ref/text/whitespace.png | bin | 5322 -> 4674 bytes | |||
| -rw-r--r-- | tests/typ/code/call.typ | 11 | ||||
| -rw-r--r-- | tests/typ/code/include.typ | 2 | ||||
| -rw-r--r-- | tests/typ/code/ops-invalid.typ | 2 | ||||
| -rw-r--r-- | tests/typ/code/ops.typ | 10 | ||||
| -rw-r--r-- | tests/typ/code/spread.typ | 10 | ||||
| -rw-r--r-- | tests/typ/coma.typ | 5 | ||||
| -rw-r--r-- | tests/typ/layout/align.typ | 2 | ||||
| -rw-r--r-- | tests/typ/layout/box-block.typ (renamed from tests/typ/layout/containers.typ) | 2 | ||||
| -rw-r--r-- | tests/typ/layout/grid-1.typ | 4 | ||||
| -rw-r--r-- | tests/typ/layout/grid-2.typ | 2 | ||||
| -rw-r--r-- | tests/typ/layout/grid-3.typ | 10 | ||||
| -rw-r--r-- | tests/typ/layout/grid-4.typ | 2 | ||||
| -rw-r--r-- | tests/typ/layout/grid-5.typ | 4 | ||||
| -rw-r--r-- | tests/typ/layout/image.typ (renamed from tests/typ/elements/image.typ) | 6 | ||||
| -rw-r--r-- | tests/typ/layout/pad.typ | 2 | ||||
| -rw-r--r-- | tests/typ/layout/page.typ | 28 | ||||
| -rw-r--r-- | tests/typ/layout/pagebreak.typ | 15 | ||||
| -rw-r--r-- | tests/typ/layout/place-background.typ (renamed from tests/typ/layout/background.typ) | 4 | ||||
| -rw-r--r-- | tests/typ/layout/place.typ (renamed from tests/typ/layout/placed.typ) | 15 | ||||
| -rw-r--r-- | tests/typ/layout/shape-aspect.typ (renamed from tests/typ/layout/aspect.typ) | 10 | ||||
| -rw-r--r-- | tests/typ/layout/shape-circle.typ (renamed from tests/typ/elements/circle.typ) | 4 | ||||
| -rw-r--r-- | tests/typ/layout/shape-ellipse.typ (renamed from tests/typ/elements/ellipse.typ) | 2 | ||||
| -rw-r--r-- | tests/typ/layout/shape-fill-stroke.typ (renamed from tests/typ/elements/fill-stroke.typ) | 0 | ||||
| -rw-r--r-- | tests/typ/layout/shape-rect.typ (renamed from tests/typ/elements/rect.typ) | 2 | ||||
| -rw-r--r-- | tests/typ/layout/shape-square.typ (renamed from tests/typ/elements/square.typ) | 6 | ||||
| -rw-r--r-- | tests/typ/layout/spacing.typ | 17 | ||||
| -rw-r--r-- | tests/typ/layout/stack-1.typ | 12 | ||||
| -rw-r--r-- | tests/typ/layout/stack-2.typ | 6 | ||||
| -rw-r--r-- | tests/typ/layout/transform.typ | 6 | ||||
| -rw-r--r-- | tests/typ/markup/heading.typ | 9 | ||||
| -rw-r--r-- | tests/typ/style/set-block.typ | 10 | ||||
| -rw-r--r-- | tests/typ/style/set-site.typ | 30 | ||||
| -rw-r--r-- | tests/typ/style/set-toggle.typ | 10 | ||||
| -rw-r--r-- | tests/typ/text/baseline.typ | 2 | ||||
| -rw-r--r-- | tests/typ/text/basic.typ | 2 | ||||
| -rw-r--r-- | tests/typ/text/bidi.typ | 42 | ||||
| -rw-r--r-- | tests/typ/text/chinese.typ | 2 | ||||
| -rw-r--r-- | tests/typ/text/decorations.typ | 2 | ||||
| -rw-r--r-- | tests/typ/text/em.typ | 17 | ||||
| -rw-r--r-- | tests/typ/text/features.typ | 71 | ||||
| -rw-r--r-- | tests/typ/text/font.typ | 70 | ||||
| -rw-r--r-- | tests/typ/text/links.typ | 11 | ||||
| -rw-r--r-- | tests/typ/text/par.typ | 39 | ||||
| -rw-r--r-- | tests/typ/text/shaping.typ | 10 | ||||
| -rw-r--r-- | tests/typ/text/tracking.typ | 6 | ||||
| -rw-r--r-- | tests/typ/text/whitespace.typ | 45 | ||||
| -rw-r--r-- | tests/typeset.rs | 106 |
71 files changed, 460 insertions, 260 deletions
diff --git a/tests/README.md b/tests/README.md index 57d47fe2..7343d868 100644 --- a/tests/README.md +++ b/tests/README.md @@ -15,9 +15,19 @@ Running the integration tests (the tests in this directory). cargo test --test typeset ``` -Running all tests whose names contain the word `filter`. +Running all tests whose paths contain the string `page` or `stack`. ```bash -cargo test --test typeset filter +cargo test --test typeset page stack +``` + +Running a test with the exact filename `page.typ`. +```bash +cargo test --test typeset -- --exact page.typ +``` + +Debug-printing the layout trees for all executed tests. +```bash +cargo test --test typeset -- --debug empty.typ ``` To make the integration tests go faster they don't generate PDFs by default. @@ -39,3 +49,24 @@ oxipng -o max path/to/image.png # All images oxipng -r -o max tests/ref ``` + +## Shorthand for running tests +If you want to have a quicker way to run the tests, consider adding a shortcut +to your shell profile so that you can simply write something like: +```bash +tests --debug empty.typ +``` + +### PowerShell +Open your PowerShell profile by executing `notepad $profile`. +```ps +function tests { + cargo test --test typeset -- $args +} +``` + +### Bash +Open your Bash configuration by executing `nano ~/.bashrc`. +```bash +alias tests="cargo test --test typeset --" +``` diff --git a/tests/ref/elements/circle.png b/tests/ref/elements/circle.png Binary files differdeleted file mode 100644 index 931debd0..00000000 --- a/tests/ref/elements/circle.png +++ /dev/null diff --git a/tests/ref/elements/ellipse.png b/tests/ref/elements/ellipse.png Binary files differdeleted file mode 100644 index 9a80c4c0..00000000 --- a/tests/ref/elements/ellipse.png +++ /dev/null diff --git a/tests/ref/layout/containers.png b/tests/ref/layout/box-block.png Binary files differindex f6981fe5..f6981fe5 100644 --- a/tests/ref/layout/containers.png +++ b/tests/ref/layout/box-block.png diff --git a/tests/ref/elements/image.png b/tests/ref/layout/image.png Binary files differindex bdcfd200..bdcfd200 100644 --- a/tests/ref/elements/image.png +++ b/tests/ref/layout/image.png diff --git a/tests/ref/layout/pagebreak.png b/tests/ref/layout/pagebreak.png Binary files differindex fbb1d00c..a6c0725e 100644 --- a/tests/ref/layout/pagebreak.png +++ b/tests/ref/layout/pagebreak.png diff --git a/tests/ref/layout/background.png b/tests/ref/layout/place-background.png Binary files differindex 805139f5..805139f5 100644 --- a/tests/ref/layout/background.png +++ b/tests/ref/layout/place-background.png diff --git a/tests/ref/layout/placed.png b/tests/ref/layout/place.png Binary files differindex 10a0bfd4..4fdb1f70 100644 --- a/tests/ref/layout/placed.png +++ b/tests/ref/layout/place.png diff --git a/tests/ref/layout/aspect.png b/tests/ref/layout/shape-aspect.png Binary files differindex f76b4980..f76b4980 100644 --- a/tests/ref/layout/aspect.png +++ b/tests/ref/layout/shape-aspect.png diff --git a/tests/ref/layout/shape-circle.png b/tests/ref/layout/shape-circle.png Binary files differnew file mode 100644 index 00000000..30734cb5 --- /dev/null +++ b/tests/ref/layout/shape-circle.png diff --git a/tests/ref/layout/shape-ellipse.png b/tests/ref/layout/shape-ellipse.png Binary files differnew file mode 100644 index 00000000..e3c63427 --- /dev/null +++ b/tests/ref/layout/shape-ellipse.png diff --git a/tests/ref/elements/fill-stroke.png b/tests/ref/layout/shape-fill-stroke.png Binary files differindex 2d04b3dd..2d04b3dd 100644 --- a/tests/ref/elements/fill-stroke.png +++ b/tests/ref/layout/shape-fill-stroke.png diff --git a/tests/ref/elements/rect.png b/tests/ref/layout/shape-rect.png Binary files differindex b6ab89aa..b6ab89aa 100644 --- a/tests/ref/elements/rect.png +++ b/tests/ref/layout/shape-rect.png diff --git a/tests/ref/elements/square.png b/tests/ref/layout/shape-square.png Binary files differindex 86bc1ff5..86bc1ff5 100644 --- a/tests/ref/elements/square.png +++ b/tests/ref/layout/shape-square.png diff --git a/tests/ref/layout/spacing.png b/tests/ref/layout/spacing.png Binary files differindex c653df6d..09f7d6d9 100644 --- a/tests/ref/layout/spacing.png +++ b/tests/ref/layout/spacing.png diff --git a/tests/ref/layout/transform.png b/tests/ref/layout/transform.png Binary files differindex 5abdef97..2593a3f2 100644 --- a/tests/ref/layout/transform.png +++ b/tests/ref/layout/transform.png diff --git a/tests/ref/markup/heading.png b/tests/ref/markup/heading.png Binary files differindex c33da420..52911d66 100644 --- a/tests/ref/markup/heading.png +++ b/tests/ref/markup/heading.png diff --git a/tests/ref/style/set-block.png b/tests/ref/style/set-block.png Binary files differnew file mode 100644 index 00000000..8ee5cfb6 --- /dev/null +++ b/tests/ref/style/set-block.png diff --git a/tests/ref/style/set-site.png b/tests/ref/style/set-site.png Binary files differnew file mode 100644 index 00000000..affe2e1c --- /dev/null +++ b/tests/ref/style/set-site.png diff --git a/tests/ref/style/set-toggle.png b/tests/ref/style/set-toggle.png Binary files differnew file mode 100644 index 00000000..ae8101ca --- /dev/null +++ b/tests/ref/style/set-toggle.png diff --git a/tests/ref/text/em.png b/tests/ref/text/em.png Binary files differnew file mode 100644 index 00000000..4c168db6 --- /dev/null +++ b/tests/ref/text/em.png diff --git a/tests/ref/text/links.png b/tests/ref/text/links.png Binary files differindex 18154a06..20b04a8e 100644 --- a/tests/ref/text/links.png +++ b/tests/ref/text/links.png diff --git a/tests/ref/text/par.png b/tests/ref/text/par.png Binary files differindex 47f0ed95..03117e67 100644 --- a/tests/ref/text/par.png +++ b/tests/ref/text/par.png diff --git a/tests/ref/text/whitespace.png b/tests/ref/text/whitespace.png Binary files differindex 7e79c177..36fb2475 100644 --- a/tests/ref/text/whitespace.png +++ b/tests/ref/text/whitespace.png diff --git a/tests/typ/code/call.typ b/tests/typ/code/call.typ index 2c16af1c..5736c63b 100644 --- a/tests/typ/code/call.typ +++ b/tests/typ/code/call.typ @@ -5,7 +5,8 @@ // Ref: true // Ommitted space. -[#font(weight:"bold")Bold] +#let f() = {} +[#f()*Bold*] // Call return value of function with body. #let f(x, body) = (y) => [#x] + body + [#y] @@ -44,25 +45,25 @@ } --- -// Error: 2-6 expected function or collection, found boolean +// Error: 2-6 expected callable or collection, found boolean {true()} --- #let x = "x" -// Error: 1-3 expected function or collection, found string +// Error: 1-3 expected callable or collection, found string #x() --- #let f(x) = x -// Error: 1-6 expected function or collection, found integer +// Error: 1-6 expected callable or collection, found integer #f(1)(2) --- #let f(x) = x -// Error: 1-6 expected function or collection, found template +// Error: 1-6 expected callable or collection, found template #f[1](2) --- diff --git a/tests/typ/code/include.typ b/tests/typ/code/include.typ index 83e00384..1e5d5827 100644 --- a/tests/typ/code/include.typ +++ b/tests/typ/code/include.typ @@ -1,7 +1,7 @@ // Test include statements. --- -#page(width: 200pt) +#set page(width: 200pt) = Document diff --git a/tests/typ/code/ops-invalid.typ b/tests/typ/code/ops-invalid.typ index 91dd576f..340e4c9f 100644 --- a/tests/typ/code/ops-invalid.typ +++ b/tests/typ/code/ops-invalid.typ @@ -26,7 +26,7 @@ {not ()} --- -// Error: 2-18 cannot apply '<=' to linear and relative +// Error: 2-18 cannot apply '<=' to relative length and relative {30% + 1pt <= 40%} --- diff --git a/tests/typ/code/ops.typ b/tests/typ/code/ops.typ index 04a72e72..be2cdb48 100644 --- a/tests/typ/code/ops.typ +++ b/tests/typ/code/ops.typ @@ -64,7 +64,7 @@ } // Linears cannot be divided by themselves. - if type(v) != "linear" { + if type(v) != "relative length" { test(v / v, 1.0) test(v / v == 1, true) } @@ -130,12 +130,14 @@ #test(test == test, true) #test((() => {}) == (() => {}), false) -// Templates also compare by identity. +// Templates compare by shallow equality. #let t = [a] #test(t == t, true) -#test([] == [], false) +#test([] == [], true) +#test([a] == [a], true) #test([] == [a], false) -#test([a] == [a], false) +#test([[a]] == [a], false) +#test(box[] == box[], false) --- // Test comparison operators. diff --git a/tests/typ/code/spread.typ b/tests/typ/code/spread.typ index 41e790a4..5f7d2061 100644 --- a/tests/typ/code/spread.typ +++ b/tests/typ/code/spread.typ @@ -4,14 +4,14 @@ --- // Test standard argument overriding. { - let font(style: "normal", weight: "regular") = { + let f(style: "normal", weight: "regular") = { "(style: " + style + ", weight: " + weight + ")" } - let myfont(..args) = font(weight: "bold", ..args) - test(myfont(), "(style: normal, weight: bold)") - test(myfont(weight: "black"), "(style: normal, weight: black)") - test(myfont(style: "italic"), "(style: italic, weight: bold)") + let myf(..args) = f(weight: "bold", ..args) + test(myf(), "(style: normal, weight: bold)") + test(myf(weight: "black"), "(style: normal, weight: black)") + test(myf(style: "italic"), "(style: italic, weight: bold)") } --- diff --git a/tests/typ/coma.typ b/tests/typ/coma.typ index 45d28f9a..ef9e9f86 100644 --- a/tests/typ/coma.typ +++ b/tests/typ/coma.typ @@ -1,4 +1,4 @@ -#page(width: 450pt, margins: 1cm) +#set page(width: 450pt, margins: 1cm) *Technische Universität Berlin* #h(1fr) *WiSe 2019/2020* \ *Fakultät II, Institut for Mathematik* #h(1fr) Woche 3 \ @@ -8,7 +8,8 @@ Ola Nordmann, John Doe #v(6mm) #align(center)[ - ==== 3. Übungsblatt Computerorientierte Mathematik II #v(4mm) + ==== 3. Übungsblatt Computerorientierte Mathematik II + #v(4mm) *Abgabe: 03.05.2019* (bis 10:10 Uhr in MA 001) #v(4mm) *Alle Antworten sind zu beweisen.* ] diff --git a/tests/typ/layout/align.typ b/tests/typ/layout/align.typ index 13b88ac1..09c4dee5 100644 --- a/tests/typ/layout/align.typ +++ b/tests/typ/layout/align.typ @@ -1,7 +1,7 @@ // Test alignment. --- -#page(height: 100pt) +#set page(height: 100pt) #stack(dir: ltr, align(left, square(size: 15pt, fill: eastern)), align(center, square(size: 20pt, fill: eastern)), diff --git a/tests/typ/layout/containers.typ b/tests/typ/layout/box-block.typ index d4556a0f..14258c1e 100644 --- a/tests/typ/layout/containers.typ +++ b/tests/typ/layout/box-block.typ @@ -12,7 +12,7 @@ Apart --- // Test block over multiple pages. -#page(height: 60pt) +#set page(height: 60pt) First! #block[ diff --git a/tests/typ/layout/grid-1.typ b/tests/typ/layout/grid-1.typ index 647e366f..a6596c98 100644 --- a/tests/typ/layout/grid-1.typ +++ b/tests/typ/layout/grid-1.typ @@ -3,7 +3,7 @@ --- #let cell(width, color) = rect(width: width, height: 2cm, fill: color) -#page(width: 100pt, height: 140pt) +#set page(width: 100pt, height: 140pt) #grid( columns: (auto, 1fr, 3fr, 0.25cm, 3%, 2mm + 10%), cell(0.5cm, rgb("2a631a")), @@ -31,7 +31,7 @@ ) --- -#page(height: 3cm, margins: 0pt) +#set page(height: 3cm, margins: 0pt) #grid( columns: (1fr,), rows: (1fr, auto, 2fr), diff --git a/tests/typ/layout/grid-2.typ b/tests/typ/layout/grid-2.typ index c522a402..7df64a56 100644 --- a/tests/typ/layout/grid-2.typ +++ b/tests/typ/layout/grid-2.typ @@ -1,7 +1,7 @@ // Test using the `grid` function to create a finance table. --- -#page(width: 12cm, height: 2.5cm) +#set page(width: 12cm, height: 2.5cm) #grid( columns: 5, column-gutter: (2fr, 1fr, 1fr), diff --git a/tests/typ/layout/grid-3.typ b/tests/typ/layout/grid-3.typ index 6f7f6977..8d04722e 100644 --- a/tests/typ/layout/grid-3.typ +++ b/tests/typ/layout/grid-3.typ @@ -1,7 +1,7 @@ // Test grid cells that overflow to the next region. --- -#page(width: 5cm, height: 3cm) +#set page(width: 5cm, height: 3cm) #grid( columns: 2, row-gutter: 8pt, @@ -18,7 +18,7 @@ --- // Test a column that starts overflowing right after another row/column did // that. -#page(width: 5cm, height: 2cm) +#set page(width: 5cm, height: 2cm) #grid( columns: 4 * (1fr,), row-gutter: 10pt, @@ -32,7 +32,7 @@ --- // Test two columns in the same row overflowing by a different amount. -#page(width: 5cm, height: 2cm) +#set page(width: 5cm, height: 2cm) #grid( columns: 3 * (1fr,), row-gutter: 8pt, @@ -48,7 +48,7 @@ --- // Test grid within a grid, overflowing. -#page(width: 5cm, height: 2.25cm) +#set page(width: 5cm, height: 2.25cm) #grid( columns: 4 * (1fr,), row-gutter: 10pt, @@ -62,7 +62,7 @@ --- // Test partition of `fr` units before and after multi-region layout. -#page(width: 5cm, height: 4cm) +#set page(width: 5cm, height: 4cm) #grid( columns: 2 * (1fr,), rows: (1fr, 2fr, auto, 1fr, 1cm), diff --git a/tests/typ/layout/grid-4.typ b/tests/typ/layout/grid-4.typ index d6aa6358..e02d98c5 100644 --- a/tests/typ/layout/grid-4.typ +++ b/tests/typ/layout/grid-4.typ @@ -23,7 +23,7 @@ --- // Test that all three kinds of rows use the correct bases. -#page(height: 4cm, margins: 0cm) +#set page(height: 4cm, margins: 0cm) #grid( rows: (1cm, 1fr, 1fr, auto), rect(height: 50%, width: 100%, fill: conifer), diff --git a/tests/typ/layout/grid-5.typ b/tests/typ/layout/grid-5.typ index 585fc6ce..db7c525a 100644 --- a/tests/typ/layout/grid-5.typ +++ b/tests/typ/layout/grid-5.typ @@ -1,7 +1,7 @@ --- // Test that trailing linebreak doesn't overflow the region. -#page(height: 2cm) +#set page(height: 2cm) #grid[ Hello \ Hello \ @@ -12,7 +12,7 @@ --- // Test that broken cell expands vertically. -#page(height: 2.25cm) +#set page(height: 2.25cm) #grid( columns: 2, gutter: 10pt, diff --git a/tests/typ/elements/image.typ b/tests/typ/layout/image.typ index 7fddb12d..8817713f 100644 --- a/tests/typ/elements/image.typ +++ b/tests/typ/layout/image.typ @@ -7,7 +7,7 @@ #image("../../res/rhino.png") // Load an RGB JPEG image. -#page(height: 60pt) +#set page(height: 60pt) #image("../../res/tiger.jpg") --- @@ -25,7 +25,7 @@ --- // Test all three fit modes. -#page(height: 50pt, margins: 0pt) +#set page(height: 50pt, margins: 0pt) #grid( columns: (1fr, 1fr, 1fr), rows: 100%, @@ -37,7 +37,7 @@ --- // Does not fit to remaining height of page. -#page(height: 60pt) +#set page(height: 60pt) Stuff \ Stuff #image("../../res/rhino.png") diff --git a/tests/typ/layout/pad.typ b/tests/typ/layout/pad.typ index 1fa0f79d..502137ec 100644 --- a/tests/typ/layout/pad.typ +++ b/tests/typ/layout/pad.typ @@ -19,7 +19,7 @@ Hi #box(pad(left: 10pt)[A]) there --- // Test that the pad node doesn't consume the whole region. -#page(height: 6cm) +#set page(height: 6cm) #align(left)[Before] #pad(10pt, image("../../res/tiger.jpg")) #align(right)[After] diff --git a/tests/typ/layout/page.typ b/tests/typ/layout/page.typ index dc6c7c81..35f338f4 100644 --- a/tests/typ/layout/page.typ +++ b/tests/typ/layout/page.typ @@ -2,33 +2,33 @@ --- // Set width and height. -#page(width: 80pt, height: 80pt) -[#page(width: 40pt) High] -[#page(height: 40pt) Wide] +#set page(width: 80pt, height: 80pt) +[#set page(width: 40pt);High] +[#set page(height: 40pt);Wide] // Set all margins at once. [ - #page(margins: 5pt) + #set page(margins: 5pt) #place(top + left)[TL] #place(bottom + right)[BR] ] // Set individual margins. -#page(height: 40pt) -[#page(left: 0pt) #align(left)[Left]] -[#page(right: 0pt) #align(right)[Right]] -[#page(top: 0pt) #align(top)[Top]] -[#page(bottom: 0pt) #align(bottom)[Bottom]] +#set page(height: 40pt) +[#set page(left: 0pt); #align(left)[Left]] +[#set page(right: 0pt); #align(right)[Right]] +[#set page(top: 0pt); #align(top)[Top]] +[#set page(bottom: 0pt); #align(bottom)[Bottom]] // Ensure that specific margins override general margins. -[#page(margins: 0pt, left: 20pt) Overriden] +[#set page(margins: 0pt, left: 20pt); Overriden] // Flipped predefined paper. -[#page(paper: "a11", flip: true) Flipped A11] +[#set page(paper: "a11", flipped: true);Flipped A11] --- -#page(width: 80pt, height: 40pt, fill: eastern) -#font(15pt, "Roboto", fill: white, smallcaps: true)[Typst] +#set page(width: 80pt, height: 40pt, fill: eastern) +#text(15pt, "Roboto", fill: white, smallcaps: true)[Typst] -#page(width: 40pt, fill: none, margins: auto, top: 10pt) +#set page(width: 40pt, fill: none, margins: auto, top: 10pt) Hi diff --git a/tests/typ/layout/pagebreak.typ b/tests/typ/layout/pagebreak.typ index f9a935bc..9a74d2bf 100644 --- a/tests/typ/layout/pagebreak.typ +++ b/tests/typ/layout/pagebreak.typ @@ -3,7 +3,8 @@ --- First of two #pagebreak() -#page(height: 40pt) +#set page(height: 40pt) +Second of two --- // Make sure that you can't do page related stuff in a container. @@ -11,7 +12,7 @@ A #box[ B #pagebreak() - #page("a4") + #set page("a4") ] C @@ -22,13 +23,13 @@ D --- // Test a combination of pages with bodies and normal content. -#page(width: 80pt, height: 30pt) +#set page(width: 80pt, height: 30pt) -[#page() First] -[#page() Second] +Fi[#set page(width: 80pt);rst] +[#set page(width: 70pt); Second] #pagebreak() #pagebreak() Fourth -[#page(height: 25pt)] +#page(height: 20pt)[] Sixth -[#page() Seventh] +[#set page(); Seventh] diff --git a/tests/typ/layout/background.typ b/tests/typ/layout/place-background.typ index 6303a83b..f64bf0ee 100644 --- a/tests/typ/layout/background.typ +++ b/tests/typ/layout/place-background.typ @@ -1,8 +1,8 @@ // Test placing a background image on a page. --- -#page(paper: "a10", flip: true) -#font(fill: white) +#set page(paper: "a10", flipped: true) +#set text(fill: white) #place( dx: -10pt, dy: -10pt, diff --git a/tests/typ/layout/placed.typ b/tests/typ/layout/place.typ index 334ff80d..527e0559 100644 --- a/tests/typ/layout/placed.typ +++ b/tests/typ/layout/place.typ @@ -1,4 +1,7 @@ -#page("a8") +// Test the `place` function. + +--- +#set page("a8") #place(bottom + center)[© Typst] = Placement @@ -20,3 +23,13 @@ the line breaks still had to be inserted manually. #place(center, dx: 7pt, dy: 5pt)[Hello] Hello #h(1fr) Hello ] + +--- +// Test how the placed node interacts with paragraph spacing around it. +#set page("a8", height: 60pt) + +First + +#place(bottom + right)[Placed] + +Second diff --git a/tests/typ/layout/aspect.typ b/tests/typ/layout/shape-aspect.typ index c9b8ee41..2c3e9b0c 100644 --- a/tests/typ/layout/aspect.typ +++ b/tests/typ/layout/shape-aspect.typ @@ -3,14 +3,14 @@ --- // Test relative width and height and size that is smaller // than default size. -#page(width: 120pt, height: 70pt) +#set page(width: 120pt, height: 70pt) #square(width: 50%, align(bottom)[A]) #square(height: 50%) #box(stack(square(size: 10pt), 5pt, square(size: 10pt, [B]))) --- // Test alignment in automatically sized square and circle. -#font(8pt) +#set text(8pt) #square(padding: 4pt)[ Hey there, #align(center + bottom, rotate(180deg, [you!])) ] @@ -23,19 +23,19 @@ --- // Test square that is limited by region size. -#page(width: 20pt, height: 10pt, margins: 0pt) +#set page(width: 20pt, height: 10pt, margins: 0pt) #stack(dir: ltr, square(fill: forest), square(fill: conifer)) --- // Test different ways of sizing. -#page(width: 120pt, height: 40pt) +#set page(width: 120pt, height: 40pt) #circle(radius: 5pt) #circle(width: 10%) #circle(height: 50%) --- // Test square that is overflowing due to its aspect ratio. -#page(width: 40pt, height: 20pt, margins: 5pt) +#set page(width: 40pt, height: 20pt, margins: 5pt) #square(width: 100%) #square(width: 100%)[Hello] diff --git a/tests/typ/elements/circle.typ b/tests/typ/layout/shape-circle.typ index ad9d3a4e..8b795830 100644 --- a/tests/typ/elements/circle.typ +++ b/tests/typ/layout/shape-circle.typ @@ -23,7 +23,7 @@ Center-aligned rect in auto-sized circle. Rect in auto-sized circle. \ #circle(fill: forest, rect(fill: conifer, stroke: white, padding: 4pt)[ - #font(8pt) + #set text(8pt) But, soft! what light through yonder window breaks? ] ) @@ -38,7 +38,7 @@ Expanded by height. --- // Test relative sizing. #let centered(body) = align(center + horizon, body) -#font(fill: white) +#set text(fill: white) #rect(width: 100pt, height: 50pt, fill: rgb("aaa"), centered[ #circle(radius: 10pt, fill: eastern, centered[A]) // D=20pt #circle(height: 60%, fill: eastern, centered[B]) // D=30pt diff --git a/tests/typ/elements/ellipse.typ b/tests/typ/layout/shape-ellipse.typ index 39c73a6f..154144c4 100644 --- a/tests/typ/elements/ellipse.typ +++ b/tests/typ/layout/shape-ellipse.typ @@ -18,6 +18,6 @@ Rect in ellipse in fixed rect. \ Auto-sized ellipse. \ #ellipse(fill: conifer, stroke: forest, thickness: 3pt, padding: 3pt)[ - #font(8pt) + #set text(8pt) But, soft! what light through yonder window breaks? ] diff --git a/tests/typ/elements/fill-stroke.typ b/tests/typ/layout/shape-fill-stroke.typ index 3ae5f987..3ae5f987 100644 --- a/tests/typ/elements/fill-stroke.typ +++ b/tests/typ/layout/shape-fill-stroke.typ diff --git a/tests/typ/elements/rect.typ b/tests/typ/layout/shape-rect.typ index b3d4d286..add39b80 100644 --- a/tests/typ/elements/rect.typ +++ b/tests/typ/layout/shape-rect.typ @@ -5,7 +5,7 @@ #rect() --- -#page(width: 150pt) +#set page(width: 150pt) // Fit to text. #rect(fill: conifer, padding: 3pt)[Textbox] diff --git a/tests/typ/elements/square.typ b/tests/typ/layout/shape-square.typ index f09fc3e0..c4ece778 100644 --- a/tests/typ/elements/square.typ +++ b/tests/typ/layout/shape-square.typ @@ -8,7 +8,7 @@ --- // Test auto-sized square. #square(fill: eastern, padding: 5pt)[ - #font(fill: white, weight: "bold") + #set text(fill: white, weight: "bold") Typst ] @@ -21,14 +21,14 @@ --- // Test text overflowing height. -#page(width: 75pt, height: 100pt) +#set page(width: 75pt, height: 100pt) #square(fill: conifer)[ But, soft! what light through yonder window breaks? ] --- // Test that square does not overflow page. -#page(width: 100pt, height: 75pt) +#set page(width: 100pt, height: 75pt) #square(fill: conifer)[ But, soft! what light through yonder window breaks? ] diff --git a/tests/typ/layout/spacing.typ b/tests/typ/layout/spacing.typ index 7cf6760f..37aa8eaa 100644 --- a/tests/typ/layout/spacing.typ +++ b/tests/typ/layout/spacing.typ @@ -18,6 +18,23 @@ Add #h(10pt) #h(10pt) up | #h(1fr) | #h(2fr) | #h(1fr) | --- +// Test spacing collapsing with parbreaks. +#v(0pt) +A +#v(0pt) +B +#v(0pt) + +C #parbreak() D + +--- +// Test that spacing can carry paragraph and page style properties. + +A[#set par(align: right);#h(1cm)]B +[#set page(height: 20pt);#v(1cm)] +B + +--- // Missing spacing. // Error: 11-13 missing argument: spacing Totally #h() ignored diff --git a/tests/typ/layout/stack-1.typ b/tests/typ/layout/stack-1.typ index 02083d2b..a4a0d6b8 100644 --- a/tests/typ/layout/stack-1.typ +++ b/tests/typ/layout/stack-1.typ @@ -15,13 +15,13 @@ #let items = for w in widths { (align(right, shaded(w)),) } -#page(width: 50pt, margins: 0pt) +#set page(width: 50pt, margins: 0pt) #stack(dir: btt, ..items) --- // Test RTL alignment. -#page(width: 50pt, margins: 5pt) -#font(8pt) +#set page(width: 50pt, margins: 5pt) +#set text(8pt) #stack(dir: rtl, align(center, [A]), align(left, [B]), @@ -30,8 +30,8 @@ --- // Test spacing. -#page(width: 50pt, margins: 0pt) -#par(spacing: 5pt) +#set page(width: 50pt, margins: 0pt) +#set par(spacing: 5pt) #let x = square(size: 10pt, fill: eastern) #stack(dir: rtl, spacing: 5pt, x, x, x) @@ -40,7 +40,7 @@ --- // Test overflow. -#page(width: 50pt, height: 30pt, margins: 0pt) +#set page(width: 50pt, height: 30pt, margins: 0pt) #box(stack( rect(width: 40pt, height: 20pt, fill: conifer), rect(width: 30pt, height: 13pt, fill: forest), diff --git a/tests/typ/layout/stack-2.typ b/tests/typ/layout/stack-2.typ index 2167f48f..f88f7a58 100644 --- a/tests/typ/layout/stack-2.typ +++ b/tests/typ/layout/stack-2.typ @@ -1,7 +1,7 @@ // Test fr units in stacks. --- -#page(height: 3.5cm) +#set page(height: 3.5cm) #stack( dir: ltr, spacing: 1fr, @@ -15,8 +15,8 @@ from #h(1fr) the #h(1fr) wonderful World! 🌍 --- -#page(height: 2cm) -#font(white) +#set page(height: 2cm) +#set text(white) #rect(fill: forest)[ #v(1fr) #h(1fr) Hi you! #h(5pt) diff --git a/tests/typ/layout/transform.typ b/tests/typ/layout/transform.typ index 5b1fa2a1..82ee1390 100644 --- a/tests/typ/layout/transform.typ +++ b/tests/typ/layout/transform.typ @@ -23,13 +23,13 @@ [X] } -#font("Latin Modern Math", size) +#set text("Latin Modern Math", size) Neither #tex, \ nor #xetex! --- // Test combination of scaling and rotation. -#page(height: 80pt) +#set page(height: 80pt) #align(center + horizon, rotate(20deg, scale(70%, image("../../res/tiger.jpg"))) ) @@ -43,7 +43,7 @@ nor #xetex! --- // Test setting scaling origin. #let r = rect(width: 100pt, height: 10pt, fill: forest) -#page(height: 65pt) +#set page(height: 65pt) #scale(r, x: 50%, y: 200%, origin: left + top) #scale(r, x: 50%, origin: center) #scale(r, x: 50%, y: 200%, origin: right + bottom) diff --git a/tests/typ/markup/heading.typ b/tests/typ/markup/heading.typ index cb022617..2ae97aa8 100644 --- a/tests/typ/markup/heading.typ +++ b/tests/typ/markup/heading.typ @@ -39,3 +39,12 @@ is not. = A { "B" } + +--- +// Test styling. += Heading + +#set heading(family: "Roboto", fill: eastern) + +===== Heading 🌍 +#heading(level: 5)[Heading] diff --git a/tests/typ/style/set-block.typ b/tests/typ/style/set-block.typ new file mode 100644 index 00000000..f260acdc --- /dev/null +++ b/tests/typ/style/set-block.typ @@ -0,0 +1,10 @@ +// Test set in code blocks. + +--- +// Test that template in block is not affected by set +// rule in block ... +A{set text(fill: eastern); [B]}C + +--- +// ... no matter the order. +A{[B]; set text(fill: eastern)}C diff --git a/tests/typ/style/set-site.typ b/tests/typ/style/set-site.typ new file mode 100644 index 00000000..0a00e199 --- /dev/null +++ b/tests/typ/style/set-site.typ @@ -0,0 +1,30 @@ +// Test that set affects the instantiation site and not the +// definition site of a template. + +--- +// Test that text is affected by instantiation-site bold. +#let x = [World] +Hello *{x}* + +--- +// Test that lists are affected by correct indents. +#set par(spacing: 4pt) +#let fruit = [ + - Apple + - Orange + #set list(body-indent: 10pt) + - Pear +] + +- Fruit +[#set list(label-indent: 10pt) + #fruit] +- No more fruit + +--- +// Test that that par spacing and text style are respected from +// the outside, but the more specific fill is respected. +#set par(spacing: 4pt) +#set text(style: "italic", fill: eastern) +#let x = [And the forest #parbreak() lay silent!] +#text(fill: forest, x) diff --git a/tests/typ/style/set-toggle.typ b/tests/typ/style/set-toggle.typ new file mode 100644 index 00000000..9f26bdf7 --- /dev/null +++ b/tests/typ/style/set-toggle.typ @@ -0,0 +1,10 @@ +// Test set rules for toggleable booleans. + +--- +// Test toggling and untoggling. +*AB_C*DE +*_* + +--- +// Test toggling and nested templates. +*A[B*[_C]]D*E diff --git a/tests/typ/text/baseline.typ b/tests/typ/text/baseline.typ index f22fce08..7100ab52 100644 --- a/tests/typ/text/baseline.typ +++ b/tests/typ/text/baseline.typ @@ -1,4 +1,4 @@ // Test text baseline. --- -Hi #font(150%)[You], #font(75%)[how are you?] +Hi #text(150%)[You], #text(75%)[how are you?] diff --git a/tests/typ/text/basic.typ b/tests/typ/text/basic.typ index 0c6c8896..a074a046 100644 --- a/tests/typ/text/basic.typ +++ b/tests/typ/text/basic.typ @@ -1,7 +1,7 @@ // Test simple text. --- -#page(width: 250pt, height: 120pt) +#set page(width: 250pt, height: 120pt) But, soft! what light through yonder window breaks? It is the east, and Juliet is the sun. Arise, fair sun, and kill the envious moon, Who is already sick and diff --git a/tests/typ/text/bidi.typ b/tests/typ/text/bidi.typ index 7d33aeea..658c7fa6 100644 --- a/tests/typ/text/bidi.typ +++ b/tests/typ/text/bidi.typ @@ -2,55 +2,55 @@ --- // Test reordering with different top-level paragraph directions. -#let text = [Text טֶקסט] -#font(serif, "Noto Serif Hebrew") -#par(lang: "he") {text} -#par(lang: "de") {text} +#let content = [Text טֶקסט] +#set text(serif, "Noto Serif Hebrew") +#par(lang: "he", content) +#par(lang: "de", content) --- // Test that consecutive, embedded LTR runs stay LTR. // Here, we have two runs: "A" and italic "B". -#let text = [أنت A_B_مطرC] -#font(serif, "Noto Sans Arabic") -#par(lang: "ar") {text} -#par(lang: "de") {text} +#let content = [أنت A_B_مطرC] +#set text(serif, "Noto Sans Arabic") +#par(lang: "ar", content) +#par(lang: "de", content) --- // Test that consecutive, embedded RTL runs stay RTL. // Here, we have three runs: "גֶ", bold "שֶׁ", and "ם". -#let text = [Aגֶ*שֶׁ*םB] -#font(serif, "Noto Serif Hebrew") -#par(lang: "he") {text} -#par(lang: "de") {text} +#let content = [Aגֶ*שֶׁ*םB] +#set text(serif, "Noto Serif Hebrew") +#par(lang: "he", content) +#par(lang: "de", content) --- // Test embedding up to level 4 with isolates. -#font(serif, "Noto Serif Hebrew", "Twitter Color Emoji") -#par(dir: rtl) +#set text(serif, "Noto Serif Hebrew", "Twitter Color Emoji") +#set par(dir: rtl) א\u{2066}A\u{2067}Bב\u{2069}? --- // Test hard line break (leads to two paragraphs in unicode-bidi). -#font("Noto Sans Arabic", serif) -#par(lang: "ar") +#set text("Noto Sans Arabic", serif) +#set par(lang: "ar") Life المطر هو الحياة \ الحياة تمطر is rain. --- // Test spacing. -#font(serif, "Noto Serif Hebrew") +#set text(serif, "Noto Serif Hebrew") L #h(1cm) ריווחR \ Lריווח #h(1cm) R --- // Test inline object. -#font("Noto Serif Hebrew", serif) -#par(lang: "he") +#set text("Noto Serif Hebrew", serif) +#set par(lang: "he") קרנפיםRh#image("../../res/rhino.png", height: 11pt)inoחיים --- // Test setting a vertical direction. // Ref: false -// Error: 11-14 must be horizontal -#par(dir: ttb) +// Error: 15-18 must be horizontal +#set par(dir: ttb) diff --git a/tests/typ/text/chinese.typ b/tests/typ/text/chinese.typ index 0800a220..04fa7027 100644 --- a/tests/typ/text/chinese.typ +++ b/tests/typ/text/chinese.typ @@ -1,7 +1,7 @@ // Test chinese text from Wikipedia. --- -#font("Noto Serif CJK SC") +#set text("Noto Serif CJK SC") 是美国广播公司电视剧《迷失》第3季的第22和23集,也是全剧的第71集和72集 由执行制作人戴蒙·林道夫和卡尔顿·库斯编剧,导演则是另一名执行制作人杰克·本德 diff --git a/tests/typ/text/decorations.typ b/tests/typ/text/decorations.typ index 9cd7b096..14dfe821 100644 --- a/tests/typ/text/decorations.typ +++ b/tests/typ/text/decorations.typ @@ -13,7 +13,7 @@ #underline(red)[Critical information is conveyed here.] // Inherits font color. -#font(fill: red, underline[Change with the wind.]) +#text(fill: red, underline[Change with the wind.]) // Both over- and underline. #overline(underline[Running amongst the wolves.]) diff --git a/tests/typ/text/em.typ b/tests/typ/text/em.typ new file mode 100644 index 00000000..d9b00f06 --- /dev/null +++ b/tests/typ/text/em.typ @@ -0,0 +1,17 @@ +// Test font-relative sizing. + +--- +#set text(size: 5pt) +A // 5pt +[ + #set text(size: 200%) + B // 10pt + [ + #set text(size: 150% + 1pt) + C // 16pt + #text(size: 200%)[D] // 32pt + E // 16pt + ] + F // 10pt +] +G // 5pt diff --git a/tests/typ/text/features.typ b/tests/typ/text/features.typ index d60583d8..3f61873e 100644 --- a/tests/typ/text/features.typ +++ b/tests/typ/text/features.typ @@ -2,72 +2,73 @@ --- // Test turning kerning off. -#font(kerning: true)[Tq] \ -#font(kerning: false)[Tq] +#text(kerning: true)[Tq] \ +#text(kerning: false)[Tq] --- // Test smallcaps. -#font("Roboto") -#font(smallcaps: true)[Smallcaps] +#set text("Roboto") +#text(smallcaps: true)[Smallcaps] --- // Test alternates and stylistic sets. -#font("IBM Plex Serif") -a vs #font(alternates: true)[a] \ -ß vs #font(stylistic-set: 5)[ß] +#set text("IBM Plex Serif") +a vs #text(alternates: true)[a] \ +ß vs #text(stylistic-set: 5)[ß] --- // Test ligatures. -fi vs. #font(ligatures: false)[No fi] \ +fi vs. #text(ligatures: false)[No fi] \ --- // Test number type. -#font("Roboto") -#font(number-type: "old-style") 0123456789 \ -#font(number-type: auto)[0123456789] +#set text("Roboto") +#set text(number-type: "old-style") +0123456789 \ +#text(number-type: auto)[0123456789] --- // Test number width. -#font("Roboto") -#font(number-width: "proportional")[0123456789] \ -#font(number-width: "tabular")[3456789123] \ -#font(number-width: "tabular")[0123456789] +#set text("Roboto") +#text(number-width: "proportional")[0123456789] \ +#text(number-width: "tabular")[3456789123] \ +#text(number-width: "tabular")[0123456789] --- // Test number position. -#font("IBM Plex Sans") -#font(number-position: "normal")[C2H4] \ -#font(number-position: "subscript")[C2H4] \ -#font(number-position: "superscript")[C2H4] +#set text("IBM Plex Sans") +#text(number-position: "normal")[C2H4] \ +#text(number-position: "subscript")[C2H4] \ +#text(number-position: "superscript")[C2H4] --- // Test extra number stuff. -#font("IBM Plex Sans") -0 vs. #font(slashed-zero: true)[0] \ -1/2 vs. #font(fractions: true)[1/2] +#set text("IBM Plex Sans") +0 vs. #text(slashed-zero: true)[0] \ +1/2 vs. #text(fractions: true)[1/2] --- // Test raw features. -#font("Roboto") -#font(features: ("smcp",))[Smcp] \ -fi vs. #font(features: (liga: 0))[No fi] +#set text("Roboto") +#text(features: ("smcp",))[Smcp] \ +fi vs. #text(features: (liga: 0))[No fi] --- -// Error: 22-27 expected integer or none, found boolean -#font(stylistic-set: false) +// Error: 26-31 expected integer or none, found boolean +#set text(stylistic-set: false) --- -// Error: 22-24 must be between 1 and 20 -#font(stylistic-set: 25) +// Error: 26-28 must be between 1 and 20 +#set text(stylistic-set: 25) --- -// Error: 20-21 expected string or auto, found integer -#font(number-type: 2) +// Error: 24-25 expected string or auto, found integer +#set text(number-type: 2) --- -// Error: 20-31 expected "lining" or "old-style" -#font(number-type: "different") +// Error: 24-35 expected "lining" or "old-style" +#set text(number-type: "different") --- -// Error: 17-22 expected array of strings or dictionary mapping tags to integers, found boolean -#font(features: false) +// Error: 21-26 expected array of strings or dictionary mapping tags to integers, found boolean +#set text(features: false) diff --git a/tests/typ/text/font.typ b/tests/typ/text/font.typ index 5c97d367..71ac8d3d 100644 --- a/tests/typ/text/font.typ +++ b/tests/typ/text/font.typ @@ -2,57 +2,57 @@ --- // Set same font size in three different ways. -#font(20pt)[A] -#font(200%)[A] -#font(size: 15pt + 50%)[A] +#text(20pt)[A] +#text(200%)[A] +#text(size: 15pt + 50%)[A] // Do nothing. -#font()[Normal] +#text()[Normal] // Set style (is available). -#font(style: "italic")[Italic] +#text(style: "italic")[Italic] // Set weight (is available). -#font(weight: "bold")[Bold] +#text(weight: "bold")[Bold] // Set stretch (not available, matching closest). -#font(stretch: 50%)[Condensed] +#text(stretch: 50%)[Condensed] // Set family. -#font(family: serif)[Serif] +#text(family: serif)[Serif] // Emoji. Emoji: 🐪, 🌋, 🏞 // Math. -#font("Latin Modern Math")[∫ 𝛼 + 3𝛽 d𝑡] +#text("Latin Modern Math")[∫ 𝛼 + 3𝛽 d𝑡] // Colors. [ - #font(fill: eastern) - This is #font(rgb("FA644B"))[way more] colorful. + #set text(fill: eastern) + This is #text(rgb("FA644B"))[way more] colorful. ] // Disable font fallback beyond the user-specified list. // Without disabling, Latin Modern Math would come to the rescue. -#font("PT Sans", "Twitter Color Emoji", fallback: false) +#set text("PT Sans", "Twitter Color Emoji", fallback: false) 2π = 𝛼 + 𝛽. ✅ --- // Test class definitions. -#font(sans-serif: "PT Sans") -#font(family: sans-serif)[Sans-serif.] \ -#font(monospace)[Monospace.] \ -#font(monospace, monospace: ("Nope", "Latin Modern Math"))[Math.] +#set text(sans-serif: "PT Sans") +#text(family: sans-serif)[Sans-serif.] \ +#text(monospace)[Monospace.] \ +#text(monospace, monospace: ("Nope", "Latin Modern Math"))[Math.] --- // Test top and bottom edge. -#page(width: 150pt) -#font(size: 8pt) +#set page(width: 150pt) +#set text(size: 8pt) #let try(top, bottom) = rect(fill: conifer)[ - #font(monospace, top-edge: top, bottom-edge: bottom) + #set text(monospace, top-edge: top, bottom-edge: bottom) From #top to #bottom ] @@ -64,33 +64,33 @@ Emoji: 🐪, 🌋, 🏞 #try(1pt + 27%, -18%) --- -// Error: 7-12 unexpected argument -#font(false) +// Error: 11-16 unexpected argument +#set text(false) --- -// Error: 14-20 expected "normal", "italic" or "oblique" -#font(style: "bold", weight: "thin") +// Error: 18-24 expected "normal", "italic" or "oblique" +#set text(style: "bold", weight: "thin") --- -// Error: 17-19 expected linear or string, found array -#font(top-edge: ()) +// Error: 21-23 expected linear or string, found array +#set text(top-edge: ()) --- -// Error: 17-19 unknown font metric -#font(top-edge: "") +// Error: 21-23 unknown font metric +#set text(top-edge: "") --- -// Error: 14-15 expected string or array of strings, found integer -#font(serif: 0) +// Error: 18-19 expected string or array of strings, found integer +#set text(serif: 0) --- -// Error: 19-23 unexpected argument -#font(size: 10pt, 12pt) +// Error: 23-27 unexpected argument +#set text(size: 10pt, 12pt) --- -// Error: 28-35 unexpected argument -#font(family: "Helvetica", "Arial") +// Error: 32-39 unexpected argument +#set text(family: "Helvetica", "Arial") --- -// Error: 7-27 unexpected argument -#font(something: "invalid") +// Error: 11-31 unexpected argument +#set text(something: "invalid") diff --git a/tests/typ/text/links.typ b/tests/typ/text/links.typ index e5f7affc..f2da8b9c 100644 --- a/tests/typ/text/links.typ +++ b/tests/typ/text/links.typ @@ -12,11 +12,18 @@ Contact #link("mailto:hi@typst.app") or call #link("tel:123") for more informati --- // Styled with underline and color. -#let link(url, body) = link(url, font(fill: rgb("283663"), underline(body))) +#let link(url, body) = link(url, text(fill: rgb("283663"), underline(body))) You could also make the #link("https://html5zombo.com/")[link look way more typical.] --- // Transformed link. -#page(height: 60pt) +#set page(height: 60pt) #let link = link("https://typst.app/")[LINK] My cool #move(x: 0.7cm, y: 0.7cm, rotate(10deg, scale(200%, link))) + +--- +// Link containing a block. +#link("https://example.com/", block[ + My cool rhino + #move(x: 10pt, image("../../res/rhino.png", width: 1cm)) +]) diff --git a/tests/typ/text/par.typ b/tests/typ/text/par.typ index 7b6bd289..8bd43deb 100644 --- a/tests/typ/text/par.typ +++ b/tests/typ/text/par.typ @@ -2,20 +2,47 @@ --- // Test ragged-left. -#par(align: right) +#set par(align: right) To the right! Where the sunlight peeks behind the mountain. --- +// Test that explicit paragraph break respects active styles. +#set par(spacing: 7pt) +[#set par(spacing: 100pt);First] + +[#set par(spacing: 100pt);Second] +#set par(spacing: 20pt) + +Third + +--- +// Test that paragraph spacing uses correct set rule. +Hello + +#set par(spacing: 100pt) +World +#set par(spacing: 0pt) + +You + +--- +// Test that paragraph break due to incompatibility respects +// spacing defined by the two adjacent paragraphs. +#let a = [#set par(spacing: 40pt);Hello] +#let b = [#set par(spacing: 60pt);World] +{a}{b} + +--- // Test weird metrics. -#par(spacing: 100%, leading: 0pt) +#set par(spacing: 100%, leading: 0pt) But, soft! what light through yonder window breaks? It is the east, and Juliet is the sun. --- -// Error: 13-16 must be horizontal -#par(align: top) +// Error: 17-20 must be horizontal +#set par(align: top) --- -// Error: 13-29 expected alignment, found 2d alignment -#par(align: horizon + center) +// Error: 17-33 expected alignment, found 2d alignment +#set par(align: horizon + center) diff --git a/tests/typ/text/shaping.typ b/tests/typ/text/shaping.typ index 1a8a7933..bb8f4ce9 100644 --- a/tests/typ/text/shaping.typ +++ b/tests/typ/text/shaping.typ @@ -7,11 +7,11 @@ Le fira // This should just shape nicely. -#font("Noto Sans Arabic") +#set text("Noto Sans Arabic") دع النص يمطر عليك // This should form a three-member family. -#font("Twitter Color Emoji") +#set text("Twitter Color Emoji") 👩👩👦 🤚🏿 // These two shouldn't be affected by a zero-width joiner. @@ -20,7 +20,7 @@ Le fira --- // Test font fallback. -#font(sans-serif, "Noto Sans Arabic", "Twitter Color Emoji") +#set text(sans-serif, "Noto Sans Arabic", "Twitter Color Emoji") // Font fallback for emoji. A😀B @@ -40,6 +40,6 @@ A🐈中文B --- // Test reshaping. -#font("Noto Serif Hebrew") -#par(lang: "he") +#set text("Noto Serif Hebrew") +#set par(lang: "he") ס \ טֶ diff --git a/tests/typ/text/tracking.typ b/tests/typ/text/tracking.typ index 695e6734..e3ff70ff 100644 --- a/tests/typ/text/tracking.typ +++ b/tests/typ/text/tracking.typ @@ -1,12 +1,12 @@ // Test tracking characters apart or together. --- -#font(tracking: -0.01) +#set text(tracking: -0.01) I saw Zoe yӛsterday, on the tram. --- -I'm in#font(tracking: 0.3)[ spaace]! +I'm in#text(tracking: 0.3)[ spaace]! --- -#font("Noto Serif Hebrew", tracking: 0.3) +#set text("Noto Serif Hebrew", tracking: 0.3) טֶקסט diff --git a/tests/typ/text/whitespace.typ b/tests/typ/text/whitespace.typ index e01b047c..831a5543 100644 --- a/tests/typ/text/whitespace.typ +++ b/tests/typ/text/whitespace.typ @@ -1,43 +1,36 @@ // Test whitespace handling. --- -// Spacing around let. +// Spacing around code constructs. A#let x = 1;B #test(x, 1) \ -A #let x = 2;B #test(x, 2) \ -A#let x = 3; B #test(x, 3) +C #let x = 2;D #test(x, 2) \ +E#if true [F]G \ +H #if true{"I"} J \ +K #if true [L] else []M \ +#let c = true; N#while c [{c = false}O] P \ +#let c = true; Q #while c { c = false; "R" } S \ +T#for _ in (none,) {"U"}V --- -// Spacing around if-else. -A#if true [B]C \ -A#if true [B] C \ -A #if true{"B"}C \ -A #if true{"B"} C \ -A#if false [] else [B]C \ -A#if true [B] else [] C - ---- -// Spacing around while loop. -#let c = true; A#while c [{c = false}B]C \ -#let c = true; A#while c [{c = false}B] C \ -#let c = true; A #while c { c = false; "B" }C \ -#let c = true; A #while c { c = false; "B" } C - ---- -// Spacing around for loop. -A#for _ in (none,) [B]C \ -A#for _ in (none,) [B] C \ -A #for _ in (none,) {"B"}C +// Test spacing with comments. +A/**/B/**/C \ +A /**/ B/**/C \ +A /**/B/**/ C --- // Test that a run consisting only of whitespace isn't trimmed. -A[#font(serif) ]B +A[#set text(serif); ]B --- // Test font change after space. -Left [#font(serif)Right]. +Left [#set text(serif);Right]. + +--- +// Test that linebreak consumed surrounding spaces. +#align(center)[A \ B \ C] --- -// Test that space at start of line is not trimmed. +// Test that space at start of non-backslash-linebreak line isn't trimmed. A{"\n"} B --- diff --git a/tests/typeset.rs b/tests/typeset.rs index 792251c3..c53250b3 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -12,20 +12,17 @@ use usvg::FitTo; use walkdir::WalkDir; use typst::diag::Error; -use typst::eval::{Smart, Value}; +use typst::eval::{Smart, Styles, Value}; use typst::font::Face; use typst::frame::{Element, Frame, Geometry, Group, Shape, Stroke, Text}; -use typst::geom::{ - self, Color, Length, Paint, PathElement, RgbaColor, Sides, Size, Transform, -}; +use typst::geom::{self, Color, Length, Paint, PathElement, RgbaColor, Size, Transform}; use typst::image::{Image, RasterImage, Svg}; -use typst::layout::layout; #[cfg(feature = "layout-cache")] -use typst::library::DocumentNode; +use typst::layout::RootNode; +use typst::library::{PageNode, TextNode}; use typst::loading::FsLoader; use typst::parse::Scanner; use typst::source::SourceFile; -use typst::style::Style; use typst::syntax::Span; use typst::Context; @@ -52,7 +49,7 @@ fn main() { continue; } - if args.matches(&src_path.to_string_lossy()) { + if args.matches(&src_path) { filtered.push(src_path); } } @@ -64,12 +61,17 @@ fn main() { println!("Running {} tests", len); } - // We want to have "unbounded" pages, so we allow them to be infinitely - // large and fit them to match their content. - let mut style = Style::default(); - style.page_mut().size = Size::new(Length::pt(120.0), Length::inf()); - style.page_mut().margins = Sides::splat(Smart::Custom(Length::pt(10.0).into())); - style.text_mut().size = Length::pt(10.0); + // Set page width to 120pt with 10pt margins, so that the inner page is + // exactly 100pt wide. Page height is unbounded and font size is 10pt so + // that it multiplies to nice round numbers. + let mut styles = Styles::new(); + styles.set(PageNode::WIDTH, Smart::Custom(Length::pt(120.0))); + styles.set(PageNode::HEIGHT, Smart::Auto); + styles.set(PageNode::LEFT, Smart::Custom(Length::pt(10.0).into())); + styles.set(PageNode::TOP, Smart::Custom(Length::pt(10.0).into())); + styles.set(PageNode::RIGHT, Smart::Custom(Length::pt(10.0).into())); + styles.set(PageNode::BOTTOM, Smart::Custom(Length::pt(10.0).into())); + styles.set(TextNode::SIZE, Length::pt(10.0).into()); // Hook up an assert function into the global scope. let mut std = typst::library::new(); @@ -87,10 +89,10 @@ fn main() { // Create loader and context. let loader = FsLoader::new().with_path(FONT_DIR).wrap(); - let mut ctx = Context::builder().std(std).style(style).build(loader); + let mut ctx = Context::builder().std(std).styles(styles).build(loader); // Run all the tests. - let mut ok = true; + let mut ok = 0; for src_path in filtered { let path = src_path.strip_prefix(TYP_DIR).unwrap(); let png_path = Path::new(PNG_DIR).join(path).with_extension("png"); @@ -98,49 +100,64 @@ fn main() { let pdf_path = args.pdf.then(|| Path::new(PDF_DIR).join(path).with_extension("pdf")); - ok &= test( + ok += test( &mut ctx, &src_path, &png_path, &ref_path, pdf_path.as_deref(), - ); + args.debug, + ) as usize; } - if !ok { + if len > 1 { + println!("{} / {} tests passed.", ok, len); + } + + if ok < len { std::process::exit(1); } } struct Args { filter: Vec<String>, + exact: bool, + debug: bool, pdf: bool, - perfect: bool, } impl Args { fn new(args: impl Iterator<Item = String>) -> Self { let mut filter = Vec::new(); - let mut perfect = false; + let mut exact = false; + let mut debug = false; let mut pdf = false; for arg in args { match arg.as_str() { + // Ignore this, its for cargo. "--nocapture" => {} + // Match only the exact filename. + "--exact" => exact = true, + // Generate PDFs. "--pdf" => pdf = true, - "=" => perfect = true, + // Debug print the layout trees. + "--debug" | "-d" => debug = true, + // Everything else is a file filter. _ => filter.push(arg), } } - Self { filter, pdf, perfect } + Self { filter, pdf, debug, exact } } - fn matches(&self, name: &str) -> bool { - if self.perfect { - self.filter.iter().any(|p| name == p) + fn matches(&self, path: &Path) -> bool { + if self.exact { + let name = path.file_name().unwrap().to_string_lossy(); + self.filter.iter().any(|v| v == &name) } else { - self.filter.is_empty() || self.filter.iter().any(|p| name.contains(p)) + let path = path.to_string_lossy(); + self.filter.is_empty() || self.filter.iter().any(|v| path.contains(v)) } } } @@ -151,6 +168,7 @@ fn test( png_path: &Path, ref_path: &Path, pdf_path: Option<&Path>, + debug: bool, ) -> bool { let name = src_path.strip_prefix(TYP_DIR).unwrap_or(src_path); println!("Testing {}", name.display()); @@ -179,7 +197,7 @@ fn test( } } else { let (part_ok, compare_here, part_frames) = - test_part(ctx, src_path, part.into(), i, compare_ref, line); + test_part(ctx, src_path, part.into(), i, compare_ref, line, debug); ok &= part_ok; compare_ever |= compare_here; frames.extend(part_frames); @@ -211,7 +229,10 @@ fn test( } if ok { - println!("\x1b[1ATesting {} ✔", name.display()); + if !debug { + print!("\x1b[1A"); + } + println!("Testing {} ✔", name.display()); } ok @@ -224,6 +245,7 @@ fn test_part( i: usize, compare_ref: bool, line: usize, + debug: bool, ) -> (bool, bool, Vec<Rc<Frame>>) { let id = ctx.sources.provide(src_path, src); let source = ctx.sources.get(id); @@ -232,12 +254,17 @@ fn test_part( let compare_ref = local_compare_ref.unwrap_or(compare_ref); let mut ok = true; - let (frames, mut errors) = match ctx.execute(id) { - Ok(document) => { - let mut frames = layout(ctx, &document); + let (frames, mut errors) = match ctx.evaluate(id) { + Ok(module) => { + let tree = module.into_root(); + if debug { + println!("{:#?}", tree); + } + + let mut frames = tree.layout(ctx); #[cfg(feature = "layout-cache")] - (ok &= test_incremental(ctx, i, &document, &frames)); + (ok &= test_incremental(ctx, i, &tree, &frames)); if !compare_ref { frames.clear(); @@ -285,7 +312,7 @@ fn test_part( fn test_incremental( ctx: &mut Context, i: usize, - document: &DocumentNode, + tree: &RootNode, frames: &[Rc<Frame>], ) -> bool { let mut ok = true; @@ -300,7 +327,7 @@ fn test_incremental( ctx.layouts.turnaround(); - let cached = silenced(|| layout(ctx, document)); + let cached = silenced(|| tree.layout(ctx)); let misses = ctx .layouts .entries() @@ -319,7 +346,10 @@ fn test_incremental( } if cached != frames { - println!(" Subtest {} relayout differs from clean pass ❌", i); + println!( + " Subtest {} relayout differs from clean pass on level {} ❌", + i, level + ); ok = false; } } @@ -504,7 +534,7 @@ fn draw_text( let mut x = 0.0; for glyph in &text.glyphs { let glyph_id = GlyphId(glyph.id); - let offset = x + glyph.x_offset.to_length(text.size).to_f32(); + let offset = x + glyph.x_offset.resolve(text.size).to_f32(); let ts = ts.pre_translate(offset, 0.0); if let Some(tree) = ttf @@ -557,7 +587,7 @@ fn draw_text( } } - x += glyph.x_advance.to_length(text.size).to_f32(); + x += glyph.x_advance.resolve(text.size).to_f32(); } } |
