mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 10:00:54 +00:00
Bug 1275546 - Use CSS lexer to parse angle values in css-angle.js . r=nchevobbe
MozReview-Commit-ID: DVqlbrruf2b
This commit is contained in:
parent
dbf7715579
commit
ed4558f67f
@ -10,6 +10,8 @@ const SPECIALVALUES = new Set([
|
|||||||
"unset"
|
"unset"
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const {getCSSLexer} = require("devtools/shared/css-lexer");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This module is used to convert between various angle units.
|
* This module is used to convert between various angle units.
|
||||||
*
|
*
|
||||||
@ -66,7 +68,12 @@ CssAngle.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
get valid() {
|
get valid() {
|
||||||
return /^-?\d+\.?\d*(deg|rad|grad|turn)$/gi.test(this.authored);
|
let token = getCSSLexer(this.authored).nextToken();
|
||||||
|
if (!token) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return (token.tokenType === "dimension"
|
||||||
|
&& token.text.toLowerCase() in CssAngle.ANGLEUNIT);
|
||||||
},
|
},
|
||||||
|
|
||||||
get specialValue() {
|
get specialValue() {
|
||||||
|
@ -156,7 +156,7 @@ OutputParser.prototype = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let angleOK = function (angle) {
|
let angleOK = function (angle) {
|
||||||
return /^-?\d+\.?\d*(deg|rad|grad|turn)$/gi.test(angle);
|
return (new angleUtils.CssAngle(angle)).valid;
|
||||||
};
|
};
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -13,6 +13,7 @@ add_task(function* () {
|
|||||||
|
|
||||||
info("Starting the test");
|
info("Starting the test");
|
||||||
testAngleUtils();
|
testAngleUtils();
|
||||||
|
testAngleValidity();
|
||||||
|
|
||||||
host.destroy();
|
host.destroy();
|
||||||
gBrowser.removeCurrentTab();
|
gBrowser.removeCurrentTab();
|
||||||
@ -35,6 +36,16 @@ function testAngleUtils() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testAngleValidity() {
|
||||||
|
let data = getAngleValidityData();
|
||||||
|
|
||||||
|
for (let {angle, result} of data) {
|
||||||
|
let testAngle = new angleUtils.CssAngle(angle);
|
||||||
|
|
||||||
|
is(testAngle.valid, result, `Testing that "${angle}" is ${testAngle.valid ? " a valid" : "an invalid" } angle`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function testToString(angle, deg, rad, grad, turn) {
|
function testToString(angle, deg, rad, grad, turn) {
|
||||||
angle.angleUnit = angleUtils.CssAngle.ANGLEUNIT.deg;
|
angle.angleUnit = angleUtils.CssAngle.ANGLEUNIT.deg;
|
||||||
is(angle.toString(), deg, "toString() with deg type");
|
is(angle.toString(), deg, "toString() with deg type");
|
||||||
@ -49,6 +60,43 @@ function testToString(angle, deg, rad, grad, turn) {
|
|||||||
is(angle.toString(), turn, "toString() with turn type");
|
is(angle.toString(), turn, "toString() with turn type");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getAngleValidityData() {
|
||||||
|
return [{
|
||||||
|
angle: "0.2turn",
|
||||||
|
result: true
|
||||||
|
}, {
|
||||||
|
angle: "-0.2turn",
|
||||||
|
result: true
|
||||||
|
}, {
|
||||||
|
angle: "-.2turn",
|
||||||
|
result: true
|
||||||
|
}, {
|
||||||
|
angle: "1e02turn",
|
||||||
|
result: true
|
||||||
|
}, {
|
||||||
|
angle: "-2e2turn",
|
||||||
|
result: true
|
||||||
|
}, {
|
||||||
|
angle: ".2turn",
|
||||||
|
result: true
|
||||||
|
}, {
|
||||||
|
angle: "0.2aaturn",
|
||||||
|
result: false
|
||||||
|
}, {
|
||||||
|
angle: "2dega",
|
||||||
|
result: false
|
||||||
|
}, {
|
||||||
|
angle: "0.deg",
|
||||||
|
result: false
|
||||||
|
}, {
|
||||||
|
angle: ".deg",
|
||||||
|
result: false
|
||||||
|
}, {
|
||||||
|
angle: "..2turn",
|
||||||
|
result: false
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
function getTestData() {
|
function getTestData() {
|
||||||
return [{
|
return [{
|
||||||
authored: "0deg",
|
authored: "0deg",
|
||||||
|
Loading…
Reference in New Issue
Block a user