| OLD | NEW |
| 1 <html> | 1 <html> |
| 2 <head> | 2 <head> |
| 3 <script src="../../http/tests/inspector/inspector-test.js"></script> | 3 <script src="../../http/tests/inspector/inspector-test.js"></script> |
| 4 | 4 |
| 5 <script> | 5 <script> |
| 6 function test() | 6 function test() |
| 7 { | 7 { |
| 8 InspectorTest.runTestSuite([ | 8 InspectorTest.runTestSuite([ |
| 9 function testMatchQuotes(next) | 9 function testMatchQuotes(next) |
| 10 { | 10 { |
| 11 var testStrings = [ | 11 var testStrings = [ |
| 12 {"odd back slashes with text around":"tes\\\"t"}, | 12 {"odd back slashes with text around":"tes\\\"t"}, |
| 13 {"escaped double quotes":"\"test\""}, | 13 {"escaped double quotes":"\"test\""}, |
| 14 {"escaped back slash before double quote":"test\\"}, | 14 {"escaped back slash before double quote":"test\\"}, |
| 15 {1:2}, | 15 {1:2}, |
| 16 {"":""}, | 16 {"":""}, |
| 17 {"nested brackets":{}}, | 17 {"nested brackets":{}}, |
| 18 {"nested brackets with double quotes":{"":""}}, | 18 {"nested brackets with double quotes":{"":""}}, |
| 19 {"etc":{"\\":"\""}}, | 19 {"etc":{"\\":"\""}}, |
| 20 {"etc":{"\\\\":"\\"}}, | 20 {"etc":{"\\\\":"\\"}}, |
| 21 {"etc":{"\\\\\"":"\\\\\""}} | 21 {"etc":{"\\\\\"":"\\\\\""}} |
| 22 ]; | 22 ]; |
| 23 | 23 |
| 24 for (var i = 0; i < testStrings.length; ++i) { | 24 for (var i = 0; i < testStrings.length; ++i) { |
| 25 var string = JSON.stringify(testStrings[i]); | 25 var string = JSON.stringify(testStrings[i]); |
| 26 InspectorTest.addResult("\nParsing " + string); | 26 InspectorTest.addResult("\nParsing " + string); |
| 27 var tokenizer = new Common.TextUtils.BalancedJSONTokenizer(Inspe
ctorTest.addResult.bind(InspectorTest)); | 27 var tokenizer = new TextUtils.TextUtils.BalancedJSONTokenizer(In
spectorTest.addResult.bind(InspectorTest)); |
| 28 var result = tokenizer.write(string); | 28 var result = tokenizer.write(string); |
| 29 if (!result) | 29 if (!result) |
| 30 InspectorTest.addResult(`tokenizer.write() returned ${result
}, true expected`); | 30 InspectorTest.addResult(`tokenizer.write() returned ${result
}, true expected`); |
| 31 } | 31 } |
| 32 next(); | 32 next(); |
| 33 }, | 33 }, |
| 34 | 34 |
| 35 function testMatchSequenceUsingOneShot(next) | 35 function testMatchSequenceUsingOneShot(next) |
| 36 { | 36 { |
| 37 var testData = [ | 37 var testData = [ |
| 38 {"one":"one"}, | 38 {"one":"one"}, |
| 39 [{"one":"one"}, {"two":"two"}], | 39 [{"one":"one"}, {"two":"two"}], |
| 40 [{"one":"one"}, {"two":"two"}, {"three":"three"}], | 40 [{"one":"one"}, {"two":"two"}, {"three":"three"}], |
| 41 ]; | 41 ]; |
| 42 | 42 |
| 43 for (var i = 0; i < testData.length; ++i) { | 43 for (var i = 0; i < testData.length; ++i) { |
| 44 var string = JSON.stringify(testData[i]); | 44 var string = JSON.stringify(testData[i]); |
| 45 InspectorTest.addResult("\nParsing " + string); | 45 InspectorTest.addResult("\nParsing " + string); |
| 46 var tokenizer = new Common.TextUtils.BalancedJSONTokenizer(Inspe
ctorTest.addResult.bind(InspectorTest)); | 46 var tokenizer = new TextUtils.TextUtils.BalancedJSONTokenizer(In
spectorTest.addResult.bind(InspectorTest)); |
| 47 var result = tokenizer.write(string); | 47 var result = tokenizer.write(string); |
| 48 if (!result) | 48 if (!result) |
| 49 InspectorTest.addResult(`tokenizer.write() returned ${result
}, false expected`); | 49 InspectorTest.addResult(`tokenizer.write() returned ${result
}, false expected`); |
| 50 } | 50 } |
| 51 next(); | 51 next(); |
| 52 }, | 52 }, |
| 53 | 53 |
| 54 function testMatchSequenceUsingMultiple(next) | 54 function testMatchSequenceUsingMultiple(next) |
| 55 { | 55 { |
| 56 var testData = [ | 56 var testData = [ |
| 57 {"one":"one"}, | 57 {"one":"one"}, |
| 58 [{"one":"one"}, {"two":"two"}], | 58 [{"one":"one"}, {"two":"two"}], |
| 59 [{"one":"one"}, {"two":"two"}, {"three":"three"}], | 59 [{"one":"one"}, {"two":"two"}, {"three":"three"}], |
| 60 ]; | 60 ]; |
| 61 | 61 |
| 62 for (var i = 0; i < testData.length; ++i) { | 62 for (var i = 0; i < testData.length; ++i) { |
| 63 var string = JSON.stringify(testData[i]); | 63 var string = JSON.stringify(testData[i]); |
| 64 InspectorTest.addResult("\nParsing " + string); | 64 InspectorTest.addResult("\nParsing " + string); |
| 65 var tokenizer = new Common.TextUtils.BalancedJSONTokenizer(Inspe
ctorTest.addResult.bind(InspectorTest), true); | 65 var tokenizer = new TextUtils.TextUtils.BalancedJSONTokenizer(In
spectorTest.addResult.bind(InspectorTest), true); |
| 66 var result = tokenizer.write(string); | 66 var result = tokenizer.write(string); |
| 67 var expectedResult = !(testData[i] instanceof Array); | 67 var expectedResult = !(testData[i] instanceof Array); |
| 68 if (result != expectedResult) | 68 if (result != expectedResult) |
| 69 InspectorTest.addResult(`tokenizer.write() returned ${result
}, ${expectedResult} expected`); | 69 InspectorTest.addResult(`tokenizer.write() returned ${result
}, ${expectedResult} expected`); |
| 70 } | 70 } |
| 71 next(); | 71 next(); |
| 72 }, | 72 }, |
| 73 | 73 |
| 74 function testIncrementalWrites(next) | 74 function testIncrementalWrites(next) |
| 75 { | 75 { |
| 76 var testStrings = [ | 76 var testStrings = [ |
| 77 {"odd back slashes with text around":"tes\\\"t"}, | 77 {"odd back slashes with text around":"tes\\\"t"}, |
| 78 {"escaped double quotes":"\"test\""}, | 78 {"escaped double quotes":"\"test\""}, |
| 79 {"escaped back slash before double quote":"test\\"}, | 79 {"escaped back slash before double quote":"test\\"}, |
| 80 {1:2}, | 80 {1:2}, |
| 81 {"":""}, | 81 {"":""}, |
| 82 {"nested brackets":{}}, | 82 {"nested brackets":{}}, |
| 83 {"nested brackets with double quotes":{"":""}}, | 83 {"nested brackets with double quotes":{"":""}}, |
| 84 {"etc":{"\\":"\""}}, | 84 {"etc":{"\\":"\""}}, |
| 85 {"etc":{"\\\\":"\\"}}, | 85 {"etc":{"\\\\":"\\"}}, |
| 86 {"etc":{"\\\\\"":"\\\\\""}} | 86 {"etc":{"\\\\\"":"\\\\\""}} |
| 87 ]; | 87 ]; |
| 88 var string = JSON.stringify(testStrings); | 88 var string = JSON.stringify(testStrings); |
| 89 var tokenizer = new Common.TextUtils.BalancedJSONTokenizer(Inspector
Test.addResult.bind(InspectorTest), true); | 89 var tokenizer = new TextUtils.TextUtils.BalancedJSONTokenizer(Inspec
torTest.addResult.bind(InspectorTest), true); |
| 90 InspectorTest.addResult("\nRunning at once:"); | 90 InspectorTest.addResult("\nRunning at once:"); |
| 91 var result = tokenizer.write(string); | 91 var result = tokenizer.write(string); |
| 92 if (result) | 92 if (result) |
| 93 InspectorTest.addResult(`tokenizer.write() returned ${result}, f
alse expected`); | 93 InspectorTest.addResult(`tokenizer.write() returned ${result}, f
alse expected`); |
| 94 | 94 |
| 95 for (var sample of [3, 15, 50]) { | 95 for (var sample of [3, 15, 50]) { |
| 96 tokenizer = new Common.TextUtils.BalancedJSONTokenizer(Inspector
Test.addResult.bind(InspectorTest), true); | 96 tokenizer = new TextUtils.TextUtils.BalancedJSONTokenizer(Inspec
torTest.addResult.bind(InspectorTest), true); |
| 97 InspectorTest.addResult("\nRunning by " + sample + ":"); | 97 InspectorTest.addResult("\nRunning by " + sample + ":"); |
| 98 for (var i = 0; i < string.length; i += sample) { | 98 for (var i = 0; i < string.length; i += sample) { |
| 99 var result = tokenizer.write(string.substring(i, i + sample)
); | 99 var result = tokenizer.write(string.substring(i, i + sample)
); |
| 100 var expectedResult = (i + sample < string.length); | 100 var expectedResult = (i + sample < string.length); |
| 101 if (!!result !== expectedResult) | 101 if (!!result !== expectedResult) |
| 102 InspectorTest.addResult(`tokenizer.write() returned ${re
sult}, ${expectedResult} expected`); | 102 InspectorTest.addResult(`tokenizer.write() returned ${re
sult}, ${expectedResult} expected`); |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 next(); | 105 next(); |
| 106 }, | 106 }, |
| 107 | 107 |
| 108 function testGarbageAfterObject(next) | 108 function testGarbageAfterObject(next) |
| 109 { | 109 { |
| 110 var testString = "[{a: 'b'}], {'x': {a: 'b'}}"; | 110 var testString = "[{a: 'b'}], {'x': {a: 'b'}}"; |
| 111 InspectorTest.addResult("\nParsing " + testString); | 111 InspectorTest.addResult("\nParsing " + testString); |
| 112 var tokenizer = new Common.TextUtils.BalancedJSONTokenizer(Inspector
Test.addResult.bind(InspectorTest), true); | 112 var tokenizer = new TextUtils.TextUtils.BalancedJSONTokenizer(Inspec
torTest.addResult.bind(InspectorTest), true); |
| 113 var result = tokenizer.write(testString); | 113 var result = tokenizer.write(testString); |
| 114 InspectorTest.addResult(`tokenizer.write() returned ${result}, false
expected`); | 114 InspectorTest.addResult(`tokenizer.write() returned ${result}, false
expected`); |
| 115 next(); | 115 next(); |
| 116 } | 116 } |
| 117 ]); | 117 ]); |
| 118 } | 118 } |
| 119 </script> | 119 </script> |
| 120 | 120 |
| 121 <body onload="runTest()"> | 121 <body onload="runTest()"> |
| 122 Test Common.TextUtils.BalancedJSONTokenizer. | 122 Test TextUtils.TextUtils.BalancedJSONTokenizer. |
| 123 </p> | 123 </p> |
| 124 </body> | 124 </body> |
| 125 </html> | 125 </html> |
| OLD | NEW |