summaryrefslogtreecommitdiff
path: root/tests/typ/layout
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-11-29 13:37:25 +0100
committerLaurenz <laurmaedje@gmail.com>2022-11-29 14:18:13 +0100
commit0efe669278a5e1c3f2985eba2f3360e91159c54a (patch)
tree502712857c48f0decb5e698257c0a96d358a436e /tests/typ/layout
parent836692e73cff0356e409a9ba5b4887b86809d4ca (diff)
Reorganize library and tests
Diffstat (limited to 'tests/typ/layout')
-rw-r--r--tests/typ/layout/flow-orphan.typ (renamed from tests/typ/layout/orphan-widow.typ)9
-rw-r--r--tests/typ/layout/hide.typ5
-rw-r--r--tests/typ/layout/math.typ20
-rw-r--r--tests/typ/layout/orphan-heading.typ8
-rw-r--r--tests/typ/layout/par-bidi.typ57
-rw-r--r--tests/typ/layout/par-indent.typ37
-rw-r--r--tests/typ/layout/par-justify.typ33
-rw-r--r--tests/typ/layout/par-knuth.typ30
-rw-r--r--tests/typ/layout/par-simple.typ20
-rw-r--r--tests/typ/layout/par.typ45
-rw-r--r--tests/typ/layout/repeat.typ39
-rw-r--r--tests/typ/layout/transform.typ49
12 files changed, 323 insertions, 29 deletions
diff --git a/tests/typ/layout/orphan-widow.typ b/tests/typ/layout/flow-orphan.typ
index 445b44e3..a51da2b2 100644
--- a/tests/typ/layout/orphan-widow.typ
+++ b/tests/typ/layout/flow-orphan.typ
@@ -1,4 +1,11 @@
-// Test widow and orphan prevention.
+// Test that a heading doesn't become an orphan.
+
+---
+#set page(height: 100pt)
+#lorem(12)
+
+= Introduction
+This is the start and it goes on.
---
#set page("a8", height: 150pt)
diff --git a/tests/typ/layout/hide.typ b/tests/typ/layout/hide.typ
new file mode 100644
index 00000000..a979b24f
--- /dev/null
+++ b/tests/typ/layout/hide.typ
@@ -0,0 +1,5 @@
+// Test the `hide` function.
+
+---
+AB #h(1fr) CD \
+#hide[A]B #h(1fr) C#hide[D]
diff --git a/tests/typ/layout/math.typ b/tests/typ/layout/math.typ
deleted file mode 100644
index 55a853cf..00000000
--- a/tests/typ/layout/math.typ
+++ /dev/null
@@ -1,20 +0,0 @@
-// Test math formulas.
-
----
-The sum of $a$ and $b$ is $a + b$.
-
----
-We will show that:
-$ a^2 + b^2 = c^2 $
-
----
-Prove by induction:
-$ sum_(k=0)^n k = (n(n+1))/2 $
-
----
-// Test that blackboard style looks nice.
-$ f: NN arrow RR $
-
----
-// Error: 1:3 expected dollar sign
-$a
diff --git a/tests/typ/layout/orphan-heading.typ b/tests/typ/layout/orphan-heading.typ
deleted file mode 100644
index ef3de885..00000000
--- a/tests/typ/layout/orphan-heading.typ
+++ /dev/null
@@ -1,8 +0,0 @@
-// Test that a heading doesn't become an orphan.
-
----
-#set page(height: 100pt)
-#lorem(12)
-
-= Introduction
-This is the start and it goes on.
diff --git a/tests/typ/layout/par-bidi.typ b/tests/typ/layout/par-bidi.typ
new file mode 100644
index 00000000..11c0cafa
--- /dev/null
+++ b/tests/typ/layout/par-bidi.typ
@@ -0,0 +1,57 @@
+// Test bidirectional text and language configuration.
+
+---
+// Test reordering with different top-level paragraph directions.
+#let content = par[Text טֶקסט]
+#set text("IBM Plex Serif")
+#text(lang: "he", content)
+#text(lang: "de", content)
+
+---
+// Test that consecutive, embedded LTR runs stay LTR.
+// Here, we have two runs: "A" and italic "B".
+#let content = par[أنت A#emph[B]مطرC]
+#set text("IBM Plex Serif", "Noto Sans Arabic")
+#text(lang: "ar", content)
+#text(lang: "de", content)
+
+---
+// Test that consecutive, embedded RTL runs stay RTL.
+// Here, we have three runs: "גֶ", bold "שֶׁ", and "ם".
+#let content = par[Aגֶ#strong[שֶׁ]םB]
+#set text("IBM Plex Serif", "Noto Serif Hebrew")
+#text(lang: "he", content)
+#text(lang: "de", content)
+
+---
+// Test embedding up to level 4 with isolates.
+#set text(dir: rtl, "IBM Plex Serif")
+א\u{2066}A\u{2067}Bב\u{2069}?
+
+---
+// Test hard line break (leads to two paragraphs in unicode-bidi).
+#set text(lang: "ar", "Noto Sans Arabic", "IBM Plex Serif")
+Life المطر هو الحياة \
+الحياة تمطر is rain.
+
+---
+// Test spacing.
+#set text("IBM Plex Serif")
+L #h(1cm) ריווחR \
+Lריווח #h(1cm) R
+
+---
+// Test inline object.
+#set text(lang: "he", "IBM Plex Serif")
+קרנפיםRh#image("/res/rhino.png", height: 11pt)inoחיים
+
+---
+// Test whether L1 whitespace resetting destroys stuff.
+الغالب #h(70pt) ن{" "}ة
+
+---
+// Test setting a vertical direction.
+// Ref: false
+
+// Error: 16-19 must be horizontal
+#set text(dir: ttb)
diff --git a/tests/typ/layout/par-indent.typ b/tests/typ/layout/par-indent.typ
new file mode 100644
index 00000000..8454dda5
--- /dev/null
+++ b/tests/typ/layout/par-indent.typ
@@ -0,0 +1,37 @@
+// Test paragraph indent.
+
+---
+#set par(indent: 12pt, leading: 5pt)
+#set block(spacing: 5pt)
+#show heading: set text(size: 10pt)
+
+The first paragraph has no indent.
+
+But the second one does.
+
+#image("/res/tiger.jpg", height: 6pt)
+starts a paragraph without indent.
+
+#align(center, image("/res/rhino.png", width: 1cm))
+
+= Headings
+- And lists.
+- Have no indent.
+
+ Except if you have another paragraph in them.
+
+#set text(8pt, lang: "ar", "Noto Sans Arabic", "IBM Plex Sans")
+#set par(leading: 8pt)
+
+= Arabic
+دع النص يمطر عليك
+
+ثم يصبح النص رطبًا وقابل للطرق ويبدو المستند رائعًا.
+
+
+---
+// This is madness.
+#set par(indent: 12pt)
+Why would anybody ever ...
+
+... want spacing and indent?
diff --git a/tests/typ/layout/par-justify.typ b/tests/typ/layout/par-justify.typ
new file mode 100644
index 00000000..e3d61322
--- /dev/null
+++ b/tests/typ/layout/par-justify.typ
@@ -0,0 +1,33 @@
+
+---
+#set page(width: 180pt)
+#set block(spacing: 5pt)
+#set par(justify: true, indent: 14pt, leading: 5pt)
+
+This text is justified, meaning that spaces are stretched so that the text
+forms a "block" with flush edges at both sides.
+
+First line indents and hyphenation play nicely with justified text.
+
+---
+// Test that lines with hard breaks aren't justified.
+#set par(justify: true)
+A B C \
+D
+
+---
+// Test forced justification with justified break.
+A B C #linebreak(justify: true)
+D E F #linebreak(justify: true)
+
+---
+// Test that justificating chinese text is at least a bit sensible.
+#set page(width: 200pt)
+#set par(justify: true)
+中文维基百科使用汉字书写,汉字是汉族或华人的共同文字,是中国大陆、新加坡、马来西亚、台湾、香港、澳门的唯一官方文字或官方文字之一。25.9%,而美国和荷兰则分別占13.7%及8.2%。近年來,中国大陆地区的维基百科编辑者正在迅速增加;
+
+---
+// Test that there are no hick-ups with justification enabled and
+// basically empty paragraph.
+#set par(justify: true)
+{""}
diff --git a/tests/typ/layout/par-knuth.typ b/tests/typ/layout/par-knuth.typ
new file mode 100644
index 00000000..59349738
--- /dev/null
+++ b/tests/typ/layout/par-knuth.typ
@@ -0,0 +1,30 @@
+#set page(width: auto, height: auto)
+#set par(leading: 4pt, justify: true)
+#set text(family: "Latin Modern Roman")
+
+#let story = [
+ In olden times when wishing still helped one, there lived a king whose
+ daughters were all beautiful; and the youngest was so beautiful that the sun
+ itself, which has seen so much, was astonished whenever it shone in her face.
+ Close by the king’s castle lay a great dark forest, and under an old lime-tree
+ in the forest was a well, and when the day was very warm, the king’s child
+ went out into the forest and sat down by the side of the cool fountain; and
+ when she was bored she took a golden ball, and threw it up on high and caught
+ it; and this ball was her favorite plaything.
+]
+
+#let column(title, linebreaks, hyphenate) = {
+ rect(width: 132pt, fill: rgb("eee"))[
+ #set par(linebreaks: linebreaks)
+ #set text(hyphenate: hyphenate)
+ #strong(title) \ #story
+ ]
+}
+
+#grid(
+ columns: 3,
+ gutter: 10pt,
+ column([Simple without hyphens], "simple", false),
+ column([Simple with hyphens], "simple", true),
+ column([Optimized with hyphens], "optimized", true),
+)
diff --git a/tests/typ/layout/par-simple.typ b/tests/typ/layout/par-simple.typ
new file mode 100644
index 00000000..34a2d626
--- /dev/null
+++ b/tests/typ/layout/par-simple.typ
@@ -0,0 +1,20 @@
+// Test plain text.
+
+---
+#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
+pale with grief, That thou her maid art far more fair than she: Be not her maid,
+since she is envious; Her vestal livery is but sick and green And none but fools
+do wear it; cast it off. It is my lady, O, it is my love! O, that she knew she
+were! She speaks yet she says nothing: what of that? Her eye discourses; I will
+answer it.
+
+I am too bold, 'tis not to me she speaks: Two of the fairest stars in all the
+heaven, Having some business, do entreat her eyes To twinkle in their spheres
+till they return. What if her eyes were there, they in her head? The brightness
+of her cheek would shame those stars, As daylight doth a lamp; her eyes in
+heaven Would through the airy region stream so bright That birds would sing and
+think it were not night. See, how she leans her cheek upon her hand! O, that I
+were a glove upon that hand, That I might touch that cheek!
diff --git a/tests/typ/layout/par.typ b/tests/typ/layout/par.typ
new file mode 100644
index 00000000..558059e9
--- /dev/null
+++ b/tests/typ/layout/par.typ
@@ -0,0 +1,45 @@
+// Test configuring paragraph properties.
+
+---
+// Test ragged-left.
+#set par(align: right)
+To the right! Where the sunlight peeks behind the mountain.
+
+---
+// Test changing leading and spacing.
+#set block(spacing: 1em)
+#set par(leading: 2pt)
+But, soft! what light through yonder window breaks?
+
+It is the east, and Juliet is the sun.
+
+---
+// Test that paragraph spacing loses against block spacing.
+// TODO
+#set block(spacing: 100pt)
+#show table: set block(above: 5pt, below: 5pt)
+Hello
+#table(columns: 4, fill: (x, y) => if odd(x + y) { silver })[A][B][C][D]
+
+---
+// While we're at it, test the larger block spacing wins.
+#set block(spacing: 0pt)
+#show raw: set block(spacing: 15pt)
+#show math: set block(spacing: 7.5pt)
+#show list: set block(spacing: 2.5pt)
+
+```rust
+fn main() {}
+```
+
+- List
+
+Paragraph
+
+---
+// Error: 17-20 must be horizontal
+#set par(align: top)
+
+---
+// Error: 17-33 expected alignment, found 2d alignment
+#set par(align: horizon + center)
diff --git a/tests/typ/layout/repeat.typ b/tests/typ/layout/repeat.typ
new file mode 100644
index 00000000..13e99b51
--- /dev/null
+++ b/tests/typ/layout/repeat.typ
@@ -0,0 +1,39 @@
+// Test the `repeat` function.
+
+---
+// Test multiple repeats.
+#let sections = (
+ ("Introduction", 1),
+ ("Approach", 1),
+ ("Evaluation", 3),
+ ("Discussion", 15),
+ ("Related Work", 16),
+ ("Conclusion", 253),
+)
+
+#for section in sections [
+ #section(0) #repeat[.] #section(1) \
+]
+
+---
+// Test dots with RTL.
+#set text(lang: "ar")
+مقدمة #repeat[.] 15
+
+---
+// Test empty repeat.
+A #repeat[] B
+
+---
+// Test spaceless repeat.
+A#repeat(rect(width: 2.5em, height: 1em))B
+
+---
+// Test single repeat in both directions.
+A#repeat(rect(width: 6em, height: 0.7em))B
+
+#set par(align: center)
+A#repeat(rect(width: 6em, height: 0.7em))B
+
+#set text(dir: rtl)
+ريجين#repeat(rect(width: 4em, height: 0.7em))سون
diff --git a/tests/typ/layout/transform.typ b/tests/typ/layout/transform.typ
new file mode 100644
index 00000000..2dde626b
--- /dev/null
+++ b/tests/typ/layout/transform.typ
@@ -0,0 +1,49 @@
+// Test transformations.
+
+---
+// Test creating the TeX and XeTeX logos.
+#let size = 11pt
+#let tex = [{
+ [T]
+ h(-0.14 * size)
+ move(dy: 0.22 * size)[E]
+ h(-0.12 * size)
+ [X]
+}]
+
+#let xetex = {
+ [X]
+ h(-0.14 * size)
+ scale(x: -100%, move(dy: 0.26 * size)[E])
+ h(-0.14 * size)
+ [T]
+ h(-0.14 * size)
+ move(dy: 0.26 * size)[E]
+ h(-0.12 * size)
+ [X]
+}
+
+#set text("Latin Modern Roman", size)
+Neither #tex, \
+nor #xetex!
+
+---
+// Test combination of scaling and rotation.
+#set page(height: 80pt)
+#align(center + horizon,
+ rotate(20deg, scale(70%, image("/res/tiger.jpg")))
+)
+
+---
+// Test setting rotation origin.
+#rotate(10deg, origin: top + left,
+ image("/res/tiger.jpg", width: 50%)
+)
+
+---
+// Test setting scaling origin.
+#let r = rect(width: 100pt, height: 10pt, fill: forest)
+#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)