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

Side by Side Diff: tests/try/poi/library_updater_test.dart

Issue 2232273004: Delete site/try (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 // Test of LibraryUpdater (one compilation unit per library).
6 library trydart.library_updater_test;
7
8 import 'package:dart2js_incremental/library_updater.dart' show
9 IncrementalCompilerContext,
10 LibraryUpdater,
11 Update;
12
13 import 'package:compiler/src/script.dart' show
14 Script;
15
16 import 'package:compiler/src/io/source_file.dart' show
17 StringSourceFile;
18
19 import 'compiler_test_case.dart';
20
21 void nolog(_) {}
22
23 Script newScriptFrom(LibraryElement library, String newSource) {
24 Script script = library.entryCompilationUnit.script;
25 return script.copyWithFile(
26 new StringSourceFile.fromUri(script.file.uri, newSource));
27 }
28
29 class LibraryUpdaterTestCase extends CompilerTestCase {
30 final String newSource;
31
32 final bool expectedCanReuse;
33
34 final List<String> expectedUpdates;
35
36 LibraryUpdaterTestCase(
37 {String before,
38 String after,
39 bool canReuse,
40 List<String> updates})
41 : this.newSource = after,
42 this.expectedCanReuse = canReuse,
43 this.expectedUpdates = updates,
44 super(before);
45
46 Future run() => loadMainApp().then((LibraryElement library) {
47 var context = new IncrementalCompilerContext();
48 LibraryUpdater updater =
49 new LibraryUpdater(this.compiler, null, nolog, nolog, context);
50 context.registerUriWithUpdates([scriptUri]);
51 bool actualCanReuse =
52 updater.canReuseLibrary(
53 library, <Script>[newScriptFrom(library, newSource)]);
54 Expect.equals(expectedCanReuse, actualCanReuse);
55
56 Expect.setEquals(
57 expectedUpdates.toSet(),
58 updater.updates.map(nameOfUpdate).toSet());
59 });
60
61 String toString() => 'Before:\n$source\n\n\nAfter:\n$newSource';
62 }
63
64 String nameOfUpdate(Update update) {
65 var element = update.before;
66 if (element == null) element = update.after;
67 return element.name;
68 }
69
70 void main() {
71 runTests(
72 [
73 // Only method body changed. Can be reused if 'main' is
74 // updated/patched.
75 new LibraryUpdaterTestCase(
76 before: 'main() { print("Hello, World!"); }',
77 after: 'main() { print("Hello, Brave New World!"); }',
78 canReuse: true,
79 updates: ['main']),
80
81 // Signature changed. Can't be reused.
82 new LibraryUpdaterTestCase(
83 before: 'main() { print("Hello, World!"); }',
84 after: 'void main() { print("Hello, World!"); }',
85 canReuse: true,
86 updates: ['main']),
87
88 // Only whitespace changes. Can be reused; no updates/patches needed.
89 new LibraryUpdaterTestCase(
90 before: 'main(){print("Hello, World!");}',
91 after: 'main() { print ( "Hello, World!" ) ; }',
92 canReuse: true,
93 updates: []),
94
95 // Only whitespace/comment changes (in signature). Can be reused; no
96 // updates/patches needed.
97 new LibraryUpdaterTestCase(
98 before:
99 '/* Implicitly dynamic. */ main ( /* No parameters. */ ) '
100 '{print("Hello, World!");}',
101 after: 'main() {print("Hello, World!");}',
102 canReuse: true,
103 updates: []),
104
105 // Arrow function changed to method body. Can be reused if 'main' is
106 // updated/patched.
107 new LibraryUpdaterTestCase(
108 before: 'main() => null',
109 after: 'main() { return null; }',
110 canReuse: true,
111 updates: ['main']),
112
113 // Empty body changed to contain a statement. Can be reused if 'main'
114 // is updated/patched.
115 new LibraryUpdaterTestCase(
116 before: 'main() {}',
117 after: 'main() { return null; }',
118 canReuse: true,
119 updates: ['main']),
120
121 // Empty body changed to arrow. Can be reused if 'main'
122 // is updated/patched.
123 new LibraryUpdaterTestCase(
124 before: 'main() {}',
125 after: 'main() => null;',
126 canReuse: true,
127 updates: ['main']),
128
129 // Arrow changed to empty body. Can be reused if 'main'
130 // is updated/patched.
131 new LibraryUpdaterTestCase(
132 before: 'main() => null;',
133 after: 'main() {}',
134 canReuse: true,
135 updates: ['main']),
136
137 // TODO(ahe): When supporting class members, test abstract methods.
138 ]
139 );
140 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698