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 'dart:convert' show | 9 import 'dart:convert' show |
10 UTF8; | 10 UTF8; |
11 | 11 |
12 import 'package:dart2js_incremental/library_updater.dart' show | 12 import 'package:dart2js_incremental/library_updater.dart' show |
| 13 IncrementalCompilerContext, |
13 LibraryUpdater, | 14 LibraryUpdater, |
14 Update; | 15 Update; |
15 | 16 |
16 import 'package:compiler/src/scanner/scannerlib.dart' show | 17 import 'package:compiler/src/scanner/scannerlib.dart' show |
17 PartialFunctionElement; | 18 PartialFunctionElement; |
18 | 19 |
19 import 'compiler_test_case.dart'; | 20 import 'compiler_test_case.dart'; |
20 | 21 |
21 import 'library_updater_test.dart' show | 22 import 'library_updater_test.dart' show |
22 LibraryUpdaterTestCase, | 23 LibraryUpdaterTestCase, |
23 nolog; | 24 nolog; |
24 | 25 |
25 class ApplyUpdateTestCase extends LibraryUpdaterTestCase { | 26 class ApplyUpdateTestCase extends LibraryUpdaterTestCase { |
26 final String expectedUpdate; | 27 final String expectedUpdate; |
27 | 28 |
28 ApplyUpdateTestCase( | 29 ApplyUpdateTestCase( |
29 {String before, | 30 {String before, |
30 String after, | 31 String after, |
31 String update}) | 32 String update}) |
32 : this.expectedUpdate = update, | 33 : this.expectedUpdate = update, |
33 super(before: before, after: after, canReuse: true); | 34 super(before: before, after: after, canReuse: true); |
34 | 35 |
35 Future run() => loadMainApp().then((LibraryElement library) { | 36 Future run() => loadMainApp().then((LibraryElement library) { |
36 // Capture the current version of [before] before invoking the [updater]. | 37 // Capture the current version of [before] before invoking the [updater]. |
37 PartialFunctionElement before = library.localLookup(expectedUpdate); | 38 PartialFunctionElement before = library.localLookup(expectedUpdate); |
38 var beforeNode = before.parseNode(compiler); | 39 var beforeNode = before.parseNode(compiler); |
39 | 40 |
| 41 var context = new IncrementalCompilerContext(); |
40 LibraryUpdater updater = | 42 LibraryUpdater updater = |
41 new LibraryUpdater(this.compiler, null, scriptUri, nolog, nolog); | 43 new LibraryUpdater(this.compiler, null, nolog, nolog, context); |
| 44 context.registerUriWithUpdates([scriptUri]); |
| 45 |
42 bool actualCanReuse = | 46 bool actualCanReuse = |
43 updater.canReuseLibrary(library, UTF8.encode(newSource)); | 47 updater.canReuseLibrary(library, UTF8.encode(newSource)); |
44 Expect.equals(expectedCanReuse, actualCanReuse); | 48 Expect.equals(expectedCanReuse, actualCanReuse); |
45 | 49 |
46 Update update = updater.updates.single; | 50 Update update = updater.updates.single; |
47 | 51 |
48 // Check that the [updater] didn't modify the changed element. | 52 // Check that the [updater] didn't modify the changed element. |
49 Expect.identical(before, update.before); | 53 Expect.identical(before, update.before); |
50 Expect.identical(beforeNode, before.parseNode(compiler)); | 54 Expect.identical(beforeNode, before.parseNode(compiler)); |
51 | 55 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 93 |
90 new ApplyUpdateTestCase( | 94 new ApplyUpdateTestCase( |
91 before: 'main(){}', | 95 before: 'main(){}', |
92 after: 'main()=>null;', | 96 after: 'main()=>null;', |
93 update: 'main'), | 97 update: 'main'), |
94 | 98 |
95 // TODO(ahe): When supporting class members, test abstract methods. | 99 // TODO(ahe): When supporting class members, test abstract methods. |
96 ] | 100 ] |
97 ); | 101 ); |
98 } | 102 } |
OLD | NEW |