mirror of
https://github.com/typst/typst
synced 2025-05-16 01:55:28 +08:00
- join("a", "b", "c", sep: ", ") - int("12") - float("31.4e-1") - str(10) - sorted((3, 2, 1))
69 lines
1.3 KiB
XML
69 lines
1.3 KiB
XML
// Test basic functions.
|
|
// Ref: false
|
|
|
|
---
|
|
// Test the `type` function.
|
|
#test(type(1), "integer")
|
|
#test(type(ltr), "direction")
|
|
|
|
---
|
|
// Test the `repr` function.
|
|
#test(repr(ltr), "ltr")
|
|
#test(repr((1, 2, false, )), "(1, 2, false)")
|
|
|
|
---
|
|
// 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")
|