blob: 574043e84d8171529ba41be478a2eef48cb12ad8 [file] [log] [blame]
<!doctype html>
<meta charset="utf-8">
<title>CSSMathValue subclass tests</title>
<link rel="help" href="https://drafts.css-houdini.org/css-typed-om-1/#complex-numeric">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../resources/testhelper.js"></script>
<script>
'use strict';
const gVariadicMathValueSubclasses = [
{ subclass: CSSMathSum, operator: 'sum' },
{ subclass: CSSMathProduct, operator: 'product' },
{ subclass: CSSMathMin, operator: 'min' },
{ subclass: CSSMathMax, operator: 'max' },
];
for (const {subclass, operator} of gVariadicMathValueSubclasses) {
test(() => {
assert_throws(new SyntaxError(), () => new subclass());
}, 'Constructing a ' + subclass.name + ' with no arguments throws a SyntaxError');
test(() => {
const result = new subclass(CSS.number(0));
assert_equals(result.operator, operator);
assert_style_value_array_equals(result.values, [CSS.number(0)]);
}, subclass.name + ' can be constructed from a single number CSSUnitValue');
test(() => {
const args = [CSS.number(1), CSS.number(2), CSS.number(3), CSS.number(4), CSS.number(5)]
const result = new subclass(...args);
assert_equals(result.operator, operator);
assert_style_value_array_equals(result.values, args);
}, subclass.name + ' can be constructed from more than one number CSSUnitValue');
test(() => {
let result = new subclass(CSS.number(1), CSS.number(2));
assert_throws(new TypeError(), () => result.operator = 'foo');
}, subclass.name + '.operator is readonly');
}
const gUnaryMathValueSubclasses = [
{ subclass: CSSMathNegate, operator: 'negate' },
{ subclass: CSSMathInvert, operator: 'invert' },
]
for (const {subclass, operator} of gUnaryMathValueSubclasses) {
test(() => {
const result1 = new subclass(CSS.number(0));
assert_equals(result1.operator, operator);
assert_style_value_equals(result1.value, CSS.number(0));
const result2 = new subclass(0);
assert_equals(result2.operator, operator);
assert_style_value_equals(result2.value, CSS.number(0));
}, subclass.name + ' can be constructed from a single numberish value');
test(() => {
let result = new subclass(CSS.number(1));
assert_throws(new TypeError(), () => result.operator = 'foo');
}, subclass.name + '.operator is readonly');
}
</script>