Skip to content

Commit

Permalink
tablex-test: add tests for convert-length-to-pt
Browse files Browse the repository at this point in the history
  • Loading branch information
dixslyf committed Dec 2, 2023
1 parent 100d949 commit 65aae94
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
Binary file modified tablex-test.pdf
Binary file not shown.
83 changes: 82 additions & 1 deletion tablex-test.typ
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#import "src/common.typ": calc-mod
#import "src/utilities.typ": default-if-auto
#import "src/utilities.typ": default-if-auto, convert-length-to-pt
#import "tablex.typ": *

*Test*
Expand Down Expand Up @@ -783,3 +783,84 @@ Combining em and pt (with a stroke object):
}),
[E]
)

= Length to pt conversion

#let convert-length-to-pt-test(
len, expected,
page-size: 100pt,
frac-amount: 10,
frac-total: 10pt,
) = {
set text(size: 10pt) // Set 1em to 10pt
style(styles => {
let actual = convert-length-to-pt(
len,
styles: styles,
page-size: page-size,
frac-amount: frac-amount,
frac-total: frac-total,
)

[
Input type: #type(len) \
Input length: #len \
Expected: #expected \
Actual: #actual \
Pass: #{expected == actual} \
]
})
}

// `length` tests
#convert-length-to-pt-test(0pt, 0pt) \
#convert-length-to-pt-test(1pt, 1pt) \
#convert-length-to-pt-test(1em, 10pt) \
#convert-length-to-pt-test(-1pt, -1pt) \
#convert-length-to-pt-test(-1em, -10pt) \
#convert-length-to-pt-test(0.5pt, 0.5pt) \
#convert-length-to-pt-test(0.5em, 5pt) \
#convert-length-to-pt-test(-0.5pt, -0.5pt) \
#convert-length-to-pt-test(-0.5em, -5pt) \
#convert-length-to-pt-test(0.5pt + 0.5em, 5.5pt) \
#convert-length-to-pt-test(0.5pt - 0.5em, -4.5pt) \
#convert-length-to-pt-test(-0.5pt + 0.5em, 4.5pt) \
#convert-length-to-pt-test(-0.5pt - 0.5em, -5.5pt)

// `ratio` tests
#convert-length-to-pt-test(1%, 1pt) \
#convert-length-to-pt-test(-1%, -1pt) \
#convert-length-to-pt-test(0.5%, 0.5pt) \
#convert-length-to-pt-test(-0.5%, -0.5pt)

// `fraction` tests
#convert-length-to-pt-test(1fr, 1pt) \
#convert-length-to-pt-test(-1fr, -1pt) \
#convert-length-to-pt-test(0.5fr, 0.5pt) \
#convert-length-to-pt-test(-0.5fr, -0.5pt)

// `relative` tests
#convert-length-to-pt-test(0% + 0pt + 0em, 0pt) \
#convert-length-to-pt-test(0% + 0pt + 1em, 10pt) \
#convert-length-to-pt-test(0% + 1pt + 0em, 1pt) \
#convert-length-to-pt-test(0% + 1pt + 1em, 11pt) \
#convert-length-to-pt-test(1% + 0pt + 0em, 1pt) \
#convert-length-to-pt-test(1% + 0pt + 1em, 11pt) \
#convert-length-to-pt-test(1% + 1pt + 0em, 2pt) \
#convert-length-to-pt-test(1% + 1pt + 1em, 12pt)

#convert-length-to-pt-test(0% + 0pt + 0.5em, 5pt) \
#convert-length-to-pt-test(0% + 0.5pt + 0em, 0.5pt) \
#convert-length-to-pt-test(0% + 0.5pt + 0.5em, 5.5pt) \
#convert-length-to-pt-test(0.5% + 0pt + 0em, 0.5pt) \
#convert-length-to-pt-test(0.5% + 0pt + 0.5em, 5.5pt) \
#convert-length-to-pt-test(0.5% + 0.5pt + 0em, 1pt) \
#convert-length-to-pt-test(0.5% + 0.5pt + 0.5em, 6pt)

#convert-length-to-pt-test(0% + 0pt - 0.5em, -5pt) \
#convert-length-to-pt-test(0% - 0.5pt + 0em, -0.5pt) \
#convert-length-to-pt-test(0% - 0.5pt - 0.5em, -5.5pt) \
#convert-length-to-pt-test(-0.5% + 0pt + 0em, -0.5pt) \
#convert-length-to-pt-test(-0.5% + 0pt - 0.5em, -5.5pt) \
#convert-length-to-pt-test(-0.5% - 0.5pt + 0em, -1pt) \
#convert-length-to-pt-test(-0.5% - 0.5pt - 0.5em, -6pt)

0 comments on commit 65aae94

Please sign in to comment.