Chromium Code Reviews| Index: dart/tests/try/poi/library_updater_test.dart |
| diff --git a/dart/tests/try/poi/library_updater_test.dart b/dart/tests/try/poi/library_updater_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1a17ff544ec6f113eec2a959bb59902b902559fa |
| --- /dev/null |
| +++ b/dart/tests/try/poi/library_updater_test.dart |
| @@ -0,0 +1,112 @@ |
| +// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +// Test of LibraryUpdater. |
| +library trydart.library_updater_test; |
| + |
| +import 'dart:convert' show |
| + UTF8; |
| + |
| +import 'package:dart2js_incremental/library_updater.dart' show |
| + LibraryUpdater, |
| + Update; |
| + |
| +import 'package:compiler/implementation/elements/elements.dart' show |
| + LibraryElement; |
| + |
| +import 'compiler_test_case.dart'; |
| + |
| +void nolog(_) {} |
| + |
| +class LibraryUpdaterTestCase extends CompilerTestCase { |
| + final String newSource; |
| + |
| + final bool expectedCanReuse; |
| + |
| + final List<String> expectedUpdates; |
| + |
| + LibraryUpdaterTestCase( |
| + String source, |
| + this.newSource, |
| + this.expectedCanReuse, |
|
Johnni Winther
2014/09/29 09:37:57
Change these to named arguments.
ahe
2014/09/29 11:44:42
I really wish we had mandatory named arguments. I
|
| + this.expectedUpdates) |
| + : super(source); |
| + |
| + Future run() => mainApp.then((LibraryElement library) { |
| + LibraryUpdater updater = |
| + new LibraryUpdater(this.compiler, null, scriptUri, nolog, nolog); |
| + bool actualCanReuse = |
| + updater.canReuseLibrary(library, UTF8.encode(newSource)); |
| + Expect.equals(expectedCanReuse, actualCanReuse); |
| + |
| + Expect.setEquals( |
| + expectedUpdates.toSet(), |
| + updater.updates.map((Update update) => update.before.name).toSet()); |
| + }); |
| + |
| + String toString() => 'Before:\n$source\n\n\nAfter:\n$newSource'; |
| +} |
| + |
| +void main() { |
| + runTests( |
| + [ |
| + // Only method body changed. Can be reused if 'main' is |
| + // updated/patched. |
| + new LibraryUpdaterTestCase( |
| + 'main() { print("Hello, World!"); }', |
| + 'main() { print("Hello, Brave New World!"); }', |
| + true, |
| + ['main']), |
| + |
| + // Signature changed. Can't be reused. |
| + new LibraryUpdaterTestCase( |
| + 'main() { print("Hello, World!"); }', |
| + 'void main() { print("Hello, World!"); }', |
| + false, |
| + []), |
| + |
| + // Only whitespace changes. Can be reused; no updates/patches needed. |
|
Johnni Winther
2014/09/29 09:34:42
Add a test for whitespace in the signature.
ahe
2014/09/29 11:44:42
Done.
|
| + new LibraryUpdaterTestCase( |
| + 'main(){print("Hello, World!");}', |
| + 'main() { print ( "Hello, World!" ) ; }', |
| + true, |
| + []), |
| + |
| + |
| + // Arrow function changed to method body. Can be reused if 'main' is |
| + // updated/patched. |
| + new LibraryUpdaterTestCase( |
| + 'main() => null', |
| + 'main() { return null; }', |
| + true, |
| + ['main']), |
| + |
| + // Empty body changed to contain a statement. Can be reused if 'main' |
| + // is updated/patched. |
| + new LibraryUpdaterTestCase( |
| + 'main() {}', |
| + 'main() { return null; }', |
| + true, |
| + ['main']), |
| + |
| + // Empty body changed to arrow. Can be reused if 'main' |
| + // is updated/patched. |
| + new LibraryUpdaterTestCase( |
| + 'main() {}', |
| + 'main() => null;', |
| + true, |
| + ['main']), |
| + |
| + // Arrow changed to empty body. Can be reused if 'main' |
| + // is updated/patched. |
| + new LibraryUpdaterTestCase( |
| + 'main() => null;', |
| + 'main() {}', |
| + true, |
| + ['main']), |
| + |
| + // TODO(ahe): When supporting class members, test abstract methods. |
| + ] |
| + ); |
| +} |