summaryrefslogtreecommitdiff
path: root/tests/typ/compute/construct.typ
diff options
context:
space:
mode:
Diffstat (limited to 'tests/typ/compute/construct.typ')
-rw-r--r--tests/typ/compute/construct.typ55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/typ/compute/construct.typ b/tests/typ/compute/construct.typ
new file mode 100644
index 00000000..ccb7bd2e
--- /dev/null
+++ b/tests/typ/compute/construct.typ
@@ -0,0 +1,55 @@
+// Test creation and conversion functions.
+// Ref: false
+
+---
+// Compare both ways.
+#test(rgb(0%, 30%, 70%), rgb("004db3"))
+
+// Alpha channel.
+#test(rgb(255, 0, 0, 50%), rgb("ff000080"))
+
+// Test color modification methods.
+#test(rgb(25, 35, 45).lighten(10%), rgb(48, 57, 66))
+#test(rgb(40, 30, 20).darken(10%), rgb(36, 27, 18))
+#test(rgb("#133337").negate(), rgb(236, 204, 200))
+#test(white.lighten(100%), white)
+
+---
+// Test gray color conversion.
+// Ref: true
+#rect(fill: luma(0))
+#rect(fill: luma(80%))
+
+---
+// Error for values that are out of range.
+// Error: 11-14 must be between 0 and 255
+#test(rgb(-30, 15, 50))
+
+---
+// Error: 6-11 string contains non-hexadecimal letters
+#rgb("lol")
+
+---
+// Error: 5-7 missing argument: red component
+#rgb()
+
+---
+// Error: 5-11 missing argument: blue component
+#rgb(0, 1)
+
+---
+// Error: 21-26 expected integer or ratio, found boolean
+#rgb(10%, 20%, 30%, false)
+
+---
+// Test conversion to string.
+#test(str(123), "123")
+#test(str(50.14), "50.14")
+#test(str(10 / 3).len() > 10, true)
+
+---
+// Error: 6-8 expected integer, float, label, or string, found content
+#str([])
+
+---
+#assert(range(2, 5) == (2, 3, 4))