Skip to content

Commit c1075ad

Browse files
authored
* hypot/pow/sqrt calc tests Co-authored-by: Nikos Mouchtaris <[email protected]>
1 parent de21c7f commit c1075ad

File tree

3 files changed

+168
-0
lines changed

3 files changed

+168
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<!DOCTYPE html>
2+
<link rel="help" href="https://drafts.csswg.org/css-values-4/#comp-func">
3+
<link rel="help" href="https://drafts.csswg.org/css-values-4/#numbers">
4+
<link rel="help" href="https://drafts.csswg.org/css-values-4/#calc-type-checking">
5+
<link rel="author" title="Apple Inc">
6+
<script src="/resources/testharness.js"></script>
7+
<script src="/resources/testharnessreport.js"></script>
8+
<script src="../support/numeric-testcommon.js"></script>
9+
<div id="target"></div>
10+
<script>
11+
12+
// Identity tests
13+
test_math_used('pow(1,1)', '1', {type:'number'});
14+
test_math_used('sqrt(1)', '1', {type:'number'});
15+
test_math_used('hypot(1)', '1', {type:'number'});
16+
17+
// Nestings
18+
test_math_used('sqrt(pow(1,1))', '1');
19+
test_math_used('hypot(pow(1, sqrt(1)))', '1');
20+
test_math_used('calc(hypot(pow((1 + sqrt(1)) / 2, sqrt(1))))', '1');
21+
22+
// General calculations
23+
test_math_used('calc(100px * pow(2, pow(2, 2)))','1600px');
24+
test_math_used('calc(1px * pow(2, 3))', '8px')
25+
test_math_used('calc(100px * sqrt(100))', '1000px');
26+
test_math_used('calc(1px * pow(2, sqrt(100))', '1024px');
27+
test_math_used('hypot(3px, 4px)', '5px');
28+
test_math_used('calc(100px * hypot(3, 4))', '500px');
29+
test_math_used('hypot(-5px)', '5px');
30+
test_math_used('calc(1px * hypot(-5))', '5px');
31+
test_math_used('calc(1px * hypot(10000))','10000px');
32+
test_math_used('calc(2px * sqrt(100000000))','20000px');
33+
test_math_used('calc(3px * pow(200, 4))', '33554428px');
34+
35+
//Type checking hypot
36+
test_math_used('hypot(1px)', '1px');
37+
test_math_used('hypot(1cm)', '1cm');
38+
test_math_used('hypot(1mm)', '1mm');
39+
test_math_used('hypot(1Q)', '1Q');
40+
test_math_used('hypot(1in)', '1in');
41+
test_math_used('hypot(1pc)', '1pc');
42+
test_math_used('hypot(1pt)', '1pt');
43+
test_math_used('hypot(1em)', '1em');
44+
test_math_used('hypot(1ex)', '1ex');
45+
test_math_used('hypot(1ch)', '1ch');
46+
test_math_used('hypot(1rem)', '1rem');
47+
test_math_used('hypot(1vh)', '1vh');
48+
test_math_used('hypot(1vw)', '1vw');
49+
test_math_used('hypot(1vmin)', '1vmin');
50+
test_math_used('hypot(1vmax)', '1vmax');
51+
test_math_used('hypot(1s)', '1s', {type:'time'});
52+
test_math_used('hypot(1ms)', '1ms', {type:'time'});
53+
test_math_used('hypot(1deg)', '1deg', {type:'angle', approx:0.001});
54+
test_math_used('hypot(1grad)', '1grad', {type:'angle', approx:0.001});
55+
test_math_used('hypot(1rad)', '1rad', {type:'angle', approx:0.001});
56+
test_math_used('hypot(1turn)', '1turn', {type:'angle', approx:0.001});
57+
</script>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<!DOCTYPE html>
2+
<link rel="help" href="https://drafts.csswg.org/css-values-4/#comp-func">
3+
<link rel="help" href="https://drafts.csswg.org/css-values-4/#numbers">
4+
<link rel="help" href="https://drafts.csswg.org/css-values-4/#calc-type-checking">
5+
<link rel="author" title="Apple Inc">
6+
<script src="/resources/testharness.js"></script>
7+
<script src="/resources/testharnessreport.js"></script>
8+
<script src="../support/parsing-testcommon.js"></script>
9+
<script>
10+
function test_invalid_number(value) {
11+
test_invalid_value('opacity', value);
12+
}
13+
function test_invalid_length(value) {
14+
// 'letter-spacing' accepts <length> only, not <percentage> or any mixes.
15+
test_invalid_value('letter-spacing', value);
16+
}
17+
18+
// Syntax checking
19+
test_invalid_number('hypot()');
20+
test_invalid_number('hypot( )');
21+
test_invalid_number('hypot(,)');
22+
test_invalid_number('hypot(1, )');
23+
test_invalid_number('hypot(, 1)');
24+
test_invalid_number('hypot(1 + )');
25+
test_invalid_number('hypot(1 - )');
26+
test_invalid_number('hypot(1 * )');
27+
test_invalid_number('hypot(1 / )');
28+
test_invalid_number('hypot(1 2)');
29+
test_invalid_number('hypot(1, , 2)');
30+
test_invalid_number('hypot(1, 2)');
31+
test_invalid_number('sqrt()');
32+
test_invalid_number('sqrt( )');
33+
test_invalid_number('sqrt(,)');
34+
test_invalid_number('sqrt(1, )');
35+
test_invalid_number('sqrt(, 1)');
36+
test_invalid_number('sqrt(1 + )');
37+
test_invalid_number('sqrt(1 - )');
38+
test_invalid_number('sqrt(1 * )');
39+
test_invalid_number('sqrt(1 / )');
40+
test_invalid_number('sqrt(1 2)');
41+
test_invalid_number('sqrt(1, , 2)');
42+
test_invalid_number('sqrt(1, 2)');
43+
test_invalid_number('pow( )');
44+
test_invalid_number('pow(,)');
45+
test_invalid_number('pow(1, )');
46+
test_invalid_number('pow(, 1)');
47+
test_invalid_number('pow(1 + )');
48+
test_invalid_number('pow(1 - )');
49+
test_invalid_number('pow(1 * )');
50+
test_invalid_number('pow(1 / )');
51+
test_invalid_number('pow(1 2)');
52+
test_invalid_number('pow(1, , 2)');
53+
test_invalid_number('pow(1, 2)');
54+
55+
// General tests
56+
test_invalid_length('calc(1px * pow(1))');
57+
test_invalid_length('calc(1px * pow(2px, 3px))');
58+
test_invalid_length('calc(sqrt(100px)');
59+
test_invalid_length('hypot(2px, 40%)');
60+
test_invalid_length('hypot(2px, 3)');
61+
test_invalid_length('hypot(3, ,4)');
62+
test_invalid_length('calc(1px * pow(2 3))');
63+
test_invalid_length('hypot()');
64+
test_invalid_length('calc(pow(2))');
65+
test_invalid_length('pow())');
66+
test_invalid_length('calc(sqrt())');
67+
test_invalid_length('calc(sqrt(100, 200))');
68+
</script>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html>
2+
<link rel="help" href="https://drafts.csswg.org/css-values-4/#comp-func">
3+
<link rel="help" href="https://drafts.csswg.org/css-values-4/#numbers">
4+
<link rel="help" href="https://drafts.csswg.org/css-values-4/#calc-serialize">
5+
<link rel="author" title="Apple Inc">
6+
<script src="/resources/testharness.js"></script>
7+
<script src="/resources/testharnessreport.js"></script>
8+
<script src="../support/serialize-testcommon.js"></script>
9+
<div id=target></div>
10+
<script>
11+
function test_serialization(t,s,c) {
12+
test_specified_serialization('opacity', t, s);
13+
test_specified_serialization('transform', `scale(${t})`, `scale(calc(${c}))`);
14+
test_computed_serialization('opacity', t, c);
15+
test_computed_serialization('transform', `scale(${t})`, `matrix(${c}, 0, 0, ${c}, 0, 0)`);
16+
}
17+
18+
test_serialization(
19+
'pow(1,1)',
20+
'calc(1)',
21+
'1');
22+
test_serialization(
23+
'hypot(1)',
24+
'calc(1)',
25+
'1');
26+
test_serialization(
27+
'sqrt(1)',
28+
'calc(1)',
29+
'1');
30+
31+
test_serialization(
32+
'calc(pow(1,1) + 1)',
33+
'calc(2)',
34+
'2');
35+
test_serialization(
36+
'calc(hypot(1) * 2)',
37+
'calc(2)',
38+
'2');
39+
test_serialization(
40+
'calc(sqrt(1) - 1)',
41+
'calc(0)',
42+
'0');
43+
</script>

0 commit comments

Comments
 (0)