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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/compiler/dart2js/dart2js.status ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
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.
4
5 #import("../../../lib/compiler/implementation/leg.dart");
6 #import("../../../lib/compiler/implementation/elements/elements.dart");
7 #import("../../../lib/compiler/implementation/tree/tree.dart");
8 #import("../../../lib/compiler/implementation/util/util.dart");
9 #import("mock_compiler.dart");
10 #import("parser_helper.dart");
11 #import("dart:uri");
12
13 Compiler applyPatch(String script, String patch) {
14 String core = "$DEFAULT_CORELIB\n$script";
15 MockCompiler compiler = new MockCompiler(coreSource: core);
16
17 var uri = new Uri("core.dartp");
18 var patchScript = new Script(uri, new MockFile(patch));
19 var patchLibrary = new LibraryElement(patchScript);
20
21 compiler.patchParser.scanLibraryElements(patchLibrary);
22 compiler.applyLibraryPatch(compiler.coreLibrary, patchLibrary);
23
24 return compiler;
25 }
26
27 Element ensure(compiler,
28 String name,
29 Element lookup(name),
30 [bool isPatched = true,
31 bool hasBody = false,
32 bool isGetter = false]) {
33 var element = lookup(buildSourceString(name));
34 Expect.isNotNull(element);
35 if (isGetter) {
36 Expect.isTrue(element is AbstractFieldElement);
37 Expect.isNotNull(element.getter);
38 element = element.getter;
39 }
40 if (element is! ContainerElement &&
41 element is! AbstractFieldElement) {
42 // Classes aren't patched like functions and variables are.
43 Expect.equals(isPatched, element.isPatched);
44 }
45 if (hasBody) {
46 var node = element.parseNode(compiler);
47 Expect.isNotNull(node, "Element isn't parseable, when a body was expected");
48 Expect.isNotNull(node.body, "expected body, bot none found");
49 }
50 return element;
51 }
52
53 testPatchFunction() {
54 var compiler = applyPatch(
55 "external test();",
56 "patch test() { return 'string'; } ");
57 ensure(compiler, "test", compiler.coreLibrary.find, hasBody: true);
58 }
59
60 testPatchMember() {
61 var compiler = applyPatch(
62 """
63 class Class {
64 external String toString();
65 }
66 """,
67 """
68 patch class Class {
69 patch String toString() => 'string';
70 }
71 """);
72 var container = ensure(compiler, "Class", compiler.coreLibrary.find);
73 ensure(compiler, "toString", container.lookupLocalMember, hasBody:true);
74 }
75
76 testPatchGetter() {
77 var compiler = applyPatch(
78 """
79 class Class {
80 external int get field();
81 }
82 """,
83 """
84 patch class Class {
85 patch int get field() => 5;
86 }
87 """);
88 var container = ensure(compiler, "Class", compiler.coreLibrary.find);
89 ensure(compiler,
90 "field",
91 container.lookupLocalMember,
92 isGetter: true,
93 hasBody: true);
94 }
95
96 testInjectFunction() {
97 var compiler = applyPatch(
98 "",
99 "int _function() => 5;");
100 ensure(compiler,
101 "_function",
102 compiler.coreLibrary.find,
103 hasBody: true,
104 isPatched: false);
105 }
106
107 main() {
108 testPatchFunction();
109 testPatchMember();
110 testPatchGetter();
111 testInjectFunction();
112 }
OLDNEW
« 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