forked from foliojs/pdfkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.spec.js
More file actions
84 lines (81 loc) · 2.14 KB
/
utils.spec.js
File metadata and controls
84 lines (81 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { normalizeSides, PDFNumber } from '../../lib/utils';
describe('normalizeSides', () => {
test.each([
[1, { top: 1, right: 1, bottom: 1, left: 1 }],
[[1, 2], { top: 1, right: 2, bottom: 1, left: 2 }],
[
{ vertical: 1, horizontal: 2 },
{ top: 1, right: 2, bottom: 1, left: 2 },
],
[[1, 2, 3, 4], { top: 1, right: 2, bottom: 3, left: 4 }],
[
{ top: 1, right: 2, bottom: 3, left: 4 },
{ top: 1, right: 2, bottom: 3, left: 4 },
],
[
{ a: 'hi' },
{ top: undefined, right: undefined, bottom: undefined, left: undefined },
],
[
{ vertical: 'hi' },
{ top: 'hi', right: undefined, bottom: 'hi', left: undefined },
],
[
{ top: undefined },
{ top: undefined, right: undefined, bottom: undefined, left: undefined },
],
[
null,
{ top: undefined, right: undefined, bottom: undefined, left: undefined },
],
[
undefined,
{ top: undefined, right: undefined, bottom: undefined, left: undefined },
],
[true, { top: true, right: true, bottom: true, left: true }],
[false, { top: false, right: false, bottom: false, left: false }],
])('%s -> %s', (size, expected) => {
expect(normalizeSides(size)).toEqual(expected);
});
test('with transformer', () => {
expect(
normalizeSides(
undefined,
{ top: '1', right: '2', bottom: '3', left: '4' },
Number,
),
).toEqual({
top: 1,
right: 2,
bottom: 3,
left: 4,
});
});
});
describe('PDFNumber', () => {
test.each([
[0, 0],
[0.04999999701976776], //float32 rounded down
[0.05],
[0.05000000074505806], //float32 rounded up
[1],
[-1],
[-5.05],
[5.05],
])('PDFNumber(%f) -> %f', (n) => {
expect(PDFNumber(n)).toBeLessThanOrEqual(n);
expect(PDFNumber(n, false)).toBeLessThanOrEqual(n);
});
test.each([
[0],
[0.04999999701976776], //float32 rounded down
[0.05],
[0.05000000074505806], //float32 rounded up
[1],
[-1],
[-5.05],
[5.05],
])('PDFNumber(%f, true) -> %f', (n) => {
expect(PDFNumber(n, true)).toBeGreaterThanOrEqual(n);
});
});