Skip to content

Commit 08b09c6

Browse files
committed
Allow out of range math functions result in random fixed value
[the spec](https://drafts.csswg.org/css-values-4/#calc-range) states that "Parse-time range-checking of values is not performed within math functions, and therefore out-of-range values do not cause the declaration to become invalid". This means we should allow math functions that result in out of range results in <random-value-sharing> fixed values at parse time with the expectation that they will be clamped at compute time
1 parent 98685b7 commit 08b09c6

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

css/css-values/random-computed.tentative.html

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
}, `Property ${property} value on pseudo element '${pseudo_element}' '${specified}'${titleExtra ? ' ' + titleExtra : ''}`);
144144
}
145145

146-
function test_random_computed_value_has_fixed(property, specified, minPercentage, maxPercentage, titleExtra) {
146+
function test_random_computed_value_has_fixed(property, specified, minPercentage, maxPercentage, expectedFixedValue = undefined, titleExtra = undefined) {
147147
test(() => {
148148
for (i = 0; i < iterations; ++i) {
149149
const target = document.getElementById('target');
@@ -164,8 +164,12 @@
164164
let [fixedString, fixedValue] = fixedComponent.split(' ');
165165

166166
assert_equals(fixedString, 'fixed', specified);
167-
assert_greater_than_equal(parseFloat(fixedValue), 0, specified);
168-
assert_less_than(parseFloat(fixedValue), 1, specified);
167+
if (expectedFixedValue) {
168+
assert_equals(parseFloat(fixedValue), expectedFixedValue);
169+
} else {
170+
assert_greater_than_equal(parseFloat(fixedValue), 0, specified);
171+
assert_less_than(parseFloat(fixedValue), 1, specified);
172+
}
169173
assert_equals(minComponent, minPercentage, specified);
170174
assert_equals(maxComponent, maxPercentage, specified);
171175
}
@@ -260,6 +264,10 @@
260264
// Test unresolvable percentage values
261265
test_random_computed_value_has_fixed('translate', 'random(10%, 100%)', '10%', '100%');
262266

267+
// Test out of range math functions for fixed value
268+
test_random_computed_value_has_fixed('translate', 'random(fixed random(1, 2), 10%, 100%)', '10%', '100%');
269+
test_random_computed_value_has_fixed('translate', 'random(fixed random(-2, -1), 10%, 100%)', '10%', '100%', 0);
270+
263271
// Test random value sharing
264272
test(() => {
265273
const holder = document.createElement('div');

css/css-values/random-invalid.tentative.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
test_invalid_value('width', 'random(element-shared 1px, 2px)');
2323
test_invalid_value('width', 'random(1px, 2px, 1px, element-shared)');
2424
test_invalid_value('width', 'random(--foo --bar, 1px, 2px)');
25-
test_invalid_value('width', 'random(fixed random(1, 2), 1px, 2px)');
2625
test_invalid_value('width', 'random(fixed 0.5 element-shared, 1px, 2px)');
2726
test_invalid_value('width', 'random(fixed 0.5 auto, 1px, 2px)');
2827
test_invalid_value('width', 'random(fixed 0.5 --foo, 1px, 2px)');

0 commit comments

Comments
 (0)