Skip to content

Commit

Permalink
Implement CSS round() function.
Browse files Browse the repository at this point in the history
Co-Authored-By: Emilio Cobos Álvarez <emilio@crisal.io>

Differential Revision: https://phabricator.services.mozilla.com/D156742

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1764850
gecko-commit: 031200e2a50dced5178c02bdcf974a4b9b61e9a3
gecko-reviewers: emilio
  • Loading branch information
cjpearson authored and moz-wptsync-bot committed Nov 7, 2022
1 parent 7107bd7 commit 4593826
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
14 changes: 7 additions & 7 deletions css/css-values/round-function.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@
// Extreme cases:

// 0 step is NaN
test_plus_infinity("round(5, 0)");
test_nan("round(5, 0)");
// both infinite is NaN
test_plus_infinity("round(infinity, infinity)");
test_plus_infinity("round(infinity, -infinity)");
test_plus_infinity("round(-infinity, infinity)");
test_plus_infinity("round(-infinity, -infinity)");
test_nan("round(infinity, infinity)");
test_nan("round(infinity, -infinity)");
test_nan("round(-infinity, infinity)");
test_nan("round(-infinity, -infinity)");

// infinite value with finite step is the same infinity
test_plus_infinity("round(infinity, 5)");
Expand All @@ -87,8 +87,8 @@
// '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");
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)");
Expand Down
26 changes: 18 additions & 8 deletions css/css-values/round-mod-rem-computed.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../support/numeric-testcommon.js"></script>
<div id="target"></div>
<div style="width: 75px;">
<div id="target"></div>
</div>
<script>
// Simple tests
test_math_used('round(10,10)', '10', {type:'number'});
Expand All @@ -18,7 +20,7 @@
test_math_used('calc(round(up, 101,10))', '110', {type:'number'});
test_math_used('calc(round(down, 106,10))', '100', {type:'number'});
test_math_used('calc(round(to-zero,105, 10))', '100', {type:'number'});
test_math_used('calc(round(to-zero,-105, 10))', '100', {type:'number'});
test_math_used('calc(round(to-zero,-105, 10))', '-100', {type:'number'});
test_math_used('calc(round(-100,10))', '-100', {type:'number'});
test_math_used('calc(round(up, -103,10))', '-100', {type:'number'});

Expand Down Expand Up @@ -60,8 +62,8 @@
test_math_used('round(10vw,6vw)', '12vw');
test_math_used('round(10vmin,6vmin)', '12vmin');
test_math_used('round(10vmax,6vmax)', '12vmax');
test_math_used('round(10s,6s)', '12s');
test_math_used('round(10ms,6ms)', '12ms');
test_math_used('round(10s,6s)', '12s', {type:'time'});
test_math_used('round(10ms,6ms)', '12ms', {type:'time'});
test_math_used('round(10deg,6deg)', '12deg', {type:'angle', approx:0.1});
test_math_used('round(10grad,6grad)', '12grad', {type:'angle', approx:0.1});
test_math_used('round(10rad,6rad)', '12rad',{type:'angle', approx:0.1});
Expand All @@ -81,8 +83,8 @@
test_math_used('mod(10vw,6vw)', '4vw');
test_math_used('mod(10vmin,6vmin)', '4vmin');
test_math_used('mod(10vmax,6vmax)', '4vmax');
test_math_used('mod(10s,6s)', '4s');
test_math_used('mod(10ms,6ms)', '4ms');
test_math_used('mod(10s,6s)', '4s', {type:'time'});
test_math_used('mod(10ms,6ms)', '4ms', {type:'time'});
test_math_used('mod(10deg,6deg)', '4deg', {type:'angle', approx:0.1});
test_math_used('mod(10grad,6grad)', '4grad', {type:'angle', approx:0.1});
test_math_used('mod(10rad,6rad)', '4rad',{type:'angle', approx:0.1});
Expand All @@ -102,10 +104,18 @@
test_math_used('rem(10vw,6vw)', '4vw');
test_math_used('rem(10vmin,6vmin)', '4vmin');
test_math_used('rem(10vmax,6vmax)', '4vmax');
test_math_used('rem(10s,6s)', '4s');
test_math_used('rem(10ms,6ms)', '4ms');
test_math_used('rem(10s,6s)', '4s', {type:'time'});
test_math_used('rem(10ms,6ms)', '4ms', {type:'time'});
test_math_used('rem(10deg,6deg)', '4deg', {type:'angle', approx:0.1});
test_math_used('rem(10grad,6grad)', '4grad', {type:'angle', approx:0.1});
test_math_used('rem(10rad,6rad)', '4rad',{type:'angle', approx:0.1});
test_math_used('rem(10turn,6turn)', '4turn',{type:'angle', approx:0.1});

//Test percentage and mixed units
test_math_used('round(10%,1px)', '8px');
test_math_used('round(10%,5px)', '10px');
test_math_used('round(2rem,5px)', '30px');
test_math_used('round(100px,1rem)', '96px');
test_math_used('round(10s,6000ms)', '12s', {type:'time'});
test_math_used('round(10000ms,6s)', '12s', {type:'time'});
</script>

1 comment on commit 4593826

@community-tc-integration
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh oh! Looks like an error! Details

HttpError: You have exceeded a secondary rate limit. Please wait a few minutes before you try again.

Please sign in to comment.