Chromium Code Reviews| Index: LayoutTests/inspector/json-balanced-tokenizer.html |
| diff --git a/LayoutTests/inspector/json-balanced-tokenizer.html b/LayoutTests/inspector/json-balanced-tokenizer.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c11b57e89cac7e383b49290248a4d30b0c2553ec |
| --- /dev/null |
| +++ b/LayoutTests/inspector/json-balanced-tokenizer.html |
| @@ -0,0 +1,111 @@ |
| +<html> |
| +<head> |
| +<script src="../http/tests/inspector/inspector-test.js"></script> |
| + |
| +<script> |
| +function test() |
| +{ |
| + InspectorTest.runTestSuite([ |
| + function testMatchQuotes(next) |
| + { |
| + var testStrings = [ |
| + {"odd back slashes with text around":"tes\\\"t"}, |
| + {"escaped double quotes":"\"test\""}, |
| + {"escaped back slash before double quote":"test\\"}, |
| + {1:2}, |
| + {"":""}, |
| + {"nested brackets":{}}, |
| + {"nested brackets with double quotes":{"":""}}, |
| + {"etc":{"\\":"\""}}, |
| + {"etc":{"\\\\":"\\"}}, |
| + {"etc":{"\\\\\"":"\\\\\""}} |
| + ]; |
| + |
| + for (var i = 0; i < testStrings.length; ++i) { |
| + var string = JSON.stringify(testStrings[i]); |
| + InspectorTest.addResult("\nParsing " + string); |
| + var tokenizer = new WebInspector.TextUtils.BalancedJSONTokenizer(InspectorTest.addResult.bind(InspectorTest)); |
| + tokenizer.write(string); |
| + } |
| + next(); |
| + }, |
| + |
| + function testMatchSequenceUsingOneShot(next) |
| + { |
| + var testData = [ |
| + {"one":"one"}, |
| + [{"one":"one"}, {"two":"two"}], |
| + [{"one":"one"}, {"two":"two"}, {"three":"three"}], |
| + ]; |
| + |
| + for (var i = 0; i < testData.length; ++i) { |
| + var string = JSON.stringify(testData[i]); |
| + InspectorTest.addResult("\nParsing " + string); |
| + var tokenizer = new WebInspector.TextUtils.BalancedJSONTokenizer(InspectorTest.addResult.bind(InspectorTest)); |
| + tokenizer.write(string); |
| + } |
| + next(); |
| + }, |
| + |
| + function testMatchSequenceUsingMultiple(next) |
| + { |
| + var testData = [ |
| + {"one":"one"}, |
| + [{"one":"one"}, {"two":"two"}], |
| + [{"one":"one"}, {"two":"two"}, {"three":"three"}], |
| + ]; |
| + |
| + for (var i = 0; i < testData.length; ++i) { |
| + var string = JSON.stringify(testData[i]); |
| + InspectorTest.addResult("\nParsing " + string); |
| + var tokenizer = new WebInspector.TextUtils.BalancedJSONTokenizer(InspectorTest.addResult.bind(InspectorTest), true); |
| + tokenizer.write(string); |
| + } |
| + next(); |
| + }, |
| + |
| + function testIncrementalWrites(next) |
| + { |
| + var testStrings = [ |
| + {"odd back slashes with text around":"tes\\\"t"}, |
| + {"escaped double quotes":"\"test\""}, |
| + {"escaped back slash before double quote":"test\\"}, |
| + {1:2}, |
| + {"":""}, |
| + {"nested brackets":{}}, |
| + {"nested brackets with double quotes":{"":""}}, |
| + {"etc":{"\\":"\""}}, |
| + {"etc":{"\\\\":"\\"}}, |
| + {"etc":{"\\\\\"":"\\\\\""}} |
| + ]; |
| + var string = JSON.stringify(testStrings); |
| + var tokenizer = new WebInspector.TextUtils.BalancedJSONTokenizer(InspectorTest.addResult.bind(InspectorTest), true); |
| + InspectorTest.addResult("\nRunning at once:"); |
| + tokenizer.write(string); |
| + |
| + tokenizer = new WebInspector.TextUtils.BalancedJSONTokenizer(InspectorTest.addResult.bind(InspectorTest), true); |
|
alph
2015/03/01 11:30:13
great place to have a loop over [3, 15, 50].
pfeldman
2015/03/01 12:18:53
Done.
|
| + InspectorTest.addResult("\nRunning by 3:"); |
| + for (var i = 0; i < string.length; i += 3) |
| + tokenizer.write(string.substring(i, i + 3)); |
| + |
| + tokenizer = new WebInspector.TextUtils.BalancedJSONTokenizer(InspectorTest.addResult.bind(InspectorTest), true); |
| + InspectorTest.addResult("\nRunning by 15:"); |
| + for (var i = 0; i < string.length; i += 15) |
| + tokenizer.write(string.substring(i, i + 15)); |
| + |
| + tokenizer = new WebInspector.TextUtils.BalancedJSONTokenizer(InspectorTest.addResult.bind(InspectorTest), true); |
| + InspectorTest.addResult("\nRunning by 50:"); |
| + for (var i = 0; i < string.length; i += 50) |
| + tokenizer.write(string.substring(i, i + 50)); |
| + |
| + next(); |
| + } |
| + ]); |
| +} |
| +</script> |
| + |
| +<body onload="runTest()"> |
| +Test WebInspector.TextUtils.BalancedJSONTokenizer. |
| +</p> |
| +</body> |
| +</html> |