| <!doctype html> |
| <html> |
| <head> |
| <meta charset="utf-8"> |
| <script src="../../http/tests/inspector/resources/inspector-test.js"></script> |
| <script> |
| function test() |
| { |
| let suite = InspectorTest.createSyncSuite("StringUtilities"); |
| |
| suite.addTestCase({ |
| name: "String.format", |
| test() { |
| InspectorTest.expectThat("%f".format(1.23456789) === "1.234568", "float format specifier with no sub-specifier should show 6 decimal digits"); |
| InspectorTest.expectThat("%.0f".format(1.23456789) === "1", "float format specifier with precision 0 should show 0 decimal digits"); |
| InspectorTest.expectThat("%.1f".format(1.23456789) === "1.2", "float format specifier with precision 1 should show 1 decimal digit"); |
| InspectorTest.expectThat("%.2f".format(1.23456789) === "1.23", "float format specifier with precision 2 should show 2 decimal digits"); |
| InspectorTest.expectThat("%.3f".format(1.23456789) === "1.235", "float format specifier with precision 3 should show 3 decimal digits"); |
| InspectorTest.expectThat("%.4f".format(1.23456789) === "1.2346", "float format specifier with precision 4 should show 4 decimal digits"); |
| InspectorTest.expectThat("%.5f".format(1.23456789) === "1.23457", "float format specifier with precision 5 should show 5 decimal digits"); |
| InspectorTest.expectThat("%.6f".format(1.23456789) === "1.234568", "float format specifier with precision 6 should show 6 decimal digits"); |
| InspectorTest.expectThat("%.7f".format(1.23456789) === "1.2345679", "float format specifier with precision 7 should show 7 decimal digits"); |
| InspectorTest.expectThat("%.8f".format(1.23456789) === "1.23456789", "float format specifier with precision 8 should show 8 decimal digits"); |
| InspectorTest.expectThat("%.9f".format(1.23456789) === "1.234567890", "float format specifier with precision 9 should show 9 decimal digits"); |
| InspectorTest.expectThat("%f".format("1.23456789") === "1.234568", "float format specifier with string argument should attempt conversion to float"); |
| InspectorTest.expectThat("%f".format(Infinity) === "\u221E", "float format specifier with Infinity argument should show \"\u221E\""); |
| InspectorTest.expectThat("%f".format(NaN) === "NaN", "float format specifier with NaN argument should show \"NaN\""); |
| |
| InspectorTest.expectThat("%d".format(137.1) === "137", "integer format specifier with float argument should convert to integer"); |
| InspectorTest.expectThat("%d".format("137") === "137", "integer format specifier with string argument should attempt conversion to integer"); |
| InspectorTest.expectThat("%d".format(Infinity) === "NaN", "integer format specifier with Infinity argument should show \"NaN\""); |
| InspectorTest.expectThat("%d".format(NaN) === "NaN", "integer format specifier with NaN argument should show \"NaN\""); |
| return true; |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "String.prototype.extendedLocaleCompare", |
| test() { |
| InspectorTest.expectEqual("1".extendedLocaleCompare("2"), -1, `"1" < "2"`); |
| InspectorTest.expectEqual("2".extendedLocaleCompare("1"), 1, `"2" > "1"`); |
| InspectorTest.expectEqual("2".extendedLocaleCompare("10"), -1, `"2" < "10"`); |
| InspectorTest.expectEqual("10".extendedLocaleCompare("2"), 1, `"10" > "2"`); |
| InspectorTest.expectEqual("1".extendedLocaleCompare("10"), -1, `"1" < "10"`); |
| InspectorTest.expectEqual("10".extendedLocaleCompare("1"), 1, `"10" > "1"`); |
| |
| InspectorTest.expectEqual("a1".extendedLocaleCompare("a2"), -1, `"a1" < "a2"`); |
| InspectorTest.expectEqual("a2".extendedLocaleCompare("a1"), 1, `"a2" > "a1"`); |
| InspectorTest.expectEqual("a2".extendedLocaleCompare("a10"), -1, `"a2" < "a10"`); |
| InspectorTest.expectEqual("a10".extendedLocaleCompare("a2"), 1, `"a10" > "a2"`); |
| InspectorTest.expectEqual("a1".extendedLocaleCompare("a10"), -1, `"a1" < "a10"`); |
| InspectorTest.expectEqual("a10".extendedLocaleCompare("a1"), 1, `"a10" > "a1"`); |
| return true; |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "String.prototype.get lineCount", |
| test() { |
| InspectorTest.expectEqual("1\n2\n3".lineCount, 3, "A string with two line breaks should have three lines."); |
| InspectorTest.expectEqual("1\n\n3".lineCount, 3, "A string with two consecutive line breaks should have three lines."); |
| InspectorTest.expectEqual("1\n".lineCount, 2, "A string with a traling line breaks should have two lines."); |
| InspectorTest.expectEqual("".lineCount, 1, "An empty string is one line."); |
| |
| return true; |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "String.prototype.get lastLine", |
| test() { |
| InspectorTest.expectEqual("single line".lastLine, "single line", "Last line of one line string is the same string."); |
| InspectorTest.expectEqual("1\n2\n3".lastLine, "3", "Last line of a three line string should be the third line."); |
| InspectorTest.expectEqual("1\n".lastLine, "", "Last line of a string with a traling line break should be empty."); |
| InspectorTest.expectEqual("".lastLine, "", "Last line of an empty string is the same empty string."); |
| |
| return true; |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "String.prototype.truncateStart", |
| test() { |
| const ellipsis = "\u2026"; |
| InspectorTest.expectEqual("abcdef".truncateStart(6), "abcdef", "String stays the same."); |
| InspectorTest.expectEqual("abcdef".truncateStart(5), ellipsis + "cdef", "Ellipsis is inserted before the third character."); |
| InspectorTest.expectEqual("abcdef".truncateStart(4), ellipsis + "def", "Ellipsis is inserted before the fourth character."); |
| return true; |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "String.prototype.truncateMiddle", |
| test() { |
| const ellipsis = "\u2026"; |
| InspectorTest.expectEqual("abcdef".truncateMiddle(6), "abcdef", "String stays the same."); |
| InspectorTest.expectEqual("abcdef".truncateMiddle(5), `ab${ellipsis}ef`, "Ellipsis is inserted in the middle."); |
| InspectorTest.expectEqual("abcdef".truncateMiddle(4), `ab${ellipsis}f`, "Ellipsis is inserted after the second character."); |
| return true; |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "String.prototype.truncateEnd", |
| test() { |
| const ellipsis = "\u2026"; |
| InspectorTest.expectEqual("abcdef".truncateEnd(6), "abcdef", "String stays the same."); |
| InspectorTest.expectEqual("abcdef".truncateEnd(5), "abcd" + ellipsis, "Ellipsis is inserted after the fourth character."); |
| InspectorTest.expectEqual("abcdef".truncateEnd(4), "abc" + ellipsis, "Ellipsis is inserted after the third character."); |
| return true; |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "String.prototype.escapeCharacters", |
| test() { |
| InspectorTest.expectEqual("abcdef".escapeCharacters(), "abcdef", "String stays the same with no escape characters."); |
| InspectorTest.expectEqual("abcdef".escapeCharacters(""), "abcdef", "String stays the same with empty escape characters."); |
| InspectorTest.expectEqual("abcdef".escapeCharacters("g"), "abcdef", "String stays the same with no matching escape characters."); |
| InspectorTest.expectEqual("abcdef".escapeCharacters("c"), "ab\\cdef", "The letter 'c' is escaped."); |
| InspectorTest.expectEqual("abcdef".escapeCharacters("ce"), "ab\\cd\\ef", "The letter 'c' and 'e' are escaped."); |
| InspectorTest.expectEqual("abcdef".escapeCharacters("cee"), "ab\\cd\\ef", "The letter 'c' and 'e' are escaped."); |
| InspectorTest.expectEqual("abcdef".escapeCharacters("ced"), "ab\\c\\d\\ef", "The letter 'c', 'd', and 'e' are escaped."); |
| return true; |
| } |
| }); |
| |
| suite.runTestCasesAndFinish(); |
| } |
| </script> |
| </head> |
| <body onLoad="runTest()"> |
| </body> |
| </html> |