summaryrefslogtreecommitdiff
path: root/tests/typ/library
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-01-14 16:47:29 +0100
committerLaurenz <laurmaedje@gmail.com>2021-01-14 16:47:29 +0100
commitcfcb36b159e3f65aff8cbdac6b537b40c22507c0 (patch)
tree18e17b3cec5530b67ec596fe13b45423a867eb5f /tests/typ/library
parent272a4c228976466e9fa6cc100ad89f93dc5cc371 (diff)
Move test files into category subfolders 🚚
Diffstat (limited to 'tests/typ/library')
-rw-r--r--tests/typ/library/font.typ56
-rw-r--r--tests/typ/library/hv.typ22
-rw-r--r--tests/typ/library/image.typ39
-rw-r--r--tests/typ/library/page.typ54
-rw-r--r--tests/typ/library/pagebreak.typ3
-rw-r--r--tests/typ/library/rgb.typ17
6 files changed, 191 insertions, 0 deletions
diff --git a/tests/typ/library/font.typ b/tests/typ/library/font.typ
new file mode 100644
index 00000000..beaddd4e
--- /dev/null
+++ b/tests/typ/library/font.typ
@@ -0,0 +1,56 @@
+// Test configuring font properties.
+
+[font "PT Sans", 10pt]
+
+// Set same font size in three different ways.
+[font 20pt][A]
+[font 200%][A]
+[font 15pt + 50%][A]
+
+// Do nothing.
+[font][Normal]
+
+// Set style (is available).
+[font style: italic][Italic]
+
+// Set weight (is available).
+[font weight: bold][Bold]
+
+// Set stretch (not available, matching closest).
+[font stretch: ultra-condensed][Condensed]
+
+// Error: 1:7-1:12 unexpected argument
+[font false]
+
+// Error: 3:14-3:18 expected font style, found font weight
+// Error: 2:28-2:34 expected font weight, found string
+// Error: 1:43-1:44 expected font family or array of font families, found integer
+[font style: bold, weight: "thin", serif: 0]
+
+// Warning: 1:15-1:19 must be between 100 and 900
+[font weight: 2700]
+
+// Error: 1:7-1:27 unexpected argument
+[font something: "invalid"]
+
+---
+// Test font fallback and class definitions.
+
+// Source Sans Pro + Segoe UI Emoji.
+Emoji: 🏀
+
+// CMU Serif + Noto Emoji.
+[font "CMU Serif", "Noto Emoji"][
+ Emoji: 🏀
+]
+
+// Class definitions.
+[font serif: ("CMU Serif", "Latin Modern Math", "Noto Emoji")]
+[font serif][
+ Math: ∫ α + β ➗ 3
+]
+
+// Class definition reused.
+[font sans-serif: "Noto Emoji"]
+[font sans-serif: ("Archivo", sans-serif)]
+New sans-serif. 🚀
diff --git a/tests/typ/library/hv.typ b/tests/typ/library/hv.typ
new file mode 100644
index 00000000..36a6d242
--- /dev/null
+++ b/tests/typ/library/hv.typ
@@ -0,0 +1,22 @@
+// Ends paragraphs.
+Tightly [v -5pt] packed
+
+// Eating up soft spacing.
+Inv [h 0pt] isible
+
+// Multiple spacings in a row.
+Add [h 10pt] [h 10pt] up
+
+// Relative to font size.
+Relative [h 100%] spacing
+
+// Missing spacing.
+// Error: 1:11-1:11 missing argument: spacing
+Totally [h] ignored
+
+// Swapped axes.
+[page main-dir: rtl, cross-dir: ttb, height: 80pt][
+ 1 [h 1cm] 2
+
+ 3 [v 1cm] 4 [v -1cm] 5
+]
diff --git a/tests/typ/library/image.typ b/tests/typ/library/image.typ
new file mode 100644
index 00000000..2e7b1eb5
--- /dev/null
+++ b/tests/typ/library/image.typ
@@ -0,0 +1,39 @@
+// Test loading different image formats.
+
+// Load an RGBA PNG image.
+[image "res/rhino.png"]
+[pagebreak]
+
+// Load an RGB JPEG image.
+[image "res/tiger.jpg"]
+
+// Error: 1:8-1:29 failed to load image
+[image "path/does/not/exist"]
+
+// Error: 1:8-1:29 failed to load image
+[image "typ/image-error.typ"]
+
+---
+// Test configuring the size and fitting behaviour of images.
+
+// Fit to width of page.
+[image "res/rhino.png"]
+
+// Fit to height of page.
+[page height: 40pt][
+ [image "res/rhino.png"]
+]
+
+// Set width explicitly.
+[image "res/rhino.png", width: 50pt]
+
+// Set height explicitly.
+[image "res/rhino.png", height: 50pt]
+
+// Set width and height explicitly and force stretching.
+[image "res/rhino.png", width: 25pt, height: 50pt]
+
+// Make sure the bounding-box of the image is correct.
+[align bottom, right][
+ [image "res/tiger.jpg", width: 60pt]
+]
diff --git a/tests/typ/library/page.typ b/tests/typ/library/page.typ
new file mode 100644
index 00000000..9eeddc93
--- /dev/null
+++ b/tests/typ/library/page.typ
@@ -0,0 +1,54 @@
+// Test configuring page sizes and margins.
+
+// Set width and height.
+[page width: 120pt, height: 120pt]
+[page width: 40pt][High]
+[page height: 40pt][Wide]
+
+// Set all margins at once.
+[page margins: 30pt][
+ [align top, left][TL]
+ [align 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]
+
+// Ensure that specific margins override general margins.
+[page margins: 0pt, left: 20pt][Overriden]
+
+// Error: 1:7-1:18 unknown variable
+[page nonexistant]
+
+// Error: 1:17-1:20 aligned axis
+[page main-dir: ltr]
+
+// Flipped predefined paper.
+[page "a11", flip: true][Flipped A11]
+
+// Flipped custom page size.
+[page width: 40pt, height: 120pt]
+[page flip: true]
+Wide
+
+// Test changing the layouting directions of pages.
+
+[page height: 50pt, main-dir: btt, cross-dir: rtl]
+Right to left!
+
+---
+// Test a combination of pages with bodies and normal content.
+
+[page height: 50pt]
+
+[page][First]
+[page][Second]
+[pagebreak]
+Fourth
+[page][]
+Sixth
+[page][Seventh and last]
diff --git a/tests/typ/library/pagebreak.typ b/tests/typ/library/pagebreak.typ
new file mode 100644
index 00000000..2f539ce0
--- /dev/null
+++ b/tests/typ/library/pagebreak.typ
@@ -0,0 +1,3 @@
+First of two
+[pagebreak]
+[page height: 40pt]
diff --git a/tests/typ/library/rgb.typ b/tests/typ/library/rgb.typ
new file mode 100644
index 00000000..66d63d0d
--- /dev/null
+++ b/tests/typ/library/rgb.typ
@@ -0,0 +1,17 @@
+// Check the output.
+[rgb 0.0, 0.3, 0.7]
+
+// Alpha channel.
+[rgb 1.0, 0.0, 0.0, 0.5]
+
+// Warning: 2:6-2:9 must be between 0.0 and 1.0
+// Warning: 1:11-1:15 must be between 0.0 and 1.0
+[rgb -30, 15.5, 0.5]
+
+// Error: 1:6-1:10 missing argument: blue component
+[rgb 0, 1]
+
+// Error: 3:5-3:5 missing argument: red component
+// Error: 2:5-2:5 missing argument: green component
+// Error: 1:5-1:5 missing argument: blue component
+[rgb]