| 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 '../../pkg/expect/lib/expect.dart'; | |
| 21 import '../../pkg/async_helper/lib/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 | |
| 36 List<Node> queryDiagnosticNodes() { | |
| 37 return mainEditorPane.querySelectorAll('a.diagnostic>span'); | |
| 38 } | |
| 39 | |
| 40 Future runTests() { | |
| 41 Iterator<String> keys = tests.keys.iterator; | |
| 42 keys.moveNext(); | |
| 43 mainEditorPane.innerHtml = keys.current; | |
| 44 | |
| 45 Future makeFuture() => new Future(() { | |
| 46 String key = keys.current; | |
| 47 print('Checking $key'); | |
| 48 queryDiagnosticNodes().forEach((Node node) { | |
| 49 node.parent.append(new Text('</DIAGNOSTIC>')); | |
| 50 node.replaceWith(new Text('<DIAGNOSTIC>')); | |
| 51 observer.takeRecords(); // Discard mutations. | |
| 52 }); | |
| 53 Expect.stringEquals(tests[key], mainEditorPane.text); | |
| 54 if (keys.moveNext()) { | |
| 55 key = keys.current; | |
| 56 print('Setting $key'); | |
| 57 mainEditorPane.innerHtml = key; | |
| 58 return makeFuture(); | |
| 59 } else { | |
| 60 // Clear the DOM to work around a bug in test.dart. | |
| 61 document.body.nodes.clear(); | |
| 62 return null; | |
| 63 } | |
| 64 }); | |
| 65 | |
| 66 return makeFuture(); | |
| 67 } | |
| 68 | |
| 69 void main() { | |
| 70 UserOption.storage = {}; | |
| 71 | |
| 72 var interaction = new InteractionManager(); | |
| 73 mainEditorPane = new DivElement(); | |
| 74 document.body.append(mainEditorPane); | |
| 75 observer = new MutationObserver(interaction.onMutation) | |
| 76 ..observe( | |
| 77 mainEditorPane, childList: true, characterData: true, subtree: true); | |
| 78 | |
| 79 asyncTest(runTests); | |
| 80 } | |
| OLD | NEW |