| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <meta charset=utf-8> | |
| 3 <title>CharacterData.substringData</title> | |
| 4 <link rel=help href="https://dom.spec.whatwg.org/#dom-characterdata-substringdat
a"> | |
| 5 <link rel=help href="https://dom.spec.whatwg.org/#dom-characterdata-data"> | |
| 6 <script src="../../../../resources/testharness.js"></script> | |
| 7 <script src="../../../../resources/testharnessreport.js"></script> | |
| 8 <div id="log"></div> | |
| 9 <script> | |
| 10 function testNode(create, type) { | |
| 11 test(function() { | |
| 12 var node = create() | |
| 13 assert_equals(node.data, "test") | |
| 14 | |
| 15 assert_throws(new TypeError(), function() { node.substringData() }) | |
| 16 assert_throws(new TypeError(), function() { node.substringData(0) }) | |
| 17 }, type + ".substringData() with too few arguments") | |
| 18 | |
| 19 test(function() { | |
| 20 var node = create() | |
| 21 assert_equals(node.data, "test") | |
| 22 | |
| 23 assert_equals(node.substringData(0, 1, "test"), "t") | |
| 24 }, type + ".substringData() with too many arguments") | |
| 25 | |
| 26 test(function() { | |
| 27 var node = create() | |
| 28 assert_equals(node.data, "test") | |
| 29 | |
| 30 assert_throws("IndexSizeError", function() { node.substringData(5, 0) }) | |
| 31 assert_throws("IndexSizeError", function() { node.substringData(6, 0) }) | |
| 32 assert_throws("IndexSizeError", function() { node.substringData(-1, 0) }) | |
| 33 }, type + ".substringData() with invalid offset") | |
| 34 | |
| 35 test(function() { | |
| 36 var node = create() | |
| 37 assert_equals(node.data, "test") | |
| 38 | |
| 39 assert_equals(node.substringData(0, 1), "t") | |
| 40 assert_equals(node.substringData(1, 1), "e") | |
| 41 assert_equals(node.substringData(2, 1), "s") | |
| 42 assert_equals(node.substringData(3, 1), "t") | |
| 43 assert_equals(node.substringData(4, 1), "") | |
| 44 }, type + ".substringData() with in-bounds offset") | |
| 45 | |
| 46 test(function() { | |
| 47 var node = create() | |
| 48 assert_equals(node.data, "test") | |
| 49 | |
| 50 assert_equals(node.substringData(0, 0), "") | |
| 51 assert_equals(node.substringData(1, 0), "") | |
| 52 assert_equals(node.substringData(2, 0), "") | |
| 53 assert_equals(node.substringData(3, 0), "") | |
| 54 assert_equals(node.substringData(4, 0), "") | |
| 55 }, type + ".substringData() with zero count") | |
| 56 | |
| 57 test(function() { | |
| 58 var node = create() | |
| 59 assert_equals(node.data, "test") | |
| 60 | |
| 61 assert_equals(node.substringData(0x100000000 + 0, 1), "t") | |
| 62 assert_equals(node.substringData(0x100000000 + 1, 1), "e") | |
| 63 assert_equals(node.substringData(0x100000000 + 2, 1), "s") | |
| 64 assert_equals(node.substringData(0x100000000 + 3, 1), "t") | |
| 65 assert_equals(node.substringData(0x100000000 + 4, 1), "") | |
| 66 }, type + ".substringData() with very large offset") | |
| 67 | |
| 68 test(function() { | |
| 69 var node = create() | |
| 70 assert_equals(node.data, "test") | |
| 71 | |
| 72 assert_equals(node.substringData(-0x100000000 + 2, 1), "s") | |
| 73 }, type + ".substringData() with negative offset") | |
| 74 | |
| 75 test(function() { | |
| 76 var node = create() | |
| 77 assert_equals(node.data, "test") | |
| 78 | |
| 79 assert_equals(node.substringData("test", 3), "tes") | |
| 80 }, type + ".substringData() with string offset") | |
| 81 | |
| 82 test(function() { | |
| 83 var node = create() | |
| 84 assert_equals(node.data, "test") | |
| 85 | |
| 86 assert_equals(node.substringData(0, 1), "t") | |
| 87 assert_equals(node.substringData(0, 2), "te") | |
| 88 assert_equals(node.substringData(0, 3), "tes") | |
| 89 assert_equals(node.substringData(0, 4), "test") | |
| 90 }, type + ".substringData() with in-bounds count") | |
| 91 | |
| 92 test(function() { | |
| 93 var node = create() | |
| 94 assert_equals(node.data, "test") | |
| 95 | |
| 96 assert_equals(node.substringData(0, 5), "test") | |
| 97 assert_equals(node.substringData(2, 20), "st") | |
| 98 }, type + ".substringData() with large count") | |
| 99 | |
| 100 test(function() { | |
| 101 var node = create() | |
| 102 assert_equals(node.data, "test") | |
| 103 | |
| 104 assert_equals(node.substringData(2, 0x100000000 + 1), "s") | |
| 105 }, type + ".substringData() with very large count") | |
| 106 | |
| 107 test(function() { | |
| 108 var node = create() | |
| 109 assert_equals(node.data, "test") | |
| 110 | |
| 111 assert_equals(node.substringData(0, -1), "test") | |
| 112 assert_equals(node.substringData(0, -0x100000000 + 2), "te") | |
| 113 }, type + ".substringData() with negative count") | |
| 114 | |
| 115 test(function() { | |
| 116 var node = create() | |
| 117 assert_equals(node.data, "test") | |
| 118 | |
| 119 node.data = "This is the character data test, other 資料,更多文字" | |
| 120 | |
| 121 assert_equals(node.substringData(12, 4), "char") | |
| 122 assert_equals(node.substringData(39, 2), "資料") | |
| 123 }, type + ".substringData() with non-ASCII data") | |
| 124 | |
| 125 test(function() { | |
| 126 var node = create() | |
| 127 assert_equals(node.data, "test") | |
| 128 | |
| 129 node.data = "🌠 test 🌠 TEST" | |
| 130 | |
| 131 assert_equals(node.substringData(5, 8), "st 🌠 TE") // Counting UTF-16 code
units | |
| 132 }, type + ".substringData() with non-BMP data") | |
| 133 } | |
| 134 | |
| 135 testNode(function() { return document.createTextNode("test") }, "Text") | |
| 136 testNode(function() { return document.createComment("test") }, "Comment") | |
| 137 </script> | |
| OLD | NEW |