diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-11-29 13:37:25 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-11-29 14:18:13 +0100 |
| commit | 0efe669278a5e1c3f2985eba2f3360e91159c54a (patch) | |
| tree | 502712857c48f0decb5e698257c0a96d358a436e /tests/typ/basics | |
| parent | 836692e73cff0356e409a9ba5b4887b86809d4ca (diff) | |
Reorganize library and tests
Diffstat (limited to 'tests/typ/basics')
| -rw-r--r-- | tests/typ/basics/desc.typ | 48 | ||||
| -rw-r--r-- | tests/typ/basics/enum.typ | 65 | ||||
| -rw-r--r-- | tests/typ/basics/heading.typ | 52 | ||||
| -rw-r--r-- | tests/typ/basics/list-attach.typ | 54 | ||||
| -rw-r--r-- | tests/typ/basics/list.typ | 53 | ||||
| -rw-r--r-- | tests/typ/basics/table.typ | 22 |
6 files changed, 294 insertions, 0 deletions
diff --git a/tests/typ/basics/desc.typ b/tests/typ/basics/desc.typ new file mode 100644 index 00000000..1bc92625 --- /dev/null +++ b/tests/typ/basics/desc.typ @@ -0,0 +1,48 @@ +// Test description lists. + +--- +/ +No: list \ +/No: list + +--- +// Test with constructor. +#desc( + (term: [One], body: [First]), + (term: [Two], body: [Second]), +) + +--- +// Test joining. +#for word in lorem(4).split().map(s => s.trim(".")) [ + / #word: Latin stuff. +] + +--- +// Test multiline. +#set text(8pt) + +/ Fruit: A tasty, edible thing. +/ Veggie: + An important energy source + for vegetarians. + +--- +// Test style change. +#set text(8pt) +/ First list: #lorem(4) + +#set desc(body-indent: 30pt) +/ Second list: #lorem(4) + +--- +// Test grid like show rule. +#show desc: it => table( + columns: 2, + padding: 3pt, + ..it.items.map(item => (emph(item.term), item.body)).flatten(), +) + +/ A: One letter +/ BB: Two letters +/ CCC: Three letters diff --git a/tests/typ/basics/enum.typ b/tests/typ/basics/enum.typ new file mode 100644 index 00000000..d4c30385 --- /dev/null +++ b/tests/typ/basics/enum.typ @@ -0,0 +1,65 @@ +// Test enumerations. + +--- +#enum[Embrace][Extend][Extinguish] + +--- +1. First. + 2. Indented + ++ Second + +--- +// Test automatic numbering in summed content. +#for i in range(5) { + [+ #numbering(1 + i, "I")] +} + +--- +// Test label pattern. +#set enum(label: "~ A:") +1. First + + Second + +#set enum(label: "(*)") ++ A ++ B ++ C + +#set enum(label: "i)") ++ A ++ B + +--- +// Mix of different lists +- List ++ Enum +/ Desc: List + +--- +// Test label closure. +#enum( + start: 4, + spacing: 0.65em - 3pt, + tight: false, + label: n => text(fill: (red, green, blue)(mod(n, 3)), numbering(n, "A")), + [Red], [Green], [Blue], +) + +--- +#set enum(label: n => n > 1) ++ A ++ B + +--- +// Lone plus is not an enum. ++ +No enum + +--- +// Error: 18-20 invalid numbering pattern +#set enum(label: "") + +--- +// Error: 18-24 invalid numbering pattern +#set enum(label: "(())") diff --git a/tests/typ/basics/heading.typ b/tests/typ/basics/heading.typ new file mode 100644 index 00000000..9fd4e648 --- /dev/null +++ b/tests/typ/basics/heading.typ @@ -0,0 +1,52 @@ +// Test headings. + +--- +#show heading: it => text(blue, it.body) + += +No heading + +--- +// Different number of equals signs. + += Level 1 +== Level 2 +=== Level 3 + +// After three, it stops shrinking. +=========== Level 11 + +--- +// Heading vs. no heading. + +// Parsed as headings if at start of the context. +/**/ = Level 1 +{[== Level 2]} +#box[=== Level 3] + +// Not at the start of the context. +No = heading + +// Escaped. +\= No heading + +--- +// Blocks can continue the heading. + += [This +is +multiline. +] + += This + is not. + +--- +// Test styling. +#show heading.where(level: 5): it => block( + text(family: "Roboto", fill: eastern, it.body + [!]) +) + += Heading +===== Heading 🌍 +#heading(level: 5)[Heading] diff --git a/tests/typ/basics/list-attach.typ b/tests/typ/basics/list-attach.typ new file mode 100644 index 00000000..9d043eb0 --- /dev/null +++ b/tests/typ/basics/list-attach.typ @@ -0,0 +1,54 @@ +// Test list attaching. + +--- +// Test basic attached list. +Attached to: +- the bottom +- of the paragraph + +Next paragraph. + +--- +// Test that attached list isn't affected by block spacing. +#show list: set block(above: 100pt) +Hello +- A +World +- B + +--- +// Test non-attached list followed by attached list, +// separated by only word. +Hello + +- A + +World +- B + +--- +// Test non-attached tight list. +#set block(spacing: 15pt) +Hello +- A +World + +- B +- C + +More. + +--- +// Test that wide lists cannot be ... +#set block(spacing: 15pt) +Hello +- A + +- B +World + +--- +// ... even if forced to. +Hello +#list(tight: false)[A][B] +World diff --git a/tests/typ/basics/list.typ b/tests/typ/basics/list.typ new file mode 100644 index 00000000..9ed5993a --- /dev/null +++ b/tests/typ/basics/list.typ @@ -0,0 +1,53 @@ +// Test unordered lists. + +--- +- +No list + +--- +_Shopping list_ +#list[Apples][Potatoes][Juice] + +--- +- First level. + + - Second level. + There are multiple paragraphs. + + - Third level. + + Still the same bullet point. + + - Still level 2. + +- At the top. + +--- +- Level 1 + - Level [ +2 through content block +] + +--- + - Top-level indent +- is fine. + +--- + - A + - B + - C +- D + +--- +// This works because tabs are used consistently. + - A with 1 tab + - B with 2 tabs + +// This doesn't work because of mixed tabs and spaces. + - A with 2 spaces + - B with 2 tabs + +--- +#set list(label: [-]) +- Bare hyphen +- is not a list diff --git a/tests/typ/basics/table.typ b/tests/typ/basics/table.typ new file mode 100644 index 00000000..527141c5 --- /dev/null +++ b/tests/typ/basics/table.typ @@ -0,0 +1,22 @@ +// Test tables. + +--- +#set page(height: 70pt) +#set table(fill: (x, y) => if even(x + y) { rgb("aaa") }) + +#table( + columns: (1fr,) * 3, + stroke: 2pt + rgb("333"), + [A], [B], [C], [], [], [D \ E \ F \ \ \ G], [H], +) + +--- +#table(columns: 3, stroke: none, fill: green, [A], [B], [C]) + +--- +// Ref: false +#table() + +--- +// Error: 14-19 expected color or none or function, found string +#table(fill: "hey") |
