summaryrefslogtreecommitdiff
path: root/tests/typ/utility
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-08-31 12:59:53 +0200
committerLaurenz <laurmaedje@gmail.com>2021-08-31 12:59:53 +0200
commit3481d8cc81a2b3a14118869c7f0ffe204ff3efc8 (patch)
tree907efa2e092366a24e25243854b1a4e088cc04a9 /tests/typ/utility
parentee84bf74083f5b9cc88a2a0a968dc905b1eef22c (diff)
More utility functions
- join("a", "b", "c", sep: ", ") - int("12") - float("31.4e-1") - str(10) - sorted((3, 2, 1))
Diffstat (limited to 'tests/typ/utility')
-rw-r--r--tests/typ/utility/basics.typ69
-rw-r--r--tests/typ/utility/collection.typ38
-rw-r--r--tests/typ/utility/strings.typ8
3 files changed, 98 insertions, 17 deletions
diff --git a/tests/typ/utility/basics.typ b/tests/typ/utility/basics.typ
index 203b7eb1..a2f6b220 100644
--- a/tests/typ/utility/basics.typ
+++ b/tests/typ/utility/basics.typ
@@ -2,16 +2,67 @@
// Ref: false
---
-// Test the `len` function.
-#test(len(()), 0)
-#test(len(("A", "B", "C")), 3)
-#test(len("Hello World!"), 12)
-#test(len((a: 1, b: 2)), 2)
+// Test the `type` function.
+#test(type(1), "integer")
+#test(type(ltr), "direction")
---
-// Error: 5-7 missing argument: collection
-#len()
+// Test the `repr` function.
+#test(repr(ltr), "ltr")
+#test(repr((1, 2, false, )), "(1, 2, false)")
---
-// Error: 6-10 expected string, array or dictionary
-#len(12pt)
+// Test the `join` function.
+#test(join(), none)
+#test(join(sep: false), none)
+#test(join(1), 1)
+#test(join("a", "b", "c"), "abc")
+#test("(" + join("a", "b", "c", sep: ", ") + ")", "(a, b, c)")
+
+---
+// Test joining templates.
+// Ref: true
+#join([One], [Two], [Three], sep: [, ]).
+
+---
+// Error: 11-24 cannot join boolean with boolean
+#test(join(true, false))
+
+---
+// Error: 11-29 cannot join string with integer
+#test(join("a", "b", sep: 1))
+
+---
+// Test conversion functions.
+#test(int(false), 0)
+#test(int(true), 1)
+#test(int(10), 10)
+#test(int("150"), 150)
+#test(type(10 / 3), "float")
+#test(int(10 / 3), 3)
+#test(float(10), 10.0)
+#test(float("31.4e-1"), 3.14)
+#test(type(float(10)), "float")
+#test(str(123), "123")
+#test(str(50.14), "50.14")
+#test(len(str(10 / 3)) > 10, true)
+
+---
+// Error: 6-10 cannot convert length to integer
+#int(10pt)
+
+---
+// Error: 8-13 cannot convert function to float
+#float(float)
+
+---
+// Error: 6-8 cannot convert template to string
+#str([])
+
+---
+// Error: 6-12 invalid integer
+#int("nope")
+
+---
+// Error: 8-15 invalid float
+#float("1.2.3")
diff --git a/tests/typ/utility/collection.typ b/tests/typ/utility/collection.typ
new file mode 100644
index 00000000..a97184d3
--- /dev/null
+++ b/tests/typ/utility/collection.typ
@@ -0,0 +1,38 @@
+// Test collection functions.
+// Ref: false
+
+---
+#let memes = "ArE mEmEs gReAt?";
+#test(lower(memes), "are memes great?")
+#test(upper(memes), "ARE MEMES GREAT?")
+#test(upper("Ελλάδα"), "ΕΛΛΆΔΑ")
+
+---
+// Test the `len` function.
+#test(len(()), 0)
+#test(len(("A", "B", "C")), 3)
+#test(len("Hello World!"), 12)
+#test(len((a: 1, b: 2)), 2)
+
+---
+// Error: 5-7 missing argument: collection
+#len()
+
+---
+// Error: 6-10 expected string, array or dictionary
+#len(12pt)
+
+---
+// Test the `sorted` function.
+#test(sorted(()), ())
+#test(sorted((true, false) * 10), (false,) * 10 + (true,) * 10)
+#test(sorted(("it", "the", "hi", "text")), ("hi", "it", "text", "the"))
+#test(sorted((2, 1, 3, 10, 5, 8, 6, -7, 2)), (-7, 1, 2, 2, 3, 5, 6, 8, 10))
+
+---
+// Error: 9-21 cannot compare string with integer
+#sorted((1, 2, "ab"))
+
+---
+// Error: 9-24 cannot compare template with template
+#sorted(([Hi], [There]))
diff --git a/tests/typ/utility/strings.typ b/tests/typ/utility/strings.typ
deleted file mode 100644
index 7c708175..00000000
--- a/tests/typ/utility/strings.typ
+++ /dev/null
@@ -1,8 +0,0 @@
-// Test string functions.
-// Ref: false
-
----
-#let memes = "ArE mEmEs gReAt?";
-#test(lower(memes), "are memes great?")
-#test(upper(memes), "ARE MEMES GREAT?")
-#test(upper("Ελλάδα"), "ΕΛΛΆΔΑ")