summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-05-03 16:59:13 +0200
committerLaurenz <laurmaedje@gmail.com>2022-05-04 00:14:31 +0200
commit507c5fc92563560426db0d86c0348880b0493467 (patch)
tree45116b62fb0fffe8e88d6c96ae1fcf11c73f8ee9 /tests
parente18a896a93cae987aa30addd40e678bf0064fd31 (diff)
Text replacement show rules
Diffstat (limited to 'tests')
-rw-r--r--tests/ref/graphics/shape-rect.pngbin13791 -> 16331 bytes
-rw-r--r--tests/ref/style/show-text.pngbin0 -> 39399 bytes
-rw-r--r--tests/typ/graphics/shape-rect.typ12
-rw-r--r--tests/typ/style/show-node.typ4
-rw-r--r--tests/typ/style/show-recursive.typ2
-rw-r--r--tests/typ/style/show-text.typ58
-rw-r--r--tests/typ/utility/regex.typ10
7 files changed, 79 insertions, 7 deletions
diff --git a/tests/ref/graphics/shape-rect.png b/tests/ref/graphics/shape-rect.png
index 5bbaf3db..5ba78f97 100644
--- a/tests/ref/graphics/shape-rect.png
+++ b/tests/ref/graphics/shape-rect.png
Binary files differ
diff --git a/tests/ref/style/show-text.png b/tests/ref/style/show-text.png
new file mode 100644
index 00000000..53c9d132
--- /dev/null
+++ b/tests/ref/style/show-text.png
Binary files differ
diff --git a/tests/typ/graphics/shape-rect.typ b/tests/typ/graphics/shape-rect.typ
index a29550b5..5495da8c 100644
--- a/tests/typ/graphics/shape-rect.typ
+++ b/tests/typ/graphics/shape-rect.typ
@@ -41,16 +41,16 @@
---
// Outset padding.
+#set raw(lang: "rust")
#show node: raw as [
- #set text("IBM Plex Mono", 8pt)
- #h(.7em, weak: true)
- #rect(radius: 3pt, outset: (y: 3pt, x: 2.5pt), fill: rgb(239, 241, 243))[{node.text}]
- #h(.7em, weak: true)
+ #set text(8pt)
+ #h(5.6pt, weak: true)
+ #rect(radius: 3pt, outset: (y: 3pt, x: 2.5pt), fill: rgb(239, 241, 243), node)
+ #h(5.6pt, weak: true)
]
-Use the `*const ptr` pointer.
+Use the `*const T` pointer or the `&mut T` reference.
---
// Error: 15-38 unexpected key "cake"
#rect(radius: (left: 10pt, cake: 5pt))
-
diff --git a/tests/typ/style/show-node.typ b/tests/typ/style/show-node.typ
index 4fcee9aa..07c30f19 100644
--- a/tests/typ/style/show-node.typ
+++ b/tests/typ/style/show-node.typ
@@ -63,5 +63,9 @@ Another text.
#show _: upper as {}
---
+// Error: 7-10 expected function, string or regular expression, found color
+#show red as []
+
+---
// Error: 2-16 set, show and wrap are only allowed directly in markup
{show list as a}
diff --git a/tests/typ/style/show-recursive.typ b/tests/typ/style/show-recursive.typ
index 423bbd80..9e93739c 100644
--- a/tests/typ/style/show-recursive.typ
+++ b/tests/typ/style/show-recursive.typ
@@ -43,7 +43,7 @@
---
// Test multi-recursion with nested lists.
-#set rect(padding: 2pt)
+#set rect(inset: 2pt)
#show v: list as rect(stroke: blue, v)
#show v: list as rect(stroke: red, v)
diff --git a/tests/typ/style/show-text.typ b/tests/typ/style/show-text.typ
new file mode 100644
index 00000000..3bc116f5
--- /dev/null
+++ b/tests/typ/style/show-text.typ
@@ -0,0 +1,58 @@
+// Test text replacement show rules.
+
+---
+// Test classic example.
+#set text("Roboto")
+#show phrase: "Der Spiegel" as text(smallcaps: true, [#phrase])
+Die Zeitung Der Spiegel existiert.
+
+---
+// Another classic example.
+#show "TeX" as [T#h(-0.145em)#move(dy: 0.233em)[E]#h(-0.135em)X]
+#show name: regex("(Lua)?(La)?TeX") as box(text("Latin Modern Roman")[#name])
+
+TeX, LaTeX, LuaTeX and LuaLaTeX!
+
+---
+// Test out-of-order guarding.
+#show "Good" as [Typst!]
+#show "Typst" as [Fun!]
+#show "Fun" as [Good!]
+#show enum as []
+
+Good \
+Fun \
+Typst \
+
+---
+// Test that replacements happen exactly once.
+#show "A" as [BB]
+#show "B" as [CC]
+AA (8)
+
+---
+// Test caseless match and word boundaries.
+#show regex("(?i)\bworld\b") as [🌍]
+
+Treeworld, the World of worlds, is a world.
+
+---
+// This is a fun one.
+#set par(justify: true)
+#show letter: regex("\S") as rect(inset: 2pt)[#upper(letter)]
+#lorem(5)
+
+---
+// See also: https://github.com/mTvare6/hello-world.rs
+#show it: regex("(?i)rust") as [#it (🚀)]
+Rust is memory-safe and blazingly fast. Let's rewrite everything in rust.
+
+---
+// Replace worlds but only in lists.
+#show node: list as [
+ #show "World" as [🌎]
+ #node
+]
+
+World
+- World
diff --git a/tests/typ/utility/regex.typ b/tests/typ/utility/regex.typ
new file mode 100644
index 00000000..4cc7d1ea
--- /dev/null
+++ b/tests/typ/utility/regex.typ
@@ -0,0 +1,10 @@
+// Test regexes.
+// Ref: false
+
+---
+{
+ let re = regex("(La)?TeX")
+ test(re.matches("La"), false)
+ test(re.matches("TeX"), true)
+ test(re.matches("LaTeX"), true)
+}