diff options
| author | Pg Biel <9021226+PgBiel@users.noreply.github.com> | 2023-07-11 11:11:18 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-11 16:11:18 +0200 |
| commit | 9b1a2b41f0bb2d62106e029a5a0174dcf07ae0d2 (patch) | |
| tree | 6f0ae44b3dfffd1c5b3e44535716d382ffc41c46 /tests/typ/compiler/methods.typ | |
| parent | 507efc3a1c14e8487705c7424d605a1663d3fe6e (diff) | |
Add fields and methods to several primitives (#790)
Diffstat (limited to 'tests/typ/compiler/methods.typ')
| -rw-r--r-- | tests/typ/compiler/methods.typ | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/tests/typ/compiler/methods.typ b/tests/typ/compiler/methods.typ index 864ed8ad..c0ad5b1d 100644 --- a/tests/typ/compiler/methods.typ +++ b/tests/typ/compiler/methods.typ @@ -53,3 +53,148 @@ // Test content fields method. #test([a].fields(), (text: "a")) #test([a *b*].fields(), (children: ([a], [ ], strong[b]))) + +--- +// Test length unit conversions. +#test((500.934pt).pt(), 500.934) +#test((3.3453cm).cm(), 3.3453) +#test((4.3452mm).mm(), 4.3452) +#test((5.345in).inches(), 5.345) +#test((500.333666999pt).pt(), 500.333666999) +#test((3.5234354cm).cm(), 3.5234354) +#test((4.12345678mm).mm(), 4.12345678) +#test((5.333666999in).inches(), 5.333666999) +#test((4.123456789123456mm).mm(), 4.123456789123456) +#test((254cm).mm(), 2540.0) +#test(calc.round((254cm).inches(), digits: 2), 100.0) +#test((2540mm).cm(), 254.0) +#test(calc.round((2540mm).inches(), digits: 2), 100.0) +#test((100in).pt(), 7200.0) +#test(calc.round((100in).cm(), digits: 2), 254.0) +#test(calc.round((100in).mm(), digits: 2), 2540.0) +#test(5em.abs.cm(), 0.0) +#test((5em + 6in).abs.inches(), 6.0) + +--- +// Error: 2-21 cannot convert a length with non-zero em units (-6pt + 10.5em) to pt +// Hint: 2-21 use 'length.abs.pt()' instead to ignore its em component +#(10.5em - 6pt).pt() + +--- +// Error: 2-12 cannot convert a length with non-zero em units (3em) to cm +// Hint: 2-12 use 'length.abs.cm()' instead to ignore its em component +#(3em).cm() + +--- +// Error: 2-20 cannot convert a length with non-zero em units (-226.77pt + 93em) to mm +// Hint: 2-20 use 'length.abs.mm()' instead to ignore its em component +#(93em - 80mm).mm() + +--- +// Error: 2-24 cannot convert a length with non-zero em units (432pt + 4.5em) to inches +// Hint: 2-24 use 'length.abs.inches()' instead to ignore its em component +#(4.5em + 6in).inches() + +--- +// Test color kind method. +#test(rgb(1, 2, 3, 4).kind(), rgb) +#test(cmyk(4%, 5%, 6%, 7%).kind(), cmyk) +#test(luma(40).kind(), luma) +#test(rgb(1, 2, 3, 4).kind() != luma, true) + +--- +// Test color '.rgba()', '.cmyk()' and '.luma()' without conversions +#test(rgb(1, 2, 3, 4).rgba(), (1, 2, 3, 4)) +#test(rgb(1, 2, 3).rgba(), (1, 2, 3, 255)) +#test(cmyk(20%, 20%, 40%, 20%).cmyk(), (20%, 20%, 40%, 20%)) +#test(luma(40).luma(), 40) + +--- +// Test color conversions. +#test(rgb(1, 2, 3).hex(), "#010203") +#test(rgb(1, 2, 3, 4).hex(), "#01020304") +#test(cmyk(4%, 5%, 6%, 7%).rgba(), (228, 225, 223, 255)) +#test(cmyk(4%, 5%, 6%, 7%).hex(), "#e4e1df") +#test(luma(40).rgba(), (40, 40, 40, 255)) +#test(luma(40).hex(), "#282828") +#test(repr(luma(40).cmyk()), repr((11.76%, 10.59%, 10.59%, 14.12%))) + +--- +// Error: 2-24 cannot obtain cmyk values from rgba color +#rgb(1, 2, 3, 4).cmyk() + +--- +// Error: 2-24 cannot obtain the luma value of rgba color +#rgb(1, 2, 3, 4).luma() + +--- +// Error: 2-29 cannot obtain the luma value of cmyk color +#cmyk(4%, 5%, 6%, 7%).luma() + +--- +// Test alignment methods. +#test(start.axis(), "horizontal") +#test(end.axis(), "horizontal") +#test(left.axis(), "horizontal") +#test(right.axis(), "horizontal") +#test(center.axis(), "horizontal") +#test(top.axis(), "vertical") +#test(bottom.axis(), "vertical") +#test(horizon.axis(), "vertical") +#test(start.inv(), end) +#test(end.inv(), start) +#test(left.inv(), right) +#test(right.inv(), left) +#test(center.inv(), center) +#test(top.inv(), bottom) +#test(bottom.inv(), top) +#test(horizon.inv(), horizon) + +--- +// Test 2d alignment methods. +#test((start + top).inv(), (end + bottom)) +#test((end + top).inv(), (start + bottom)) +#test((left + top).inv(), (right + bottom)) +#test((right + top).inv(), (left + bottom)) +#test((center + top).inv(), (center + bottom)) +#test((start + bottom).inv(), (end + top)) +#test((end + bottom).inv(), (start + top)) +#test((left + bottom).inv(), (right + top)) +#test((right + bottom).inv(), (left + top)) +#test((center + bottom).inv(), (center + top)) +#test((start + horizon).inv(), (end + horizon)) +#test((end + horizon).inv(), (start + horizon)) +#test((left + horizon).inv(), (right + horizon)) +#test((right + horizon).inv(), (left + horizon)) +#test((center + horizon).inv(), (center + horizon)) +#test((top + start).inv(), (end + bottom)) +#test((bottom + end).inv(), (start + top)) +#test((horizon + center).inv(), (center + horizon)) + +--- +// Test direction methods. +#test(ltr.axis(), "horizontal") +#test(rtl.axis(), "horizontal") +#test(ttb.axis(), "vertical") +#test(btt.axis(), "vertical") +#test(ltr.start(), left) +#test(rtl.start(), right) +#test(ttb.start(), top) +#test(btt.start(), bottom) +#test(ltr.end(), right) +#test(rtl.end(), left) +#test(ttb.end(), bottom) +#test(btt.end(), top) +#test(ltr.inv(), rtl) +#test(rtl.inv(), ltr) +#test(ttb.inv(), btt) +#test(btt.inv(), ttb) + +--- +// Test angle methods. +#test(1rad.rad(), 1.0) +#test(1.23rad.rad(), 1.23) +#test(0deg.rad(), 0.0) +#test(2deg.deg(), 2.0) +#test(2.94deg.deg(), 2.94) +#test(0rad.deg(), 0.0) |
