diff options
Diffstat (limited to 'tests/typ/compute')
| -rw-r--r-- | tests/typ/compute/calc.typ | 355 | ||||
| -rw-r--r-- | tests/typ/compute/construct.typ | 316 | ||||
| -rw-r--r-- | tests/typ/compute/data.typ | 144 | ||||
| -rw-r--r-- | tests/typ/compute/eval-path.typ | 18 | ||||
| -rw-r--r-- | tests/typ/compute/foundations.typ | 107 | ||||
| -rw-r--r-- | tests/typ/compute/version.typ | 47 |
6 files changed, 0 insertions, 987 deletions
diff --git a/tests/typ/compute/calc.typ b/tests/typ/compute/calc.typ deleted file mode 100644 index 94a13105..00000000 --- a/tests/typ/compute/calc.typ +++ /dev/null @@ -1,355 +0,0 @@ -// Test math functions. -// Ref: false - ---- -// Test conversion to numbers. -#test(int(false), 0) -#test(int(true), 1) -#test(int(10), 10) -#test(int("150"), 150) -#test(int("-834"), -834) -#test(int("\u{2212}79"), -79) -#test(int(10 / 3), 3) -#test(float(10), 10.0) -#test(float(50% * 30%), 0.15) -#test(float("31.4e-1"), 3.14) -#test(float("31.4e\u{2212}1"), 3.14) -#test(float("3.1415"), 3.1415) -#test(float("-7654.321"), -7654.321) -#test(float("\u{2212}7654.321"), -7654.321) -#test(type(float(10)), float) - ---- -// Test float `is-nan()`. -#test(float(calc.nan).is-nan(), true) -#test(float(10).is-nan(), false) - ---- -// Test float `is-infinite()`. -#test(float(calc.inf).is-infinite(), true) -#test(float(-calc.inf).is-infinite(), true) -#test(float(10).is-infinite(), false) -#test(float(-10).is-infinite(), false) - ---- -// Test float `signum()` -#test(float(0.0).signum(), 1.0) -#test(float(1.0).signum(), 1.0) -#test(float(-1.0).signum(), -1.0) -#test(float(10.0).signum(), 1.0) -#test(float(-10.0).signum(), -1.0) -#test(float(calc.nan).signum().is-nan(), true) - ---- -// Test int `signum()` -#test(int(0).signum(), 0) -#test(int(1.0).signum(), 1) -#test(int(-1.0).signum(), -1) -#test(int(10.0).signum(), 1) -#test(int(-10.0).signum(), -1) - ---- -#test(calc.round(calc.e, digits: 2), 2.72) -#test(calc.round(calc.pi, digits: 2), 3.14) - ---- -// Error: 6-10 expected integer, boolean, float, or string, found length -#int(10pt) - ---- -// Error: 8-13 expected float, boolean, integer, ratio, or string, found type -#float(float) - ---- -// Error: 6-12 invalid integer: nope -#int("nope") - ---- -// Error: 8-15 invalid float: 1.2.3 -#float("1.2.3") - ---- -// Test the `abs` function. -#test(calc.abs(-3), 3) -#test(calc.abs(3), 3) -#test(calc.abs(-0.0), 0.0) -#test(calc.abs(0.0), -0.0) -#test(calc.abs(-3.14), 3.14) -#test(calc.abs(50%), 50%) -#test(calc.abs(-25%), 25%) - ---- -// Error: 11-22 expected integer, float, length, angle, ratio, or fraction, found string -#calc.abs("no number") - ---- -// Test the `even` and `odd` functions. -#test(calc.even(2), true) -#test(calc.odd(2), false) -#test(calc.odd(-1), true) -#test(calc.even(-11), false) - ---- -// Test the `rem` function. -#test(calc.rem(1, 1), 0) -#test(calc.rem(5, 3), 2) -#test(calc.rem(5, -3), 2) -#test(calc.rem(22.5, 10), 2.5) -#test(calc.rem(9, 4.5), 0) - ---- -// Error: 14-15 divisor must not be zero -#calc.rem(5, 0) - ---- -// Error: 16-19 divisor must not be zero -#calc.rem(3.0, 0.0) - ---- -// Test the `div-euclid` function. -#test(calc.div-euclid(7, 3), 2) -#test(calc.div-euclid(7, -3), -2) -#test(calc.div-euclid(-7, 3), -3) -#test(calc.div-euclid(-7, -3), 3) -#test(calc.div-euclid(2.5, 2), 1) - ---- -// Error: 21-22 divisor must not be zero -#calc.div-euclid(5, 0) - ---- -// Error: 23-26 divisor must not be zero -#calc.div-euclid(3.0, 0.0) - ---- -// Test the `rem-euclid` function. -#test(calc.rem-euclid(7, 3), 1) -#test(calc.rem-euclid(7, -3), 1) -#test(calc.rem-euclid(-7, 3), 2) -#test(calc.rem-euclid(-7, -3), 2) -#test(calc.rem-euclid(2.5, 2), 0.5) - ---- -// Error: 21-22 divisor must not be zero -#calc.rem-euclid(5, 0) - ---- -// Error: 23-26 divisor must not be zero -#calc.rem-euclid(3.0, 0.0) - ---- -// Test the `quo` function. -#test(calc.quo(1, 1), 1) -#test(calc.quo(5, 3), 1) -#test(calc.quo(5, -3), -1) -#test(calc.quo(22.5, 10), 2) -#test(calc.quo(9, 4.5), 2) - ---- -// Error: 14-15 divisor must not be zero -#calc.quo(5, 0) - ---- -// Error: 16-19 divisor must not be zero -#calc.quo(3.0, 0.0) - ---- -// Test the `min` and `max` functions. -#test(calc.min(2, -4), -4) -#test(calc.min(3.5, 1e2, -0.1, 3), -0.1) -#test(calc.max(-3, 11), 11) -#test(calc.min("hi"), "hi") - ---- -// Test the `pow`, `log`, `exp`, and `ln` functions. -#test(calc.pow(10, 0), 1) -#test(calc.pow(2, 4), 16) -#test(calc.exp(2), calc.pow(calc.e, 2)) -#test(calc.ln(10), calc.log(10, base: calc.e)) - ---- -// Test the `bit-not`, `bit-and`, `bit-or` and `bit-xor` functions. -#test(64.bit-not(), -65) -#test(0.bit-not(), -1) -#test((-56).bit-not(), 55) -#test(128.bit-and(192), 128) -#test(192.bit-and(224), 192) -#test((-1).bit-and(325532), 325532) -#test(0.bit-and(-53), 0) -#test(0.bit-or(-1), -1) -#test(5.bit-or(3), 7) -#test((-50).bit-or(3), -49) -#test(64.bit-or(32), 96) -#test((-1).bit-xor(1), -2) -#test(64.bit-xor(96), 32) -#test((-1).bit-xor(-7), 6) -#test(0.bit-xor(492), 492) - ---- -// Test the `bit-lshift` and `bit-rshift` functions. -#test(32.bit-lshift(2), 128) -#test(694.bit-lshift(0), 694) -#test(128.bit-rshift(2), 32) -#test(128.bit-rshift(12345), 0) -#test((-7).bit-rshift(2), -2) -#test((-7).bit-rshift(12345), -1) -#test(128.bit-rshift(2, logical: true), 32) -#test((-7).bit-rshift(61, logical: true), 7) -#test(128.bit-rshift(12345, logical: true), 0) -#test((-7).bit-rshift(12345, logical: true), 0) - ---- -// Error: 2-18 the result is too large -#1.bit-lshift(64) - ---- -// Error: 15-17 number must be at least zero -#1.bit-lshift(-1) - ---- -// Error: 15-17 number must be at least zero -#1.bit-rshift(-1) - ---- -// Error: 2-16 zero to the power of zero is undefined -#calc.pow(0, 0) - ---- -// Error: 14-31 exponent is too large -#calc.pow(2, 10000000000000000) - ---- -// Error: 2-25 the result is too large -#calc.pow(2, 2147483647) - ---- -// Error: 14-36 exponent may not be infinite, subnormal, or NaN -#calc.pow(2, calc.pow(2.0, 10000.0)) - ---- -// Error: 2-19 the result is not a real number -#calc.pow(-1, 0.5) - ---- -// Error: 12-14 cannot take square root of negative number -#calc.sqrt(-1) - ---- -#test(calc.root(12.0, 1), 12.0) -#test(calc.root(9.0, 2), 3.0) -#test(calc.root(27.0, 3), 3.0) -#test(calc.root(-27.0, 3), -3.0) -// 100^(-1/2) = (100^(1/2))^-1 = 1/sqrt(100) -#test(calc.root(100.0, -2), 0.1) - ---- -// Error: 17-18 cannot take the 0th root of a number -#calc.root(1.0, 0) - ---- -// Error: 24-25 negative numbers do not have a real nth root when n is even -#test(calc.root(-27.0, 4), -3.0) - ---- -// Error: 11-13 value must be strictly positive -#calc.log(-1) - ---- -// Error: 20-21 base may not be zero, NaN, infinite, or subnormal -#calc.log(1, base: 0) - ---- -// Error: 2-24 the result is not a real number -#calc.log(10, base: -1) - ---- -// Test the `fact` function. -#test(calc.fact(0), 1) -#test(calc.fact(5), 120) - ---- -// Error: 2-15 the result is too large -#calc.fact(21) - ---- -// Test the `perm` function. -#test(calc.perm(0, 0), 1) -#test(calc.perm(5, 3), 60) -#test(calc.perm(5, 5), 120) -#test(calc.perm(5, 6), 0) - ---- -// Error: 2-19 the result is too large -#calc.perm(21, 21) - ---- -// Test the `binom` function. -#test(calc.binom(0, 0), 1) -#test(calc.binom(5, 3), 10) -#test(calc.binom(5, 5), 1) -#test(calc.binom(5, 6), 0) -#test(calc.binom(6, 2), 15) - ---- -// Test the `gcd` function. -#test(calc.gcd(112, 77), 7) -#test(calc.gcd(12, 96), 12) -#test(calc.gcd(13, 9), 1) -#test(calc.gcd(13, -9), 1) -#test(calc.gcd(272557, 272557), 272557) -#test(calc.gcd(0, 0), 0) -#test(calc.gcd(7, 0), 7) - ---- -// Test the `lcm` function. -#test(calc.lcm(112, 77), 1232) -#test(calc.lcm(12, 96), 96) -#test(calc.lcm(13, 9), 117) -#test(calc.lcm(13, -9), 117) -#test(calc.lcm(272557, 272557), 272557) -#test(calc.lcm(0, 0), 0) -#test(calc.lcm(8, 0), 0) - ---- -// Error: 2-41 the result is too large -#calc.lcm(15486487489457, 4874879896543) - ---- -// Error: 2-12 expected at least one value -#calc.min() - ---- -// Error: 14-18 cannot compare string and integer -#calc.min(1, "hi") - ---- -// Error: 16-19 cannot compare 1pt with 1em -#calc.max(1em, 1pt) - ---- -// Test the `range` function. -#test(range(4), (0, 1, 2, 3)) -#test(range(1, 4), (1, 2, 3)) -#test(range(-4, 2), (-4, -3, -2, -1, 0, 1)) -#test(range(10, 5), ()) -#test(range(10, step: 3), (0, 3, 6, 9)) -#test(range(1, 4, step: 1), (1, 2, 3)) -#test(range(1, 8, step: 2), (1, 3, 5, 7)) -#test(range(5, 2, step: -1), (5, 4, 3)) -#test(range(10, 0, step: -3), (10, 7, 4, 1)) - ---- -// Error: 2-9 missing argument: end -#range() - ---- -// Error: 11-14 expected integer, found float -#range(1, 2.0) - ---- -// Error: 17-22 expected integer, found string -#range(4, step: "one") - ---- -// Error: 18-19 number must not be zero -#range(10, step: 0) diff --git a/tests/typ/compute/construct.typ b/tests/typ/compute/construct.typ deleted file mode 100644 index e429efc5..00000000 --- a/tests/typ/compute/construct.typ +++ /dev/null @@ -1,316 +0,0 @@ -// Test creation and conversion functions. -// Ref: false - ---- -// Compare both ways. -#test-repr(rgb(0%, 30.2%, 70.2%), 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(space: rgb), rgb(236, 204, 200)) -#test(white.lighten(100%), white) - -// Color mixing, in Oklab space by default. -#test(rgb(color.mix(rgb("#ff0000"), rgb("#00ff00"))), rgb("#d0a800")) -#test(rgb(color.mix(rgb("#ff0000"), rgb("#00ff00"), space: oklab)), rgb("#d0a800")) -#test(rgb(color.mix(rgb("#ff0000"), rgb("#00ff00"), space: rgb)), rgb("#808000")) - -#test(rgb(color.mix(red, green, blue)), rgb("#909282")) -#test(rgb(color.mix(red, blue, green)), rgb("#909282")) -#test(rgb(color.mix(blue, red, green)), rgb("#909282")) - -// Mix with weights. -#test(rgb(color.mix((red, 50%), (green, 50%))), rgb("#c0983b")) -#test(rgb(color.mix((red, 0.5), (green, 0.5))), rgb("#c0983b")) -#test(rgb(color.mix((red, 5), (green, 5))), rgb("#c0983b")) -#test(rgb(color.mix((green, 5), (white, 0), (red, 5))), rgb("#c0983b")) -#test(color.mix((rgb("#aaff00"), 25%), (rgb("#aa00ff"), 75%), space: rgb), rgb("#aa40bf")) -#test(color.mix((rgb("#aaff00"), 50%), (rgb("#aa00ff"), 50%), space: rgb), rgb("#aa8080")) -#test(color.mix((rgb("#aaff00"), 75%), (rgb("#aa00ff"), 25%), space: rgb), rgb("#aabf40")) - -// Mix in hue-based space. -#test(rgb(color.mix(red, blue, space: color.hsl)), rgb("#c408ff")) -#test(rgb(color.mix((red, 50%), (blue, 100%), space: color.hsl)), rgb("#5100f8")) -// Error: 6-51 cannot mix more than two colors in a hue-based space -#rgb(color.mix(red, blue, white, space: color.hsl)) - ---- -// Test color conversion method kinds -#test(rgb(rgb(10, 20, 30)).space(), rgb) -#test(color.linear-rgb(rgb(10, 20, 30)).space(), color.linear-rgb) -#test(oklab(rgb(10, 20, 30)).space(), oklab) -#test(oklch(rgb(10, 20, 30)).space(), oklch) -#test(color.hsl(rgb(10, 20, 30)).space(), color.hsl) -#test(color.hsv(rgb(10, 20, 30)).space(), color.hsv) -#test(cmyk(rgb(10, 20, 30)).space(), cmyk) -#test(luma(rgb(10, 20, 30)).space(), luma) - -#test(rgb(color.linear-rgb(10, 20, 30)).space(), rgb) -#test(color.linear-rgb(color.linear-rgb(10, 20, 30)).space(), color.linear-rgb) -#test(oklab(color.linear-rgb(10, 20, 30)).space(), oklab) -#test(oklch(color.linear-rgb(10, 20, 30)).space(), oklch) -#test(color.hsl(color.linear-rgb(10, 20, 30)).space(), color.hsl) -#test(color.hsv(color.linear-rgb(10, 20, 30)).space(), color.hsv) -#test(cmyk(color.linear-rgb(10, 20, 30)).space(), cmyk) -#test(luma(color.linear-rgb(10, 20, 30)).space(), luma) - -#test(rgb(oklab(10%, 20%, 30%)).space(), rgb) -#test(color.linear-rgb(oklab(10%, 20%, 30%)).space(), color.linear-rgb) -#test(oklab(oklab(10%, 20%, 30%)).space(), oklab) -#test(oklch(oklab(10%, 20%, 30%)).space(), oklch) -#test(color.hsl(oklab(10%, 20%, 30%)).space(), color.hsl) -#test(color.hsv(oklab(10%, 20%, 30%)).space(), color.hsv) -#test(cmyk(oklab(10%, 20%, 30%)).space(), cmyk) -#test(luma(oklab(10%, 20%, 30%)).space(), luma) - -#test(rgb(oklch(60%, 40%, 0deg)).space(), rgb) -#test(color.linear-rgb(oklch(60%, 40%, 0deg)).space(), color.linear-rgb) -#test(oklab(oklch(60%, 40%, 0deg)).space(), oklab) -#test(oklch(oklch(60%, 40%, 0deg)).space(), oklch) -#test(color.hsl(oklch(60%, 40%, 0deg)).space(), color.hsl) -#test(color.hsv(oklch(60%, 40%, 0deg)).space(), color.hsv) -#test(cmyk(oklch(60%, 40%, 0deg)).space(), cmyk) -#test(luma(oklch(60%, 40%, 0deg)).space(), luma) - -#test(rgb(color.hsl(10deg, 20%, 30%)).space(), rgb) -#test(color.linear-rgb(color.hsl(10deg, 20%, 30%)).space(), color.linear-rgb) -#test(oklab(color.hsl(10deg, 20%, 30%)).space(), oklab) -#test(oklch(color.hsl(10deg, 20%, 30%)).space(), oklch) -#test(color.hsl(color.hsl(10deg, 20%, 30%)).space(), color.hsl) -#test(color.hsv(color.hsl(10deg, 20%, 30%)).space(), color.hsv) -#test(cmyk(color.hsl(10deg, 20%, 30%)).space(), cmyk) -#test(luma(color.hsl(10deg, 20%, 30%)).space(), luma) - -#test(rgb(color.hsv(10deg, 20%, 30%)).space(), rgb) -#test(color.linear-rgb(color.hsv(10deg, 20%, 30%)).space(), color.linear-rgb) -#test(oklab(color.hsv(10deg, 20%, 30%)).space(), oklab) -#test(oklch(color.hsv(10deg, 20%, 30%)).space(), oklch) -#test(color.hsl(color.hsv(10deg, 20%, 30%)).space(), color.hsl) -#test(color.hsv(color.hsv(10deg, 20%, 30%)).space(), color.hsv) -#test(cmyk(color.hsv(10deg, 20%, 30%)).space(), cmyk) -#test(luma(color.hsv(10deg, 20%, 30%)).space(), luma) - -#test(rgb(cmyk(10%, 20%, 30%, 40%)).space(), rgb) -#test(color.linear-rgb(cmyk(10%, 20%, 30%, 40%)).space(), color.linear-rgb) -#test(oklab(cmyk(10%, 20%, 30%, 40%)).space(), oklab) -#test(oklch(cmyk(10%, 20%, 30%, 40%)).space(), oklch) -#test(color.hsl(cmyk(10%, 20%, 30%, 40%)).space(), color.hsl) -#test(color.hsv(cmyk(10%, 20%, 30%, 40%)).space(), color.hsv) -#test(cmyk(cmyk(10%, 20%, 30%, 40%)).space(), cmyk) -#test(luma(cmyk(10%, 20%, 30%, 40%)).space(), luma) - -#test(rgb(luma(10%)).space(), rgb) -#test(color.linear-rgb(luma(10%)).space(), color.linear-rgb) -#test(oklab(luma(10%)).space(), oklab) -#test(oklch(luma(10%)).space(), oklch) -#test(color.hsl(luma(10%)).space(), color.hsl) -#test(color.hsv(luma(10%)).space(), color.hsv) -#test(cmyk(luma(10%)).space(), cmyk) -#test(luma(luma(10%)).space(), luma) - ---- -// Test gray color conversion. -// Ref: true -#stack(dir: ltr, rect(fill: luma(0)), rect(fill: luma(80%))) - ---- -// Error for values that are out of range. -// Error: 11-14 number must be between 0 and 255 -#test(rgb(-30, 15, 50)) - ---- -// Error: 6-11 color string contains non-hexadecimal letters -#rgb("lol") - ---- -// Error: 2-7 missing argument: red component -#rgb() - ---- -// Error: 2-11 missing argument: blue component -#rgb(0, 1) - ---- -// Error: 21-26 expected integer or ratio, found boolean -#rgb(10%, 20%, 30%, false) - ---- -// Error: 10-20 unexpected argument: key -#luma(1, key: "val") - ---- -// Error: 12-24 expected float or ratio, found string -// Error: 26-39 expected float or ratio, found string -#color.mix((red, "yes"), (green, "no"), (green, 10%)) - ---- -// Error: 12-23 expected a color or color-weight pair -#color.mix((red, 1, 2)) - ---- -// Error: 31-38 expected `rgb`, `luma`, `cmyk`, `oklab`, `oklch`, `color.linear-rgb`, `color.hsl`, or `color.hsv`, found string -#color.mix(red, green, space: "cyber") - ---- -// Error: 31-36 expected `rgb`, `luma`, `cmyk`, `oklab`, `oklch`, `color.linear-rgb`, `color.hsl`, or `color.hsv` -#color.mix(red, green, space: image) - ---- -// Error: 31-41 expected `rgb`, `luma`, `cmyk`, `oklab`, `oklch`, `color.linear-rgb`, `color.hsl`, or `color.hsv` -#color.mix(red, green, space: calc.round) - ---- -// Ref: true -#let envelope = symbol( - "🖂", - ("stamped", "🖃"), - ("stamped.pen", "🖆"), - ("lightning", "🖄"), - ("fly", "🖅"), -) - -#envelope -#envelope.stamped -#envelope.pen -#envelope.stamped.pen -#envelope.lightning -#envelope.fly - ---- -// Error: 2-10 expected at least one variant -#symbol() - ---- -// Test conversion to string. -#test(str(123), "123") -#test(str(123, base: 3), "11120") -#test(str(-123, base: 16), "−7b") -#test(str(9223372036854775807, base: 36), "1y2p0ij32e8e7") -#test(str(50.14), "50.14") -#test(str(10 / 3).len() > 10, true) - ---- -// Error: 6-8 expected integer, float, version, bytes, label, type, or string, found content -#str([]) - ---- -// Error: 17-19 base must be between 2 and 36 -#str(123, base: 99) - ---- -// Error: 18-19 base is only supported for integers -#str(1.23, base: 2) - ---- -// Test the unicode function. -#test(str.from-unicode(97), "a") -#test(str.to-unicode("a"), 97) - ---- -// Error: 19-22 expected integer, found content -#str.from-unicode([a]) - ---- -// Error: 17-21 expected exactly one character -#str.to-unicode("ab") - ---- -// Error: 19-21 number must be at least zero -#str.from-unicode(-1) - ---- -// Error: 2-28 0x110000 is not a valid codepoint -#str.from-unicode(0x110000) // 0x10ffff is the highest valid code point - ---- -#assert(range(2, 5) == (2, 3, 4)) - ---- -// Test displaying of dates. -#test(datetime(year: 2023, month: 4, day: 29).display(), "2023-04-29") -#test(datetime(year: 2023, month: 4, day: 29).display("[year]"), "2023") -#test( - datetime(year: 2023, month: 4, day: 29) - .display("[year repr:last_two]"), - "23", -) -#test( - datetime(year: 2023, month: 4, day: 29) - .display("[year] [month repr:long] [day] [week_number] [weekday]"), - "2023 April 29 17 Saturday", -) - -// Test displaying of times -#test(datetime(hour: 14, minute: 26, second: 50).display(), "14:26:50") -#test(datetime(hour: 14, minute: 26, second: 50).display("[hour]"), "14") -#test( - datetime(hour: 14, minute: 26, second: 50) - .display("[hour repr:12 padding:none]"), - "2", -) -#test( - datetime(hour: 14, minute: 26, second: 50) - .display("[hour], [minute], [second]"), "14, 26, 50", -) - -// Test displaying of datetimes -#test( - datetime(year: 2023, month: 4, day: 29, hour: 14, minute: 26, second: 50).display(), - "2023-04-29 14:26:50", -) - -// Test getting the year/month/day etc. of a datetime -#let d = datetime(year: 2023, month: 4, day: 29, hour: 14, minute: 26, second: 50) -#test(d.year(), 2023) -#test(d.month(), 4) -#test(d.weekday(), 6) -#test(d.day(), 29) -#test(d.hour(), 14) -#test(d.minute(), 26) -#test(d.second(), 50) - -#let e = datetime(year: 2023, month: 4, day: 29) -#test(e.hour(), none) -#test(e.minute(), none) -#test(e.second(), none) - -// Test today -#test(datetime.today().display(), "1970-01-01") -#test(datetime.today(offset: auto).display(), "1970-01-01") -#test(datetime.today(offset: 2).display(), "1970-01-01") - ---- -// Error: 2-12 at least one of date or time must be fully specified -#datetime() - ---- -// Error: 2-42 time is invalid -#datetime(hour: 25, minute: 0, second: 0) - ---- -// Error: 2-41 date is invalid -#datetime(year: 2000, month: 2, day: 30) - ---- -// Error: 27-34 missing closing bracket for bracket at index 0 -#datetime.today().display("[year") - ---- -// Error: 27-38 invalid component name 'nothing' at index 1 -#datetime.today().display("[nothing]") - ---- -// Error: 27-50 invalid modifier 'wrong' at index 6 -#datetime.today().display("[year wrong:last_two]") - ---- -// Error: 27-33 expected component name at index 2 -#datetime.today().display(" []") - ---- -// Error: 2-36 failed to format datetime (insufficient information) -#datetime.today().display("[hour]") diff --git a/tests/typ/compute/data.typ b/tests/typ/compute/data.typ deleted file mode 100644 index 03b17aed..00000000 --- a/tests/typ/compute/data.typ +++ /dev/null @@ -1,144 +0,0 @@ -// Test reading structured data and files. -// Ref: false - ---- -// Test reading plain text files -#let data = read("/assets/text/hello.txt") -#test(data, "Hello, world!\n") - ---- -// Error: 18-44 file not found (searched at assets/text/missing.txt) -#let data = read("/assets/text/missing.txt") - ---- -// Error: 18-40 file is not valid utf-8 -#let data = read("/assets/text/bad.txt") - ---- -// Test reading CSV data. -// Ref: true -#set page(width: auto) -#let data = csv("/assets/data/zoo.csv") -#let cells = data.at(0).map(strong) + data.slice(1).flatten() -#table(columns: data.at(0).len(), ..cells) - ---- -// Test reading CSV data with dictionary rows enabled. -#let data = csv("/assets/data/zoo.csv", row-type: dictionary) -#test(data.len(), 3) -#test(data.at(0).Name, "Debby") -#test(data.at(2).Weight, "150kg") -#test(data.at(1).Species, "Tiger") - ---- -// Error: 6-16 file not found (searched at typ/compute/nope.csv) -#csv("nope.csv") - ---- -// Error: 6-28 failed to parse CSV (found 3 instead of 2 fields in line 3) -#csv("/assets/data/bad.csv") - ---- -// Test error numbering with dictionary rows. -// Error: 6-28 failed to parse CSV (found 3 instead of 2 fields in line 3) -#csv("/assets/data/bad.csv", row-type: dictionary) - ---- -// Test reading JSON data. -#let data = json("/assets/data/zoo.json") -#test(data.len(), 3) -#test(data.at(0).name, "Debby") -#test(data.at(2).weight, 150) - ---- -// Error: 7-30 failed to parse JSON (expected value at line 3 column 14) -#json("/assets/data/bad.json") - ---- -// Test reading TOML data. -#let data = toml("/assets/data/toml-types.toml") -#test(data.string, "wonderful") -#test(data.integer, 42) -#test(data.float, 3.14) -#test(data.boolean, true) -#test(data.array, (1, "string", 3.0, false)) -#test(data.inline_table, ("first": "amazing", "second": "greater") ) -#test(data.table.element, 5) -#test(data.table.others, (false, "indeed", 7)) -#test(data.date_time, datetime( - year: 2023, - month: 2, - day: 1, - hour: 15, - minute: 38, - second: 57, -)) -#test(data.date_time2, datetime( - year: 2023, - month: 2, - day: 1, - hour: 15, - minute: 38, - second: 57, -)) -#test(data.date, datetime( - year: 2023, - month: 2, - day: 1, -)) -#test(data.time, datetime( - hour: 15, - minute: 38, - second: 57, -)) - ---- -// Error: 7-30 failed to parse TOML (expected `.`, `=` at line 1 column 16) -#toml("/assets/data/bad.toml") - ---- -// Test reading YAML data -#let data = yaml("/assets/data/yaml-types.yaml") -#test(data.len(), 9) -#test(data.null_key, (none, none)) -#test(data.string, "text") -#test(data.integer, 5) -#test(data.float, 1.12) -#test(data.mapping, ("1": "one", "2": "two")) -#test(data.seq, (1,2,3,4)) -#test(data.bool, false) -#test(data.keys().contains("true"), true) -#test(data.at("1"), "ok") - ---- -// Error: 7-30 failed to parse YAML (did not find expected ',' or ']' at line 2 column 1, while parsing a flow sequence at line 1 column 18) -#yaml("/assets/data/bad.yaml") - ---- -// Test reading XML data. -#let data = xml("/assets/data/hello.xml") -#test(data, (( - tag: "data", - attrs: (:), - children: ( - "\n ", - (tag: "hello", attrs: (name: "hi"), children: ("1",)), - "\n ", - ( - tag: "data", - attrs: (:), - children: ( - "\n ", - (tag: "hello", attrs: (:), children: ("World",)), - "\n ", - (tag: "hello", attrs: (:), children: ("World",)), - "\n ", - ), - ), - "\n", - ), -),)) - ---- -// Error: 6-28 failed to parse XML (found closing tag 'data' instead of 'hello' in line 3) -#xml("/assets/data/bad.xml") diff --git a/tests/typ/compute/eval-path.typ b/tests/typ/compute/eval-path.typ deleted file mode 100644 index 863b6203..00000000 --- a/tests/typ/compute/eval-path.typ +++ /dev/null @@ -1,18 +0,0 @@ -// Test file loading in eval. - ---- -// Test absolute path. -#eval("image(\"/assets/images/tiger.jpg\", width: 50%)") - ---- -#show raw: it => eval(it.text, mode: "markup") - -``` -#show emph: image("/assets/images/tiger.jpg", width: 50%) -_Tiger!_ -``` - ---- -// Test relative path. -// Ref: false -#test(eval(`"HELLO" in read("./eval-path.typ")`.text), true) diff --git a/tests/typ/compute/foundations.typ b/tests/typ/compute/foundations.typ deleted file mode 100644 index eb50c072..00000000 --- a/tests/typ/compute/foundations.typ +++ /dev/null @@ -1,107 +0,0 @@ -// Test foundational functions. -// Ref: false - ---- -#test(type(1), int) -#test(type(ltr), direction) -#test(type(10 / 3), float) - ---- -#test(repr(ltr), "ltr") -#test(repr((1, 2, false, )), "(1, 2, false)") - ---- -// Test panic. -// Error: 2-9 panicked -#panic() - ---- -// Test panic. -// Error: 2-12 panicked with: 123 -#panic(123) - ---- -// Test panic. -// Error: 2-24 panicked with: "this is wrong" -#panic("this is wrong") - ---- -// Test failing assertions. -// Error: 2-16 assertion failed -#assert(1 == 2) - ---- -// Test failing assertions. -// Error: 2-51 assertion failed: two is smaller than one -#assert(2 < 1, message: "two is smaller than one") - ---- -// Test failing assertions. -// Error: 9-15 expected boolean, found string -#assert("true") - ---- -// Test failing assertions. -// Error: 2-19 equality assertion failed: value 10 was not equal to 11 -#assert.eq(10, 11) - ---- -// Test failing assertions. -// Error: 2-55 equality assertion failed: 10 and 12 are not equal -#assert.eq(10, 12, message: "10 and 12 are not equal") - ---- -// Test failing assertions. -// Error: 2-19 inequality assertion failed: value 11 was equal to 11 -#assert.ne(11, 11) - ---- -// Test failing assertions. -// Error: 2-57 inequality assertion failed: must be different from 11 -#assert.ne(11, 11, message: "must be different from 11") - ---- -// Test successful assertions. -#assert(5 > 3) -#assert.eq(15, 15) -#assert.ne(10, 12) - ---- -// Test the `type` function. -#test(type(1), int) -#test(type(ltr), direction) -#test(type(10 / 3), float) - ---- -// Test the eval function. -#test(eval("1 + 2"), 3) -#test(eval("1 + x", scope: (x: 3)), 4) -#test(eval("let x = x + 1; x + 1", scope: (x: 1)), 3) - ---- -// Test evaluation in other modes. -// Ref: true -#eval("[_Hello" + " World!_]") \ -#eval("_Hello" + " World!_", mode: "markup") \ -#eval("RR_1^NN", mode: "math", scope: (RR: math.NN, NN: math.RR)) - ---- -// Error: 7-12 expected pattern -#eval("let") - ---- -#show raw: it => text(font: "PT Sans", eval("[" + it.text + "]")) - -Interacting -``` -#set text(blue) -Blue #move(dy: -0.15em)[🌊] -``` - ---- -// Error: 7-17 cannot continue outside of loop -#eval("continue") - ---- -// Error: 7-12 expected semicolon or line break -#eval("1 2") diff --git a/tests/typ/compute/version.typ b/tests/typ/compute/version.typ deleted file mode 100644 index e33eeb6f..00000000 --- a/tests/typ/compute/version.typ +++ /dev/null @@ -1,47 +0,0 @@ -// Test versions. -// Ref: false - ---- -// Test version constructor. - -// Empty. -#version() - -// Plain. -#version(1, 2) - -// Single Array argument. -#version((1, 2)) - -// Mixed arguments. -#version(1, (2, 3), 4, (5, 6), 7) - ---- -// Test equality of different-length versions -#test(version(), version(0)) -#test(version(0), version(0, 0)) -#test(version(1, 2), version(1, 2, 0, 0, 0, 0)) ---- -// Test `version.at`. - -// Non-negative index in bounds -#test(version(1, 2).at(1), 2) - -// Non-negative index out of bounds -#test(version(1, 2).at(4), 0) - -// Negative index in bounds -#test(version(1, 2).at(-2), 1) - -// Error: 2-22 component index out of bounds (index: -3, len: 2) -#version(1, 2).at(-3) - ---- -// Test version fields. -#test(version(1, 2, 3).major, 1) -#test(version(1, 2, 3).minor, 2) -#test(version(1, 2, 3).patch, 3) - ---- -// Test the type of `sys.version` -#test(type(sys.version), version) |
