| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library trydart.paste_test; | |
| 6 | |
| 7 import 'dart:html'; | |
| 8 import 'dart:async'; | |
| 9 | |
| 10 import 'package:try/src/interaction_manager.dart' show | |
| 11 InteractionManager; | |
| 12 | |
| 13 import 'package:try/src/ui.dart' show | |
| 14 mainEditorPane, | |
| 15 observer; | |
| 16 | |
| 17 import 'package:try/src/user_option.dart' show | |
| 18 UserOption; | |
| 19 | |
| 20 import 'package:expect/expect.dart'; | |
| 21 import 'package:async_helper/async_helper.dart'; | |
| 22 | |
| 23 const Map<String, String> tests = const <String, String> { | |
| 24 '<span><p>//...</p>}</span>': '//...\n}', | |
| 25 'someText': 'someText', | |
| 26 '"\$"': '"<DIAGNOSTIC>\$</DIAGNOSTIC>"', | |
| 27 '"\$\$"': '"<DIAGNOSTIC>\$</DIAGNOSTIC><DIAGNOSTIC>\$</DIAGNOSTIC>"', | |
| 28 '"\$\$4"': '"<DIAGNOSTIC>\$</DIAGNOSTIC><DIAGNOSTIC>\$</DIAGNOSTIC>4"', | |
| 29 '"\$\$4 "': '"<DIAGNOSTIC>\$</DIAGNOSTIC><DIAGNOSTIC>\$</DIAGNOSTIC>4 "', | |
| 30 '1e': '<DIAGNOSTIC>1e</DIAGNOSTIC>', | |
| 31 'r"""\n\n\'"""': 'r"""\n\n\'"""', | |
| 32 '"': '<DIAGNOSTIC>"</DIAGNOSTIC>', | |
| 33 '/**\n*/': '/**\n*/', | |
| 34 | |
| 35 // The following case tests that single line strings can span multiple lines | |
| 36 // via ${}. The string is constructed so that it is possible to tell if the | |
| 37 // line-bases scanner (incorrectly) reverses the order of the string quotes | |
| 38 // in its state string. The example string is a complicated way of writing: | |
| 39 // '[[{{}: {}}]]'. See also | |
| 40 // tests/language/string_interpolation_newline_test.dart. | |
| 41 '"\${ [ "\${ [ \'\${ { \'\${\n{\n} }\' : {\n} } }\' ] }" ] }"': | |
| 42 '"\${ [ "\${ [ \'\${ { \'\${\n{\n} }\' : {\n} } }\' ] }" ] }"', | |
| 43 }; | |
| 44 | |
| 45 List<Node> queryDiagnosticNodes() { | |
| 46 return mainEditorPane.querySelectorAll('a.diagnostic>span'); | |
| 47 } | |
| 48 | |
| 49 Future runTests() { | |
| 50 Iterator<String> keys = tests.keys.iterator; | |
| 51 keys.moveNext(); | |
| 52 mainEditorPane.innerHtml = keys.current; | |
| 53 | |
| 54 Future makeFuture() => new Future(() { | |
| 55 String key = keys.current; | |
| 56 print('Checking $key'); | |
| 57 queryDiagnosticNodes().forEach((Node node) { | |
| 58 node.parent.append(new Text('</DIAGNOSTIC>')); | |
| 59 node.replaceWith(new Text('<DIAGNOSTIC>')); | |
| 60 observer.takeRecords(); // Discard mutations. | |
| 61 }); | |
| 62 Expect.stringEquals(tests[key], mainEditorPane.text); | |
| 63 if (keys.moveNext()) { | |
| 64 key = keys.current; | |
| 65 print('Setting $key'); | |
| 66 mainEditorPane.innerHtml = key; | |
| 67 return makeFuture(); | |
| 68 } else { | |
| 69 // Clear the DOM to work around a bug in test.dart. | |
| 70 document.body.nodes.clear(); | |
| 71 return null; | |
| 72 } | |
| 73 }); | |
| 74 | |
| 75 return makeFuture(); | |
| 76 } | |
| 77 | |
| 78 void main() { | |
| 79 UserOption.storage = {}; | |
| 80 | |
| 81 var interaction = new InteractionManager(); | |
| 82 mainEditorPane = new DivElement(); | |
| 83 document.body.append(mainEditorPane); | |
| 84 observer = new MutationObserver(interaction.onMutation) | |
| 85 ..observe( | |
| 86 mainEditorPane, childList: true, characterData: true, subtree: true); | |
| 87 | |
| 88 asyncTest(runTests); | |
| 89 } | |
| OLD | NEW |