calc-integer.html (1708B)
1 <!doctype html> 2 <meta charset="utf-8"> 3 <title>CSS Tests: calc() and division for integers</title> 4 <link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io"> 5 <link rel="author" title="Mozilla" href="https://mozilla.org"> 6 <link rel="help" href="https://drafts.csswg.org/css-values-4/#calc-range"> 7 <link rel="help" href="https://github.com/w3c/csswg-drafts/issues/2337"> 8 <script src="/resources/testharness.js"></script> 9 <script src="/resources/testharnessreport.js"></script> 10 <div id="test"></div> 11 <script> 12 const TESTS = [ 13 { 14 specified: "calc(2)", 15 computed: "2", 16 description: "Sanity", 17 }, 18 { 19 specified: "calc(4 / 2)", 20 computed: "2", 21 description: "Basic division works", 22 }, 23 { 24 specified: "calc(1 / 2)", 25 computed: "1", 26 description: "Rounds up if fractional part is >= 0.5", 27 }, 28 { 29 specified: "calc(0.5)", 30 computed: "1", 31 description: "Accepts numbers, and rounds", 32 }, 33 { 34 specified: "calc(6 / 2.0)", 35 computed: "3", 36 description: "Operation between <integer> and <number> works", 37 }, 38 { 39 specified: "calc(1 / 3)", 40 computed: "0", 41 description: "Rounds down if fractional part is < 0.5", 42 }, 43 { 44 specified: "calc(calc(1 / 3) * 3)", 45 computed: "1", 46 description: "Only rounds at the end of the conversion", 47 } 48 ]; 49 50 const testElement = document.getElementById("test"); 51 for (const { specified, computed, description } of TESTS) { 52 test(function() { 53 testElement.style.zIndex = "42"; // Just something that we know it's valid and makes tests not rely on order. 54 testElement.style.zIndex = specified; 55 assert_equals(getComputedStyle(testElement).zIndex, computed); 56 }, description); 57 } 58 </script>