Truly independent web browser
LibWeb: Support omitted intervals in round()
Callum Law9b6d9799524e
diff --git a/Libraries/LibWeb/Rust/src/css/parser/calc_parser.rs b/Libraries/LibWeb/Rust/src/css/parser/calc_parser.rsindex 55f42fb5dd1..2ad013363f5 100644--- a/Libraries/LibWeb/Rust/src/css/parser/calc_parser.rs+++ b/Libraries/LibWeb/Rust/src/css/parser/calc_parser.rs@@ -509,16 +509,31 @@ pub(crate) fn parse_a_calc_function_node(})}MathFunction::Round => {- if !(2..=3).contains(&arguments.len()) {+ let (strategy, arguments) = match parse_rounding_strategy(arguments[0]) {+ Some(strategy) => (strategy, &arguments[1..]),+ None => (CalcRoundingStrategy::Nearest, arguments.as_slice()),+ };++ if !(1..=2).contains(&arguments.len()) {return Err(CalcParseError::Invalid);}- let (strategy, arguments) = if arguments.len() == 3 {- let strategy = parse_rounding_strategy(arguments[0]).ok_or(CalcParseError::Invalid)?;- (strategy, &arguments[1..])- } else {- (CalcRoundingStrategy::Nearest, arguments.as_slice())- };- let nodes = parse_fixed_arguments(arguments, 2, context)?;++ let mut nodes = arguments+ .iter()+ .map(|argument| parse_argument(argument, context))+ .collect::<Result<Vec<_>>>()?;++ // https://drafts.csswg.org/css-values-4/#funcdef-round+ // If the type of A matches <number>, then B may be omitted, and defaults to 1.+ // NB: We add the default interval of 1 if it is omitted and let the later type check reject the non-number+ // A argument case.+ if nodes.len() == 1 {+ nodes.push(Arc::new(CalcNode::Numeric(CalcNumericValue::Number {+ value: 1.0,+ number_type: 0,+ })));+ }+let types = nodes.iter().map(|node| argument_type(node, percentages_resolve_as))diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-values/round-function.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-values/round-function.txtnew file mode 100644index 00000000000..c916c1d9a97--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-values/round-function.txt@@ -0,0 +1,225 @@+Harness status: OK++Found 219 tests++217 Pass+2 Fail+Pass round(23px, 10px) should be used-value-equivalent to 20px+Pass round(18px, 10px) should be used-value-equivalent to 20px+Pass round(15px, 10px) should be used-value-equivalent to 20px+Pass round(13px, 10px) should be used-value-equivalent to 10px+Pass round(-13px, 10px) should be used-value-equivalent to -10px+Pass round(-18px, 10px) should be used-value-equivalent to -20px+Pass round(23, 10) should be used-value-equivalent to 20+Pass round(18, 10) should be used-value-equivalent to 20+Pass round(15, 10) should be used-value-equivalent to 20+Pass round(13, 10) should be used-value-equivalent to 10+Pass round(-13, 10) should be used-value-equivalent to -10+Pass round(-18, 10) should be used-value-equivalent to -20+Pass round(nearest, 23px, 10px) should be used-value-equivalent to 20px+Pass round(nearest, 18px, 10px) should be used-value-equivalent to 20px+Pass round(nearest, 15px, 10px) should be used-value-equivalent to 20px+Pass round(nearest, 13px, 10px) should be used-value-equivalent to 10px+Pass round(nearest, -13px, 10px) should be used-value-equivalent to -10px+Pass round(nearest, -18px, 10px) should be used-value-equivalent to -20px+Pass round(nearest, 23, 10) should be used-value-equivalent to 20+Pass round(nearest, 18, 10) should be used-value-equivalent to 20+Pass round(nearest, 15, 10) should be used-value-equivalent to 20+Pass round(nearest, 13, 10) should be used-value-equivalent to 10+Pass round(nearest, -13, 10) should be used-value-equivalent to -10+Pass round(nearest, -18, 10) should be used-value-equivalent to -20+Pass round(down, 23px, 10px) should be used-value-equivalent to 20px+Pass round(down, 18px, 10px) should be used-value-equivalent to 10px+Pass round(down, 15px, 10px) should be used-value-equivalent to 10px+Pass round(down, 13px, 10px) should be used-value-equivalent to 10px+Pass round(down, -13px, 10px) should be used-value-equivalent to -20px+Pass round(down, -18px, 10px) should be used-value-equivalent to -20px+Pass round(down, 23, 10) should be used-value-equivalent to 20+Pass round(down, 18, 10) should be used-value-equivalent to 10+Pass round(down, 15, 10) should be used-value-equivalent to 10+Pass round(down, 13, 10) should be used-value-equivalent to 10+Pass round(down, -13, 10) should be used-value-equivalent to -20+Pass round(down, -18, 10) should be used-value-equivalent to -20+Pass round(up, 23px, 10px) should be used-value-equivalent to 30px+Pass round(up, 18px, 10px) should be used-value-equivalent to 20px+Pass round(up, 15px, 10px) should be used-value-equivalent to 20px+Pass round(up, 13px, 10px) should be used-value-equivalent to 20px+Pass round(up, -13px, 10px) should be used-value-equivalent to -10px+Pass round(up, -18px, 10px) should be used-value-equivalent to -10px+Pass round(up, 23, 10) should be used-value-equivalent to 30+Pass round(up, 18, 10) should be used-value-equivalent to 20+Pass round(up, 15, 10) should be used-value-equivalent to 20+Pass round(up, 13, 10) should be used-value-equivalent to 20+Pass round(up, -13, 10) should be used-value-equivalent to -10+Pass round(up, -18, 10) should be used-value-equivalent to -10+Pass round(to-zero, 23px, 10px) should be used-value-equivalent to 20px+Pass round(to-zero, 18px, 10px) should be used-value-equivalent to 10px+Pass round(to-zero, 15px, 10px) should be used-value-equivalent to 10px+Pass round(to-zero, 13px, 10px) should be used-value-equivalent to 10px+Pass round(to-zero, -13px, 10px) should be used-value-equivalent to -10px+Pass round(to-zero, -18px, 10px) should be used-value-equivalent to -10px+Pass round(to-zero, 23, 10) should be used-value-equivalent to 20+Pass round(to-zero, 18, 10) should be used-value-equivalent to 10+Pass round(to-zero, 15, 10) should be used-value-equivalent to 10+Pass round(to-zero, 13, 10) should be used-value-equivalent to 10+Pass round(to-zero, -13, 10) should be used-value-equivalent to -10+Pass round(to-zero, -18, 10) should be used-value-equivalent to -10+Pass round(23px, -10px) should be used-value-equivalent to 20px+Pass round(18px, -10px) should be used-value-equivalent to 20px+Fail round(15px, -10px) should be used-value-equivalent to 20px+Pass round(13px, -10px) should be used-value-equivalent to 10px+Pass round(-13px, -10px) should be used-value-equivalent to -10px+Pass round(-18px, -10px) should be used-value-equivalent to -20px+Pass round(23, -10) should be used-value-equivalent to 20+Pass round(18, -10) should be used-value-equivalent to 20+Fail round(15, -10) should be used-value-equivalent to 20+Pass round(13, -10) should be used-value-equivalent to 10+Pass round(-13, -10) should be used-value-equivalent to -10+Pass round(-18, -10) should be used-value-equivalent to -20+Pass round(10px, 5px) should be used-value-equivalent to 10px+Pass round(nearest, 10px, 5px) should be used-value-equivalent to 10px+Pass round(down, 10px, 5px) should be used-value-equivalent to 10px+Pass round(up, 10px, 5px) should be used-value-equivalent to 10px+Pass round(to-zero, 10px, 5px) should be used-value-equivalent to 10px+Pass round(10, 5) should be used-value-equivalent to 10+Pass round(nearest, 10, 5) should be used-value-equivalent to 10+Pass round(down, 10, 5) should be used-value-equivalent to 10+Pass round(up, 10, 5) should be used-value-equivalent to 10+Pass round(to-zero, 10, 5) should be used-value-equivalent to 10+Pass round(-10px, 5px) should be used-value-equivalent to -10px+Pass round(nearest, -10px, 5px) should be used-value-equivalent to -10px+Pass round(down, -10px, 5px) should be used-value-equivalent to -10px+Pass round(up, -10px, 5px) should be used-value-equivalent to -10px+Pass round(to-zero, -10px, 5px) should be used-value-equivalent to -10px+Pass round(-10, 5) should be used-value-equivalent to -10+Pass round(nearest, -10, 5) should be used-value-equivalent to -10+Pass round(down, -10, 5) should be used-value-equivalent to -10+Pass round(up, -10, 5) should be used-value-equivalent to -10+Pass round(to-zero, -10, 5) should be used-value-equivalent to -10+Pass calc(0px - round(23px, 10px)) should be used-value-equivalent to -20px+Pass calc(0px - round(18px, 10px)) should be used-value-equivalent to -20px+Pass calc(0px - round(15px, 10px)) should be used-value-equivalent to -20px+Pass calc(0px - round(13px, 10px)) should be used-value-equivalent to -10px+Pass calc(0px - round(-13px, 10px)) should be used-value-equivalent to 10px+Pass calc(0px - round(-18px, 10px)) should be used-value-equivalent to 20px+Pass calc(0 - round(23, 10)) should be used-value-equivalent to -20+Pass calc(0 - round(18, 10)) should be used-value-equivalent to -20+Pass calc(0 - round(15, 10)) should be used-value-equivalent to -20+Pass calc(0 - round(13, 10)) should be used-value-equivalent to -10+Pass calc(0 - round(-13, 10)) should be used-value-equivalent to 10+Pass calc(0 - round(-18, 10)) should be used-value-equivalent to 20+Pass calc(0px - round(nearest, 23px, 10px)) should be used-value-equivalent to -20px+Pass calc(0px - round(nearest, 18px, 10px)) should be used-value-equivalent to -20px+Pass calc(0px - round(nearest, 15px, 10px)) should be used-value-equivalent to -20px+Pass calc(0px - round(nearest, 13px, 10px)) should be used-value-equivalent to -10px+Pass calc(0px - round(nearest, -13px, 10px)) should be used-value-equivalent to 10px+Pass calc(0px - round(nearest, -18px, 10px)) should be used-value-equivalent to 20px+Pass calc(0 - round(nearest, 23, 10)) should be used-value-equivalent to -20+Pass calc(0 - round(nearest, 18, 10)) should be used-value-equivalent to -20+Pass calc(0 - round(nearest, 15, 10)) should be used-value-equivalent to -20+Pass calc(0 - round(nearest, 13, 10)) should be used-value-equivalent to -10+Pass calc(0 - round(nearest, -13, 10)) should be used-value-equivalent to 10+Pass calc(0 - round(nearest, -18, 10)) should be used-value-equivalent to 20+Pass calc(0px - round(down, 23px, 10px)) should be used-value-equivalent to -20px+Pass calc(0px - round(down, 18px, 10px)) should be used-value-equivalent to -10px+Pass calc(0px - round(down, 15px, 10px)) should be used-value-equivalent to -10px+Pass calc(0px - round(down, 13px, 10px)) should be used-value-equivalent to -10px+Pass calc(0px - round(down, -13px, 10px)) should be used-value-equivalent to 20px+Pass calc(0px - round(down, -18px, 10px)) should be used-value-equivalent to 20px+Pass calc(0 - round(down, 23, 10)) should be used-value-equivalent to -20+Pass calc(0 - round(down, 18, 10)) should be used-value-equivalent to -10+Pass calc(0 - round(down, 15, 10)) should be used-value-equivalent to -10+Pass calc(0 - round(down, 13, 10)) should be used-value-equivalent to -10+Pass calc(0 - round(down, -13, 10)) should be used-value-equivalent to 20+Pass calc(0 - round(down, -18, 10)) should be used-value-equivalent to 20+Pass calc(0px - round(up, 23px, 10px)) should be used-value-equivalent to -30px+Pass calc(0px - round(up, 18px, 10px)) should be used-value-equivalent to -20px+Pass calc(0px - round(up, 15px, 10px)) should be used-value-equivalent to -20px+Pass calc(0px - round(up, 13px, 10px)) should be used-value-equivalent to -20px+Pass calc(0px - round(up, -13px, 10px)) should be used-value-equivalent to 10px+Pass calc(0px - round(up, -18px, 10px)) should be used-value-equivalent to 10px+Pass calc(0 - round(up, 23, 10)) should be used-value-equivalent to -30+Pass calc(0 - round(up, 18, 10)) should be used-value-equivalent to -20+Pass calc(0 - round(up, 15, 10)) should be used-value-equivalent to -20+Pass calc(0 - round(up, 13, 10)) should be used-value-equivalent to -20+Pass calc(0 - round(up, -13, 10)) should be used-value-equivalent to 10+Pass calc(0 - round(up, -18, 10)) should be used-value-equivalent to 10+Pass calc(0px - round(to-zero, 23px, 10px)) should be used-value-equivalent to -20px+Pass calc(0px - round(to-zero, 18px, 10px)) should be used-value-equivalent to -10px+Pass calc(0px - round(to-zero, 15px, 10px)) should be used-value-equivalent to -10px+Pass calc(0px - round(to-zero, 13px, 10px)) should be used-value-equivalent to -10px+Pass calc(0px - round(to-zero, -13px, 10px)) should be used-value-equivalent to 10px+Pass calc(0px - round(to-zero, -18px, 10px)) should be used-value-equivalent to 10px+Pass calc(0 - round(to-zero, 23, 10)) should be used-value-equivalent to -20+Pass calc(0 - round(to-zero, 18, 10)) should be used-value-equivalent to -10+Pass calc(0 - round(to-zero, 15, 10)) should be used-value-equivalent to -10+Pass calc(0 - round(to-zero, 13, 10)) should be used-value-equivalent to -10+Pass calc(0 - round(to-zero, -13, 10)) should be used-value-equivalent to 10+Pass calc(0 - round(to-zero, -18, 10)) should be used-value-equivalent to 10+Pass round(1.5) should be used-value-equivalent to 2+Pass round(up, 1.5) should be used-value-equivalent to 2+Pass round(down, 1.5) should be used-value-equivalent to 1+Pass round(to-zero, 1.5) should be used-value-equivalent to 1+Pass round(-1.5) should be used-value-equivalent to -1+Pass round(up, -1.5) should be used-value-equivalent to -1+Pass round(down, -1.5) should be used-value-equivalent to -2+Pass round(to-zero, -1.5) should be used-value-equivalent to -1+Pass round(5, 0) should be used-value-equivalent to calc(NaN)+Pass calc(-1 * round(5, 0)) should be used-value-equivalent to calc(NaN)+Pass round(infinity, infinity) should be used-value-equivalent to calc(NaN)+Pass calc(-1 * round(infinity, infinity)) should be used-value-equivalent to calc(NaN)+Pass round(infinity, -infinity) should be used-value-equivalent to calc(NaN)+Pass calc(-1 * round(infinity, -infinity)) should be used-value-equivalent to calc(NaN)+Pass round(-infinity, infinity) should be used-value-equivalent to calc(NaN)+Pass calc(-1 * round(-infinity, infinity)) should be used-value-equivalent to calc(NaN)+Pass round(-infinity, -infinity) should be used-value-equivalent to calc(NaN)+Pass calc(-1 * round(-infinity, -infinity)) should be used-value-equivalent to calc(NaN)+Pass round(NaN, 5) should be used-value-equivalent to calc(NaN)+Pass calc(-1 * round(NaN, 5)) should be used-value-equivalent to calc(NaN)+Pass round(NaN, -5) should be used-value-equivalent to calc(NaN)+Pass calc(-1 * round(NaN, -5)) should be used-value-equivalent to calc(NaN)+Pass round(NaN, 0) should be used-value-equivalent to calc(NaN)+Pass calc(-1 * round(NaN, 0)) should be used-value-equivalent to calc(NaN)+Pass round(NaN, infinity) should be used-value-equivalent to calc(NaN)+Pass calc(-1 * round(NaN, infinity)) should be used-value-equivalent to calc(NaN)+Pass round(NaN, -infinity) should be used-value-equivalent to calc(NaN)+Pass calc(-1 * round(NaN, -infinity)) should be used-value-equivalent to calc(NaN)+Pass round(5, NaN) should be used-value-equivalent to calc(NaN)+Pass calc(-1 * round(5, NaN)) should be used-value-equivalent to calc(NaN)+Pass round(-5, NaN) should be used-value-equivalent to calc(NaN)+Pass calc(-1 * round(-5, NaN)) should be used-value-equivalent to calc(NaN)+Pass round(0, NaN) should be used-value-equivalent to calc(NaN)+Pass calc(-1 * round(0, NaN)) should be used-value-equivalent to calc(NaN)+Pass round(infinity, NaN) should be used-value-equivalent to calc(NaN)+Pass calc(-1 * round(infinity, NaN)) should be used-value-equivalent to calc(NaN)+Pass round(NaN, NaN) should be used-value-equivalent to calc(NaN)+Pass calc(-1 * round(NaN, NaN)) should be used-value-equivalent to calc(NaN)+Pass round(nearest, NaN, 5) should be used-value-equivalent to calc(NaN)+Pass calc(-1 * round(nearest, NaN, 5)) should be used-value-equivalent to calc(NaN)+Pass round(up, NaN, 5) should be used-value-equivalent to calc(NaN)+Pass calc(-1 * round(up, NaN, 5)) should be used-value-equivalent to calc(NaN)+Pass round(down, NaN, 5) should be used-value-equivalent to calc(NaN)+Pass calc(-1 * round(down, NaN, 5)) should be used-value-equivalent to calc(NaN)+Pass round(to-zero, NaN, 5) should be used-value-equivalent to calc(NaN)+Pass calc(-1 * round(to-zero, NaN, 5)) should be used-value-equivalent to calc(NaN)+Pass round(infinity, 5) should be used-value-equivalent to calc(infinity)+Pass round(infinity, -5) should be used-value-equivalent to calc(infinity)+Pass round(-infinity, 5) should be used-value-equivalent to calc(-infinity)+Pass round(-infinity, -5) should be used-value-equivalent to calc(-infinity)+Pass calc(1 / round(5, infinity)) should be used-value-equivalent to calc(infinity)+Pass calc(1 / round(5, -infinity)) should be used-value-equivalent to calc(infinity)+Pass calc(1 / round(-5, infinity)) should be used-value-equivalent to calc(-infinity)+Pass calc(1 / round(-5, -infinity)) should be used-value-equivalent to calc(-infinity)+Pass calc(1 / round(to-zero, 5, infinity)) should be used-value-equivalent to calc(infinity)+Pass calc(1 / round(to-zero, 5, -infinity)) should be used-value-equivalent to calc(infinity)+Pass calc(1 / round(to-zero, -5, infinity)) should be used-value-equivalent to calc(-infinity)+Pass calc(1 / round(to-zero, -5, -infinity)) should be used-value-equivalent to calc(-infinity)+Pass round(up, 1, infinity) should be used-value-equivalent to calc(infinity)+Pass calc(1 / round(up, 0, infinity)) should be used-value-equivalent to calc(infinity)+Pass calc(1 / round(up, -1 * 0, infinity)) should be used-value-equivalent to calc(-infinity)+Pass calc(1 / round(up, -1, infinity)) should be used-value-equivalent to calc(-infinity)+Pass round(down, -1, infinity) should be used-value-equivalent to calc(-infinity)+Pass calc(1 / round(down, -1 * 0, infinity)) should be used-value-equivalent to calc(-infinity)+Pass calc(1 / round(down, 0, infinity)) should be used-value-equivalent to calc(infinity)+Pass calc(1 / round(down, 1, infinity)) should be used-value-equivalent to calc(infinity)+Pass round(down, (7 - 1) / 3, 1) should be used-value-equivalent to 2\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-values/round-function.html b/Tests/LibWeb/Text/input/wpt-import/css/css-values/round-function.htmlnew file mode 100644index 00000000000..e00b9ac097c--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-values/round-function.html@@ -0,0 +1,270 @@+<!doctype html>+<title>round() function</title>+<meta charset=utf-8>+<script src="../../resources/testharness.js"></script>+<script src="../../resources/testharnessreport.js"></script>+<script src="../support/numeric-testcommon.js"></script>++<meta name=author content="Tab Atkins-Bittner">+<link rel=help href="https://drafts.csswg.org/css-values-4/#round-func">++<div id=target></div>+<script>+// No-op round should be same as nearest+test_math_used("round(23px, 10px)", "20px");+test_math_used("round(18px, 10px)", "20px");+test_math_used("round(15px, 10px)", "20px");+test_math_used("round(13px, 10px)", "10px");+test_math_used("round(-13px, 10px)", "-10px");+test_math_used("round(-18px, 10px)", "-20px");++test_math_used("round(23, 10)", "20", { type: "integer" });+test_math_used("round(18, 10)", "20", { type: "integer" });+test_math_used("round(15, 10)", "20", { type: "integer" });+test_math_used("round(13, 10)", "10", { type: "integer" });+test_math_used("round(-13, 10)", "-10", { type: "integer" });+test_math_used("round(-18, 10)", "-20", { type: "integer" });++// Test nearest+test_math_used("round(nearest, 23px, 10px)", "20px");+test_math_used("round(nearest, 18px, 10px)", "20px");+test_math_used("round(nearest, 15px, 10px)", "20px");+test_math_used("round(nearest, 13px, 10px)", "10px");+test_math_used("round(nearest, -13px, 10px)", "-10px");+test_math_used("round(nearest, -18px, 10px)", "-20px");++test_math_used("round(nearest, 23, 10)", "20", { type: "integer" });+test_math_used("round(nearest, 18, 10)", "20", { type: "integer" });+test_math_used("round(nearest, 15, 10)", "20", { type: "integer" });+test_math_used("round(nearest, 13, 10)", "10", { type: "integer" });+test_math_used("round(nearest, -13, 10)", "-10", { type: "integer" });+test_math_used("round(nearest, -18, 10)", "-20", { type: "integer" });++// Test down+test_math_used("round(down, 23px, 10px)", "20px");+test_math_used("round(down, 18px, 10px)", "10px");+test_math_used("round(down, 15px, 10px)", "10px");+test_math_used("round(down, 13px, 10px)", "10px");+test_math_used("round(down, -13px, 10px)", "-20px");+test_math_used("round(down, -18px, 10px)", "-20px");++test_math_used("round(down, 23, 10)", "20", { type: "integer" });+test_math_used("round(down, 18, 10)", "10", { type: "integer" });+test_math_used("round(down, 15, 10)", "10", { type: "integer" });+test_math_used("round(down, 13, 10)", "10", { type: "integer" });+test_math_used("round(down, -13, 10)", "-20", { type: "integer" });+test_math_used("round(down, -18, 10)", "-20", { type: "integer" });++// Test up+test_math_used("round(up, 23px, 10px)", "30px");+test_math_used("round(up, 18px, 10px)", "20px");+test_math_used("round(up, 15px, 10px)", "20px");+test_math_used("round(up, 13px, 10px)", "20px");+test_math_used("round(up, -13px, 10px)", "-10px");+test_math_used("round(up, -18px, 10px)", "-10px");++test_math_used("round(up, 23, 10)", "30", { type: "integer" });+test_math_used("round(up, 18, 10)", "20", { type: "integer" });+test_math_used("round(up, 15, 10)", "20", { type: "integer" });+test_math_used("round(up, 13, 10)", "20", { type: "integer" });+test_math_used("round(up, -13, 10)", "-10", { type: "integer" });+test_math_used("round(up, -18, 10)", "-10", { type: "integer" });++// Test to-zero+test_math_used("round(to-zero, 23px, 10px)", "20px");+test_math_used("round(to-zero, 18px, 10px)", "10px");+test_math_used("round(to-zero, 15px, 10px)", "10px");+test_math_used("round(to-zero, 13px, 10px)", "10px");+test_math_used("round(to-zero, -13px, 10px)", "-10px");+test_math_used("round(to-zero, -18px, 10px)", "-10px");++test_math_used("round(to-zero, 23, 10)", "20", { type: "integer" });+test_math_used("round(to-zero, 18, 10)", "10", { type: "integer" });+test_math_used("round(to-zero, 15, 10)", "10", { type: "integer" });+test_math_used("round(to-zero, 13, 10)", "10", { type: "integer" });+test_math_used("round(to-zero, -13, 10)", "-10", { type: "integer" });+test_math_used("round(to-zero, -18, 10)", "-10", { type: "integer" });++// Test a negative step+test_math_used("round(23px, -10px)", "20px");+test_math_used("round(18px, -10px)", "20px");+test_math_used("round(15px, -10px)", "20px");+test_math_used("round(13px, -10px)", "10px");+test_math_used("round(-13px, -10px)", "-10px");+test_math_used("round(-18px, -10px)", "-20px");++test_math_used("round(23, -10)", "20", { type: "integer" });+test_math_used("round(18, -10)", "20", { type: "integer" });+test_math_used("round(15, -10)", "20", { type: "integer" });+test_math_used("round(13, -10)", "10", { type: "integer" });+test_math_used("round(-13, -10)", "-10", { type: "integer" });+test_math_used("round(-18, -10)", "-20", { type: "integer" });++// Test with value that is an exact multiple of step+test_math_used("round(10px, 5px)", "10px");+test_math_used("round(nearest, 10px, 5px)", "10px");+test_math_used("round(down, 10px, 5px)", "10px");+test_math_used("round(up, 10px, 5px)", "10px");+test_math_used("round(to-zero, 10px, 5px)", "10px");++test_math_used("round(10, 5)", "10", { type: "integer" });+test_math_used("round(nearest, 10, 5)", "10", { type: "integer" });+test_math_used("round(down, 10, 5)", "10", { type: "integer" });+test_math_used("round(up, 10, 5)", "10", { type: "integer" });+test_math_used("round(to-zero, 10, 5)", "10", { type: "integer" });++test_math_used("round(-10px, 5px)", "-10px");+test_math_used("round(nearest, -10px, 5px)", "-10px");+test_math_used("round(down, -10px, 5px)", "-10px");+test_math_used("round(up, -10px, 5px)", "-10px");+test_math_used("round(to-zero, -10px, 5px)", "-10px");++test_math_used("round(-10, 5)", "-10", { type: "integer" });+test_math_used("round(nearest, -10, 5)", "-10", { type: "integer" });+test_math_used("round(down, -10, 5)", "-10", { type: "integer" });+test_math_used("round(up, -10, 5)", "-10", { type: "integer" });+test_math_used("round(to-zero, -10, 5)", "-10", { type: "integer" });++// Test negation of the round operation+test_math_used("calc(0px - round(23px, 10px))", "-20px");+test_math_used("calc(0px - round(18px, 10px))", "-20px");+test_math_used("calc(0px - round(15px, 10px))", "-20px");+test_math_used("calc(0px - round(13px, 10px))", "-10px");+test_math_used("calc(0px - round(-13px, 10px))", "10px");+test_math_used("calc(0px - round(-18px, 10px))", "20px");++test_math_used("calc(0 - round(23, 10))", "-20", { type: "integer" });+test_math_used("calc(0 - round(18, 10))", "-20", { type: "integer" });+test_math_used("calc(0 - round(15, 10))", "-20", { type: "integer" });+test_math_used("calc(0 - round(13, 10))", "-10", { type: "integer" });+test_math_used("calc(0 - round(-13, 10))", "10", { type: "integer" });+test_math_used("calc(0 - round(-18, 10))", "20", { type: "integer" });++// Test negation of nearest+test_math_used("calc(0px - round(nearest, 23px, 10px))", "-20px");+test_math_used("calc(0px - round(nearest, 18px, 10px))", "-20px");+test_math_used("calc(0px - round(nearest, 15px, 10px))", "-20px");+test_math_used("calc(0px - round(nearest, 13px, 10px))", "-10px");+test_math_used("calc(0px - round(nearest, -13px, 10px))", "10px");+test_math_used("calc(0px - round(nearest, -18px, 10px))", "20px");++test_math_used("calc(0 - round(nearest, 23, 10))", "-20", { type: "integer" });+test_math_used("calc(0 - round(nearest, 18, 10))", "-20", { type: "integer" });+test_math_used("calc(0 - round(nearest, 15, 10))", "-20", { type: "integer" });+test_math_used("calc(0 - round(nearest, 13, 10))", "-10", { type: "integer" });+test_math_used("calc(0 - round(nearest, -13, 10))", "10", { type: "integer" });+test_math_used("calc(0 - round(nearest, -18, 10))", "20", { type: "integer" });++// Test negation of down+test_math_used("calc(0px - round(down, 23px, 10px))", "-20px");+test_math_used("calc(0px - round(down, 18px, 10px))", "-10px");+test_math_used("calc(0px - round(down, 15px, 10px))", "-10px");+test_math_used("calc(0px - round(down, 13px, 10px))", "-10px");+test_math_used("calc(0px - round(down, -13px, 10px))", "20px");+test_math_used("calc(0px - round(down, -18px, 10px))", "20px");++test_math_used("calc(0 - round(down, 23, 10))", "-20", { type: "integer" });+test_math_used("calc(0 - round(down, 18, 10))", "-10", { type: "integer" });+test_math_used("calc(0 - round(down, 15, 10))", "-10", { type: "integer" });+test_math_used("calc(0 - round(down, 13, 10))", "-10", { type: "integer" });+test_math_used("calc(0 - round(down, -13, 10))", "20", { type: "integer" });+test_math_used("calc(0 - round(down, -18, 10))", "20", { type: "integer" });++// Test negation of up+test_math_used("calc(0px - round(up, 23px, 10px))", "-30px");+test_math_used("calc(0px - round(up, 18px, 10px))", "-20px");+test_math_used("calc(0px - round(up, 15px, 10px))", "-20px");+test_math_used("calc(0px - round(up, 13px, 10px))", "-20px");+test_math_used("calc(0px - round(up, -13px, 10px))", "10px");+test_math_used("calc(0px - round(up, -18px, 10px))", "10px");++test_math_used("calc(0 - round(up, 23, 10))", "-30", { type: "integer" });+test_math_used("calc(0 - round(up, 18, 10))", "-20", { type: "integer" });+test_math_used("calc(0 - round(up, 15, 10))", "-20", { type: "integer" });+test_math_used("calc(0 - round(up, 13, 10))", "-20", { type: "integer" });+test_math_used("calc(0 - round(up, -13, 10))", "10", { type: "integer" });+test_math_used("calc(0 - round(up, -18, 10))", "10", { type: "integer" });++// Test negation of to-zero+test_math_used("calc(0px - round(to-zero, 23px, 10px))", "-20px");+test_math_used("calc(0px - round(to-zero, 18px, 10px))", "-10px");+test_math_used("calc(0px - round(to-zero, 15px, 10px))", "-10px");+test_math_used("calc(0px - round(to-zero, 13px, 10px))", "-10px");+test_math_used("calc(0px - round(to-zero, -13px, 10px))", "10px");+test_math_used("calc(0px - round(to-zero, -18px, 10px))", "10px");++test_math_used("calc(0 - round(to-zero, 23, 10))", "-20", { type: "integer" });+test_math_used("calc(0 - round(to-zero, 18, 10))", "-10", { type: "integer" });+test_math_used("calc(0 - round(to-zero, 15, 10))", "-10", { type: "integer" });+test_math_used("calc(0 - round(to-zero, 13, 10))", "-10", { type: "integer" });+test_math_used("calc(0 - round(to-zero, -13, 10))", "10", { type: "integer" });+test_math_used("calc(0 - round(to-zero, -18, 10))", "10", { type: "integer" });++// Test omission of <step> argument+test_math_used("round(1.5)", "2", { type: "integer" });+test_math_used("round(up, 1.5)", "2", { type: "integer" });+test_math_used("round(down, 1.5)", "1", { type: "integer" });+test_math_used("round(to-zero, 1.5)", "1", { type: "integer" });+test_math_used("round(-1.5)", "-1", { type: "integer" });+test_math_used("round(up, -1.5)", "-1", { type: "integer" });+test_math_used("round(down, -1.5)", "-2", { type: "integer" });+test_math_used("round(to-zero, -1.5)", "-1", { type: "integer" });++// Extreme cases:++// 0 step is NaN+test_nan("round(5, 0)");+// both infinite is NaN+test_nan("round(infinity, infinity)");+test_nan("round(infinity, -infinity)");+test_nan("round(-infinity, infinity)");+test_nan("round(-infinity, -infinity)");+// NaN is infectious.+// https://drafts.csswg.org/css-values-4/#calc-ieee+test_nan("round(NaN, 5)");+test_nan("round(NaN, -5)");+test_nan("round(NaN, 0)");+test_nan("round(NaN, infinity)");+test_nan("round(NaN, -infinity)");+test_nan("round(5, NaN)");+test_nan("round(-5, NaN)");+test_nan("round(0, NaN)");+test_nan("round(infinity, NaN)");+test_nan("round(NaN, NaN)");+test_nan("round(nearest, NaN, 5)");+test_nan("round(up, NaN, 5)");+test_nan("round(down, NaN, 5)");+test_nan("round(to-zero, NaN, 5)");++// infinite value with finite step is the same infinity+test_plus_infinity("round(infinity, 5)");+test_plus_infinity("round(infinity, -5)");+test_minus_infinity("round(-infinity, 5)");+test_minus_infinity("round(-infinity, -5)");++// Finite value with infinite step depends on rounding strategy.+// 'nearest' and 'to-zero': pos and +0 go to +0, neg and -0 go to -0+test_plus_zero("round(5, infinity)");+test_plus_zero("round(5, -infinity)");+test_minus_zero("round(-5, infinity)");+test_minus_zero("round(-5, -infinity)");+test_plus_zero("round(to-zero, 5, infinity)");+test_plus_zero("round(to-zero, 5, -infinity)");+test_minus_zero("round(to-zero, -5, infinity)");+test_minus_zero("round(to-zero, -5, -infinity)");+// 'up': pos goes to +inf, 0+ goes to 0+, else 0-+test_plus_infinity("round(up, 1, infinity)");+test_plus_zero("round(up, 0, infinity)");+test_minus_zero("round(up, -1 * 0, infinity)");+test_minus_zero("round(up, -1, infinity)");+// 'down': neg goes to -inf, -0 goes to -0, else 0++test_minus_infinity("round(down, -1, infinity)");+test_minus_zero("round(down, -1 * 0, infinity)");+test_plus_zero("round(down, 0, infinity)");+test_plus_zero("round(down, 1, infinity)");++// In this test if the multiplication is factored into the sum first, the+// result of the round will be incorrect, because of floating point inprecision.+// round(down, 2.3333333 - 0.33333334, 1) = round(down, 1.99999996, 1) = 1+test_math_used('round(down, (7 - 1) / 3, 1)', '2', {type:'number'});+</script>