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

Unified Diff: tests/compiler/dart2js/patch_test.dart

Issue 10837233: Add (disabled) patch unit-test for dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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 | « tests/compiler/dart2js/dart2js.status ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/compiler/dart2js/patch_test.dart
diff --git a/tests/compiler/dart2js/patch_test.dart b/tests/compiler/dart2js/patch_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..9bb6b960386590d6c759f9160df89ea00014dc58
--- /dev/null
+++ b/tests/compiler/dart2js/patch_test.dart
@@ -0,0 +1,112 @@
+// Copyright (c) 2012, 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.
+
+#import("../../../lib/compiler/implementation/leg.dart");
+#import("../../../lib/compiler/implementation/elements/elements.dart");
+#import("../../../lib/compiler/implementation/tree/tree.dart");
+#import("../../../lib/compiler/implementation/util/util.dart");
+#import("mock_compiler.dart");
+#import("parser_helper.dart");
+#import("dart:uri");
+
+Compiler applyPatch(String script, String patch) {
+ String core = "$DEFAULT_CORELIB\n$script";
+ MockCompiler compiler = new MockCompiler(coreSource: core);
+
+ var uri = new Uri("core.dartp");
+ var patchScript = new Script(uri, new MockFile(patch));
+ var patchLibrary = new LibraryElement(patchScript);
+
+ compiler.patchParser.scanLibraryElements(patchLibrary);
+ compiler.applyLibraryPatch(compiler.coreLibrary, patchLibrary);
+
+ return compiler;
+}
+
+Element ensure(compiler,
+ String name,
+ Element lookup(name),
+ [bool isPatched = true,
+ bool hasBody = false,
+ bool isGetter = false]) {
+ var element = lookup(buildSourceString(name));
+ Expect.isNotNull(element);
+ if (isGetter) {
+ Expect.isTrue(element is AbstractFieldElement);
+ Expect.isNotNull(element.getter);
+ element = element.getter;
+ }
+ if (element is! ContainerElement &&
+ element is! AbstractFieldElement) {
+ // Classes aren't patched like functions and variables are.
+ Expect.equals(isPatched, element.isPatched);
+ }
+ if (hasBody) {
+ var node = element.parseNode(compiler);
+ Expect.isNotNull(node, "Element isn't parseable, when a body was expected");
+ Expect.isNotNull(node.body, "expected body, bot none found");
+ }
+ return element;
+}
+
+testPatchFunction() {
+ var compiler = applyPatch(
+ "external test();",
+ "patch test() { return 'string'; } ");
+ ensure(compiler, "test", compiler.coreLibrary.find, hasBody: true);
+}
+
+testPatchMember() {
+ var compiler = applyPatch(
+ """
+ class Class {
+ external String toString();
+ }
+ """,
+ """
+ patch class Class {
+ patch String toString() => 'string';
+ }
+ """);
+ var container = ensure(compiler, "Class", compiler.coreLibrary.find);
+ ensure(compiler, "toString", container.lookupLocalMember, hasBody:true);
+}
+
+testPatchGetter() {
+ var compiler = applyPatch(
+ """
+ class Class {
+ external int get field();
+ }
+ """,
+ """
+ patch class Class {
+ patch int get field() => 5;
+ }
+ """);
+ var container = ensure(compiler, "Class", compiler.coreLibrary.find);
+ ensure(compiler,
+ "field",
+ container.lookupLocalMember,
+ isGetter: true,
+ hasBody: true);
+}
+
+testInjectFunction() {
+ var compiler = applyPatch(
+ "",
+ "int _function() => 5;");
+ ensure(compiler,
+ "_function",
+ compiler.coreLibrary.find,
+ hasBody: true,
+ isPatched: false);
+}
+
+main() {
+ testPatchFunction();
+ testPatchMember();
+ testPatchGetter();
+ testInjectFunction();
+}
« no previous file with comments | « tests/compiler/dart2js/dart2js.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698