diff options
Diffstat (limited to 'tests/typ')
| -rw-r--r-- | tests/typ/code/ops-invalid.typ | 4 | ||||
| -rw-r--r-- | tests/typ/code/ops.typ | 2 | ||||
| -rw-r--r-- | tests/typ/code/repr.typ | 7 | ||||
| -rw-r--r-- | tests/typ/utility/basics.typ | 69 | ||||
| -rw-r--r-- | tests/typ/utility/collection.typ | 38 | ||||
| -rw-r--r-- | tests/typ/utility/strings.typ | 8 |
6 files changed, 103 insertions, 25 deletions
diff --git a/tests/typ/code/ops-invalid.typ b/tests/typ/code/ops-invalid.typ index 5d371e91..1355181a 100644 --- a/tests/typ/code/ops-invalid.typ +++ b/tests/typ/code/ops-invalid.typ @@ -26,8 +26,8 @@ {not ()} --- -// Error: 2-12 cannot apply '<=' to relative and relative -{30% <= 40%} +// Error: 2-18 cannot apply '<=' to linear and relative +{30% + 1pt <= 40%} --- // Special messages for +, -, * and /. diff --git a/tests/typ/code/ops.typ b/tests/typ/code/ops.typ index 201f86da..149837b2 100644 --- a/tests/typ/code/ops.typ +++ b/tests/typ/code/ops.typ @@ -146,6 +146,8 @@ #test(5 <= 5, true) #test(5 <= 4, false) #test(45deg < 1rad, true) +#test(10% < 20%, true) +#test(50% < 40% + 0pt, false) --- // Test assignment operators. diff --git a/tests/typ/code/repr.typ b/tests/typ/code/repr.typ index 35a47e49..22890ff1 100644 --- a/tests/typ/code/repr.typ +++ b/tests/typ/code/repr.typ @@ -51,10 +51,5 @@ {() => none} --- -// Test using the `repr` function. - -// Returns a string. -#test(repr((1, 2, false, )), "(1, 2, false)") - -// Not in monospace +// When using the `repr` function it's not in monospace. #repr(23deg) 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("Ελλάδα"), "ΕΛΛΆΔΑ") |
