blob: 8aaccee975b5e6647c592ed5e09f0c9f6c19c538 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script>
function test()
{
let suite = InspectorTest.createSyncSuite("TextUtilities");
suite.addTestCase({
name: "WI.rangeForNextCSSNameOrValue",
test() {
function testValid(text, index, expected) {
let actual = WI.rangeForNextCSSNameOrValue(text, index);
InspectorTest.expectShallowEqual(actual, expected, `Next name/value token in "${text}" starting at index ${index} is "${text.substring(actual.from, actual.to)}" [${actual.from}, ${actual.to}]`);
}
// Test empty string and out-of-bounds index
testValid("", 0, {from: 0, to: 0});
testValid("", 2, {from: 0, to: 0});
// Test basic string
testValid("foo", 0, {from: 0, to: 3});
testValid("foo", 2, {from: 0, to: 3});
// Test string with single colon
testValid("foo:bar", 0, {from: 0, to: 3});
testValid("foo:bar", 2, {from: 0, to: 3});
testValid("foo:bar", 3, {from: 4, to: 7});
testValid("foo:bar", 5, {from: 4, to: 7});
// Test string with extra whitespace
testValid("foo: bar ;", 0, {from: 0, to: 3});
testValid("foo: bar ;", 2, {from: 0, to: 3});
testValid("foo: bar ;", 3, {from: 6, to: 9});
testValid("foo: bar ;", 5, {from: 6, to: 9});
// Test string with multiple colons
testValid("foo: url(http://baz);", 0, {from: 0, to: 3});
testValid("foo: url(http://baz);", 2, {from: 0, to: 3});
testValid("foo: url(http://baz);", 3, {from: 5, to: 20});
testValid("foo: url(http://baz);", 5, {from: 5, to: 20});
return true;
}
});
suite.runTestCasesAndFinish();
}
</script>
</head>
<body onLoad="runTest()">
<p>Testing basic functionality of functions defined in TextUtilities.js.</p>
</body>
</html>