Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Unified Diff: dart/tests/try/poi/library_updater_test.dart

Issue 594843003: Introduce LibraryUpdater. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address Johnni's comments. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dart/tests/try/poi/compiler_test_case.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..0a50560948aff3195de040ba5fe8cbf6cadcef68
--- /dev/null
+++ b/dart/tests/try/poi/library_updater_test.dart
@@ -0,0 +1,124 @@
+// 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 before,
+ String after,
+ bool canReuse,
+ List<String> updates})
+ : this.newSource = after,
+ this.expectedCanReuse = canReuse,
+ this.expectedUpdates = updates,
+ super(before);
+
+ 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(
+ before: 'main() { print("Hello, World!"); }',
+ after: 'main() { print("Hello, Brave New World!"); }',
+ canReuse: true,
+ updates: ['main']),
+
+ // Signature changed. Can't be reused.
+ new LibraryUpdaterTestCase(
+ before: 'main() { print("Hello, World!"); }',
+ after: 'void main() { print("Hello, World!"); }',
+ canReuse: false,
+ updates: []),
+
+ // Only whitespace changes. Can be reused; no updates/patches needed.
+ new LibraryUpdaterTestCase(
+ before: 'main(){print("Hello, World!");}',
+ after: 'main() { print ( "Hello, World!" ) ; }',
+ canReuse: true,
+ updates: []),
+
+ // Only whitespace/comment changes (in signature). Can be reused; no
+ // updates/patches needed.
+ new LibraryUpdaterTestCase(
+ before:
+ '/* Implicitly dynamic. */ main ( /* No parameters. */ ) '
+ '{print("Hello, World!");}',
+ after: 'main() {print("Hello, World!");}',
+ canReuse: true,
+ updates: []),
+
+ // Arrow function changed to method body. Can be reused if 'main' is
+ // updated/patched.
+ new LibraryUpdaterTestCase(
+ before: 'main() => null',
+ after: 'main() { return null; }',
+ canReuse: true,
+ updates: ['main']),
+
+ // Empty body changed to contain a statement. Can be reused if 'main'
+ // is updated/patched.
+ new LibraryUpdaterTestCase(
+ before: 'main() {}',
+ after: 'main() { return null; }',
+ canReuse: true,
+ updates: ['main']),
+
+ // Empty body changed to arrow. Can be reused if 'main'
+ // is updated/patched.
+ new LibraryUpdaterTestCase(
+ before: 'main() {}',
+ after: 'main() => null;',
+ canReuse: true,
+ updates: ['main']),
+
+ // Arrow changed to empty body. Can be reused if 'main'
+ // is updated/patched.
+ new LibraryUpdaterTestCase(
+ before: 'main() => null;',
+ after: 'main() {}',
+ canReuse: true,
+ updates: ['main']),
+
+ // TODO(ahe): When supporting class members, test abstract methods.
+ ]
+ );
+}
« no previous file with comments | « dart/tests/try/poi/compiler_test_case.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698