test(glossy): switch to typst-test, add tests

- move examples/readme.typ into a test (demo)
- add test for sorting (both ways)
- add test to generate theme gallery
- add theme gallery image to README
This commit is contained in:
swaits committed 2024-12-05 01:08:43 +01:00
1 parent f2052745e0
commit 12db300709
11 files changed
+99 -47

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 606 KiB

+99
View File
@@ -0,0 +1,99 @@
// a minimal example, also listed in the README
#import "/lib.typ": *
#let myGlossary = (
html: (
short: "HTML",
long: "Hypertext Markup Language",
description: "A standard language for creating web pages",
group: "Web"),
css: (
short: "CSS",
long: "Cascading Style Sheets",
description: "A language used for describing the presentation of a document",
group: "Web"),
tps: (
short: "TPS",
long: "test procedure specification",
description: "A document on how to run all the test procedures"),
)
#show: init-glossary.with(myGlossary, show-term: (body) => [#emph(body)])
#set heading(numbering: "1.1")
= Hello, `glossy`!
In modern web development, languages like @html and @css are essential.
Now make sure I get your @tps:short reports by 2pm!
@tps:cap is defined as: @tps:def.
= Examples with modifiers
#table(
columns: 2,
table.header([*Input*], [*Output*]),
[`@tps:short` ], [@tps:short],
[`@tps:long` ], [@tps:long],
[`@tps:both` ], [@tps:both],
[`@tps:long:cap` ], [@tps:long:cap],
[`@tps:long:pl` ], [@tps:long:pl],
[`@tps:short:pl` ], [@tps:short:pl],
[`@tps:both:pl:cap`], [@tps:both:pl:cap],
[`@tps:def` ], [@tps:def],
[`@tps:desc` ], [@tps:desc],
)
== Using conflicting modifiers (short, long, both)
These modifiers are semantically mutually exclusive, by they can be combined
syntactically. When multiple are used, `glossy` tries to make a smart choice on
which one to display.
#table(
columns: 2,
table.header([*Input*], [*Output*]),
[`@tps:short:long` ], [@tps:short:long],
[`@tps:short:both` ], [@tps:short:both],
[`@tps:long:both` ], [@tps:long:both],
[`@tps:short:long:both`], [@tps:short:long:both],
)
#let my-theme = (
section: (title, body) => {
heading(level: 1, title)
body
},
group: (name, i, n, body) => {
if name != "" and n > 1 {
heading(level: 2, name)
}
body
},
entry: (entry, i, n) => {
// i is the entry's index, n is total number of entries
let output = [#entry.short]
if entry.long != none {
output = [#output -- #entry.long]
}
if entry.description != none {
output = [#output: #entry.description]
}
block(
grid(
columns: (auto, 1fr, auto),
output,
repeat([#h(0.25em) . #h(0.25em)]),
entry.pages,
)
)
}
)
#glossary(theme: my-theme)
#glossary(title: "Glossary with just empty group", groups: ("",), theme: theme-basic)
#glossary(title: "Glossary with just Web group", groups: ("Web",), theme: theme-compact)
Binary file not shown.

After

Width:  |  Height:  |  Size: 259 KiB

@@ -0,0 +1,38 @@
#import "/lib.typ": *
#let myGlossary = (
html: (
short: "HTML",
long: "Hypertext Markup Language",
description: "A standard language for creating web pages",
),
iphone: (
short: "iPhone",
long: "iPhone",
),
css: (
short: "CSS",
long: "Cascading Style Sheets",
description: "A language used for describing the presentation of a document",
),
atom: (
short: "atom",
long: "atom",
),
tps: (
short: "TPS",
long: "test procedure specification",
description: "A document on how to run all the test procedures"
),
)
#show: init-glossary.with(myGlossary, show-term: (body) => [#emph(body)])
= Refer to our terms so they show up in the glossary
@html, @iphone:long, @css, @css:cap:pl, @atom:pl, @tps:long
= Default sorting
#glossary(theme: theme-compact)
= Case-insensitive sorting (`ignore-case: true`)
#glossary(ignore-case: true, theme: theme-compact)
Binary file not shown.

After

Width:  |  Height:  |  Size: 339 KiB

@@ -0,0 +1,54 @@
#import "/lib.typ": *
#let myGlossary = (
html: (
short: "HTML",
long: "Hypertext Markup Language",
description: "A standard language for creating web pages",
),
css: (
short: "CSS",
long: "Cascading Style Sheets",
description: "A language used for describing the presentation of a document",
),
tps: (
short: "TPS",
long: "test procedure specification",
description: "A document on how to run all the test procedures"
),
)
#show: init-glossary.with(myGlossary, show-term: (body) => [#emph(body)])
#text(size: 18pt, weight: "bold")[Theme Gallery]
First, we refer to each term at least once so they'll actually show up in the
glossaries. Our terms include: @html:cap, @css, and @tps.
// TODO: ask Discord if there's a way to get a symbol (ie function) name as a
// TODO: figure out if there's a way to get a symbol (ie function) name as a
// string or content
#let themes = (
("theme-basic", theme-basic),
("theme-compact", theme-compact),
)
#for theme in themes {
block(
breakable: false,
spacing: 2em,
inset: 1em,
stroke: 1pt+gray,
glossary(title: raw(theme.first()), theme: theme.last())
)
}
// HACK: special case theme-twocol so we can restrict the height
#block(
breakable: false,
spacing: 2em,
inset: 1em,
stroke: 1pt+gray,
height: 1.5in,
glossary(title: raw("theme-twocol"), theme: theme-twocol)
)