fune/testing/web-platform/tests/css/css-values/calc-catch-divide-by-0.html
Seokho Song 9868d9049f Bug 1683483 [wpt PR 26959] - CSS calc function should evaluate and parse infinity and NaN, a=testonly
Automatic update from web-platform-tests
CSS calc function should evaluate and parse infinity and NaN

According to the newest version of CSS standard [1],
calc function could return an infinity or NaN value
when the expression has an infinity keyword without NaN product
(like inf-inf) or the division by zero.

Therefore, this initial feature implementation evaluate the expression or keywords infinity value to std::numeric_limits<double>::infinity()
and NaN value to std::numeric_limits<double>::quiet_NaN().
Also, this patch contains the infinity and NaN value serialization.

Design docs: [2]
Feature Status: [3]
Intent to prototype: [4]

[1] https://drafts.csswg.org/css-values/#calc-type-checking
[2] https://bit.ly/349gXjq
[3] https://chromestatus.com/feature/5657825571241984
[4] https://groups.google.com/a/chromium.org/g/blink-dev/c/4cT9dMkzVXE/m/aCT8B6PDAwAJ

Bug: 1133390
Change-Id: Id543e9f9af446de623ecee00ba4a3e03100096b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2465414
Reviewed-by: Xiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: Mason Freed <masonfreed@chromium.org>
Commit-Queue: Seokho Song <0xdevssh@gmail.com>
Cr-Commit-Position: refs/heads/master@{#845066}

--

wpt-commits: 8afe199d816965050217a49a3d4479ec36822d37
wpt-pr: 26959
2021-01-22 04:13:56 +00:00

47 lines
No EOL
1.9 KiB
HTML

<!DOCTYPE HTML>
<title>Zero Division: calc() serialization.</title>
<link rel="author" title="Seokho Song" href="mailto:0xdevssh@gmail.com">
<link rel="help" href="https://drafts.csswg.org/css-values/#calc-type-checking">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../support/serialize-testcommon.js"></script>
<div id="target"></div>
<div id="log"></div>
<script>
function test_serialization(t,s, {prop="width"}={}) {
test_specified_serialization(prop, t, s)
}
//TEST CASE |EXPECTED
var test_map = {
"100px * 0 / 0" :"calc(NaN * 1px)",
"100px / 0" :"calc(infinity * 1px)",
"100px / (0)" :"calc(infinity * 1px)",
"100px / (2 - 2)" :"calc(infinity * 1px)",
"100px / (2 - (-62 + 64))" :"calc(infinity * 1px)",
"100px * (1 / 0)" :"calc(infinity * 1px)",
"100px * (1 / (0))" :"calc(infinity * 1px)",
"100px * (1 / (2 - 2))" :"calc(infinity * 1px)",
"100px * (1 / (2 - (-62 + 64)))" :"calc(infinity * 1px)",
"1px * max(1/0, 0)" :"calc(infinity * 1px)",
"1px * min(1/0, 0)" :"calc(0px)",
"1px * max(0/0, 0)" :"calc(NaN * 1px)",
"1px * min(0/0, 0)" :"calc(NaN * 1px)",
"1px * max(0/0, min(0,10))" :"calc(NaN * 1px)",
"1px * clamp(0/0, 0, 10)" :"calc(NaN * 1px)",
"1px * max(0, min(10, 0/0))" :"calc(NaN * 1px)",
"1px * clamp(0, 10, 0/0)" :"calc(NaN * 1px)",
"1px * max(0, min(0/0, 10))" :"calc(NaN * 1px)",
"1px * clamp(0, 0/0, 10)" :"calc(NaN * 1px)",
"1px * clamp(-1/0, 0, 1/0)" :"calc(0px)",
"1px * clamp(-1/0, 1/0, 10)" :"calc(10px)",
};
for (var exp in test_map) {
test_serialization("calc("+exp+")", test_map[exp])
}
</script>