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