Chromium Code Reviews| Index: content/test/data/tree_parser_util_unittest.html |
| diff --git a/content/test/data/tree_parser_util_unittest.html b/content/test/data/tree_parser_util_unittest.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ae540929abca1113f41cfc9ccb425fc434cbb858 |
| --- /dev/null |
| +++ b/content/test/data/tree_parser_util_unittest.html |
| @@ -0,0 +1,70 @@ |
| +<html><body> |
|
dcheng
2015/08/04 00:14:41
Is this run automatically somewhere, or is this es
ncarter (slow)
2015/08/04 23:51:21
It's run manually. I couldn't quite bring myself t
ncarter (slow)
2015/08/05 16:43:13
I went ahead and just removed this file.
|
| +This page contains unittests for tree_parser_util.js |
| +<script src='tree_parser_util.js'></script> |
| + |
| +<pre><code id='output'></code></pre> |
| +<script> |
| +var resultLog = document.getElementById('output'); |
| +function assert(op, input, expectedResult) { |
| + var expectedText = JSON.stringify(expectedResult); |
| + |
| + try { |
| + var output = TreeParserUtil[op](input); |
| + } catch (e) { |
| + var output = e.toString(); |
| + } |
| + var actualText = JSON.stringify(output); |
| + |
| + if (actualText != expectedText) { |
| + resultLog.appendChild(document.createTextNode( |
| + 'FAILURE! during op TreeParserUtil.' + op + '\n' + |
| + ' INPUT: ' + JSON.stringify(input) + '\n' + |
| + ' ACTUAL: ' + actualText + '\n' + |
| + 'EXPECTED: ' + expectedText + '\n\n')); |
| + } |
| +} |
| + |
| +assert('_lex', ' ', []); |
| +assert('_lex', ' ) (', [')', '(']); |
| +assert('_lex', ' ) ab cd((', [')', 'ab', 'cd', '(', '(']); |
| +assert('_lex', 'a.com (y.com ( ) , x.org, z (c.org, z.com (a, d.net())))', |
| + ['a.com', '(', 'y.com', '(', ')', ',', 'x.org', ',', 'z', '(', 'c.org', |
| + ',', 'z.com', '(', 'a', ',', 'd.net', '(', ')', ')', ')', ')']); |
| +assert('parse', 'a.com (y.com (k) , x.org, z.net (c.org, z.com (a, d.net())))', |
| + { "value": "a.com", "children": [ |
| + { "value": "y.com", "children": [ |
| + { "value": "k", "children": [] } |
| + ]}, |
| + { "value": "x.org", "children": [] }, |
| + { "value": "z.net", "children": [ |
| + { "value": "c.org", "children": [] }, |
| + { "value": "z.com", "children": [ |
| + { "value": "a", "children": [] }, |
| + { "value": "d.net", "children": [] } |
| + ]} |
| + ]} |
| + ]}); |
| +assert('parse', '()', 'Error: Expected an identifier, but found "(".') |
| +assert('parse', ')', 'Error: Expected an identifier, but found ")".') |
| +assert('parse', '/', 'Error: Expected an identifier, but found "/".') |
| +assert('parse', '', 'Error: Expected an identifier, but found end-of-stream.') |
| +assert('parse', 'a)', 'Error: Expected end of stream, but found ")".') |
| +assert('parse', 'a.com ()', { "value": "a.com", "children": []}); |
| +assert('parse', 'a.com', { "value": "a.com", "children": []}); |
| +assert('parse', 'a.com wtf', |
| + 'Error: Expected end of stream, but found "wtf".'); |
| +assert('parse', 'a.com () wtf', |
| + 'Error: Expected end of stream, but found "wtf".'); |
| +assert('flatten', |
| + { "value": "y.com", "children": [ |
| + { "value": "k", "children": [] }, |
| + { "value": "j", "children": [] } |
| + ]}, |
| + 'y.com(k(),j())'); |
| +assert('flatten', { "value": "zz", "children": [] }, 'zz()'); |
| + |
| +if (resultLog.children.length == 0) { |
| + resultLog.appendChild(document.createTextNode("All tests passed!")); |
| +} |
| +</script> |
| +</body> |
|
dcheng
2015/08/04 00:14:41
</html>
|