OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // Test of FunctionUpdate by pretty printing the updated element before and | 5 // Test of FunctionUpdate by pretty printing the updated element before and |
6 // after. | 6 // after. |
7 library trydart.library_updater_test; | 7 library trydart.library_updater_test; |
8 | 8 |
9 import 'package:dart2js_incremental/library_updater.dart' show | 9 import 'package:dart2js_incremental/library_updater.dart' show |
10 IncrementalCompilerContext, | 10 IncrementalCompilerContext, |
(...skipping 22 matching lines...) Expand all Loading... |
33 ApplyUpdateTestCase( | 33 ApplyUpdateTestCase( |
34 {String before, | 34 {String before, |
35 String after, | 35 String after, |
36 String update}) | 36 String update}) |
37 : this.expectedUpdate = update, | 37 : this.expectedUpdate = update, |
38 super(before: before, after: after, canReuse: true); | 38 super(before: before, after: after, canReuse: true); |
39 | 39 |
40 Future run() => loadMainApp().then((LibraryElement library) { | 40 Future run() => loadMainApp().then((LibraryElement library) { |
41 // Capture the current version of [before] before invoking the [updater]. | 41 // Capture the current version of [before] before invoking the [updater]. |
42 PartialFunctionElement before = library.localLookup(expectedUpdate); | 42 PartialFunctionElement before = library.localLookup(expectedUpdate); |
43 var beforeNode = before.parseNode(compiler); | 43 var beforeNode = before.parseNode(compiler.parsing); |
44 | 44 |
45 var context = new IncrementalCompilerContext(); | 45 var context = new IncrementalCompilerContext(); |
46 LibraryUpdater updater = | 46 LibraryUpdater updater = |
47 new LibraryUpdater(this.compiler, null, nolog, nolog, context); | 47 new LibraryUpdater(this.compiler, null, nolog, nolog, context); |
48 context.registerUriWithUpdates([scriptUri]); | 48 context.registerUriWithUpdates([scriptUri]); |
49 | 49 |
50 bool actualCanReuse = | 50 bool actualCanReuse = |
51 updater.canReuseLibrary( | 51 updater.canReuseLibrary( |
52 library, <Script>[newScriptFrom(library, newSource)]); | 52 library, <Script>[newScriptFrom(library, newSource)]); |
53 Expect.equals(expectedCanReuse, actualCanReuse); | 53 Expect.equals(expectedCanReuse, actualCanReuse); |
54 | 54 |
55 Update update = updater.updates.single; | 55 Update update = updater.updates.single; |
56 | 56 |
57 // Check that the [updater] didn't modify the changed element. | 57 // Check that the [updater] didn't modify the changed element. |
58 Expect.identical(before, update.before); | 58 Expect.identical(before, update.before); |
59 Expect.identical(beforeNode, before.parseNode(compiler)); | 59 Expect.identical(beforeNode, before.parseNode(compiler.parsing)); |
60 | 60 |
61 PartialFunctionElement after = update.after; | 61 PartialFunctionElement after = update.after; |
62 var afterNode = after.parseNode(compiler); | 62 var afterNode = after.parseNode(compiler.parsing); |
63 | 63 |
64 // Check that pretty-printing the elements match [source] (before), and | 64 // Check that pretty-printing the elements match [source] (before), and |
65 // [newSource] (after). | 65 // [newSource] (after). |
66 Expect.stringEquals(source, '$beforeNode'); | 66 Expect.stringEquals(source, '$beforeNode'); |
67 Expect.stringEquals(newSource, '$afterNode'); | 67 Expect.stringEquals(newSource, '$afterNode'); |
68 Expect.notEquals(source, newSource); | 68 Expect.notEquals(source, newSource); |
69 | 69 |
70 // Apply the update. | 70 // Apply the update. |
71 update.apply(); | 71 update.apply(); |
72 | 72 |
73 // Check that the update was applied by pretty-printing [before]. Make no | 73 // Check that the update was applied by pretty-printing [before]. Make no |
74 // assumptions about [after], as the update may destroy that element. | 74 // assumptions about [after], as the update may destroy that element. |
75 beforeNode = before.parseNode(compiler); | 75 beforeNode = before.parseNode(compiler.parsing); |
76 Expect.notEquals(source, '$beforeNode'); | 76 Expect.notEquals(source, '$beforeNode'); |
77 Expect.stringEquals(newSource, '$beforeNode'); | 77 Expect.stringEquals(newSource, '$beforeNode'); |
78 }); | 78 }); |
79 } | 79 } |
80 | 80 |
81 void main() { | 81 void main() { |
82 runTests( | 82 runTests( |
83 [ | 83 [ |
84 new ApplyUpdateTestCase( | 84 new ApplyUpdateTestCase( |
85 before: 'main(){print("Hello, World!");}', | 85 before: 'main(){print("Hello, World!");}', |
(...skipping 12 matching lines...) Expand all Loading... |
98 | 98 |
99 new ApplyUpdateTestCase( | 99 new ApplyUpdateTestCase( |
100 before: 'main(){}', | 100 before: 'main(){}', |
101 after: 'main()=>null;', | 101 after: 'main()=>null;', |
102 update: 'main'), | 102 update: 'main'), |
103 | 103 |
104 // TODO(ahe): When supporting class members, test abstract methods. | 104 // TODO(ahe): When supporting class members, test abstract methods. |
105 ] | 105 ] |
106 ); | 106 ); |
107 } | 107 } |
OLD | NEW |