OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 import 'package:front_end/compiler_options.dart'; | 7 import 'package:front_end/compiler_options.dart'; |
8 import 'package:front_end/incremental_kernel_generator.dart'; | 8 import 'package:front_end/incremental_kernel_generator.dart'; |
9 import 'package:front_end/memory_file_system.dart'; | 9 import 'package:front_end/memory_file_system.dart'; |
10 import 'package:kernel/ast.dart'; | 10 import 'package:kernel/ast.dart'; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 import self as self; | 103 import self as self; |
104 import "dart:core" as core; | 104 import "dart:core" as core; |
105 | 105 |
106 static method main() → dynamic { | 106 static method main() → dynamic { |
107 core::double v = 2.3; | 107 core::double v = 2.3; |
108 } | 108 } |
109 '''); | 109 '''); |
110 } | 110 } |
111 } | 111 } |
112 | 112 |
| 113 test_updatePart() async { |
| 114 writeFile('/test/.packages', 'test:lib/'); |
| 115 String libPath = '/test/lib/test.dart'; |
| 116 String partPath = '/test/lib/bar.dart'; |
| 117 Uri libUri = writeFile( |
| 118 libPath, |
| 119 r''' |
| 120 library foo; |
| 121 part 'bar.dart'; |
| 122 var a = 1; |
| 123 var c = b; |
| 124 void main() {} |
| 125 '''); |
| 126 Uri partUri = writeFile( |
| 127 partPath, |
| 128 r''' |
| 129 part of foo; |
| 130 var b = 2; |
| 131 var d = a; |
| 132 '''); |
| 133 |
| 134 // Check the initial state - types flow between the part and the library. |
| 135 Program program = await getInitialState(libUri); |
| 136 Library library = _getLibrary(program, libUri); |
| 137 expect( |
| 138 _getLibraryText(library), |
| 139 r''' |
| 140 library foo; |
| 141 import self as self; |
| 142 import "dart:core" as core; |
| 143 |
| 144 static field core::int a = 1; |
| 145 static field core::int c = self::b; |
| 146 static field core::int b = 2 /* from file:///test/lib/bar.dart */; |
| 147 static field core::int d = self::a /* from file:///test/lib/bar.dart */; |
| 148 static method main() → void {} |
| 149 '''); |
| 150 |
| 151 // Update [b] in the part, the type is changed in the part and library. |
| 152 { |
| 153 writeFile( |
| 154 partPath, |
| 155 r''' |
| 156 part of foo; |
| 157 var b = 2.3; |
| 158 var d = a; |
| 159 '''); |
| 160 incrementalKernelGenerator.invalidate(partUri); |
| 161 DeltaProgram delta = await incrementalKernelGenerator.computeDelta(); |
| 162 Library library = _getLibrary(delta.newProgram, libUri); |
| 163 expect( |
| 164 _getLibraryText(library), |
| 165 r''' |
| 166 library foo; |
| 167 import self as self; |
| 168 import "dart:core" as core; |
| 169 |
| 170 static field core::int a = 1; |
| 171 static field core::double c = self::b; |
| 172 static field core::double b = 2.3 /* from file:///test/lib/bar.dart */; |
| 173 static field core::int d = self::a /* from file:///test/lib/bar.dart */; |
| 174 static method main() → void {} |
| 175 '''); |
| 176 } |
| 177 |
| 178 // Update [a] in the library, the type is changed in the part and library. |
| 179 { |
| 180 writeFile( |
| 181 libPath, |
| 182 r''' |
| 183 library foo; |
| 184 part 'bar.dart'; |
| 185 var a = 'aaa'; |
| 186 var c = b; |
| 187 void main() {} |
| 188 '''); |
| 189 incrementalKernelGenerator.invalidate(libUri); |
| 190 DeltaProgram delta = await incrementalKernelGenerator.computeDelta(); |
| 191 Library library = _getLibrary(delta.newProgram, libUri); |
| 192 expect( |
| 193 _getLibraryText(library), |
| 194 r''' |
| 195 library foo; |
| 196 import self as self; |
| 197 import "dart:core" as core; |
| 198 |
| 199 static field core::String a = "aaa"; |
| 200 static field core::double c = self::b; |
| 201 static field core::double b = 2.3 /* from file:///test/lib/bar.dart */; |
| 202 static field core::String d = self::a /* from file:///test/lib/bar.dart */; |
| 203 static method main() → void {} |
| 204 '''); |
| 205 } |
| 206 } |
| 207 |
113 /// Write the given [text] of the file with the given [path] into the | 208 /// Write the given [text] of the file with the given [path] into the |
114 /// virtual filesystem. Return the URI of the file. | 209 /// virtual filesystem. Return the URI of the file. |
115 Uri writeFile(String path, String text) { | 210 Uri writeFile(String path, String text) { |
116 Uri uri = Uri.parse('file://$path'); | 211 Uri uri = Uri.parse('file://$path'); |
117 fileSystem.entityForUri(uri).writeAsStringSync(text); | 212 fileSystem.entityForUri(uri).writeAsStringSync(text); |
118 return uri; | 213 return uri; |
119 } | 214 } |
120 | 215 |
121 // test_part() async { | |
122 // writeFiles({ | |
123 // '/foo.dart': 'library foo; part "bar.dart"; main() { print(1); f(); }', | |
124 // '/bar.dart': 'part of foo; f() { print(2); }' | |
125 // }); | |
126 // var fooUri = Uri.parse('file:///foo.dart'); | |
127 // var initialState = await getInitialState(fooUri); | |
128 // expect(initialState.keys, unorderedEquals([fooUri])); | |
129 // var library = _getLibrary(initialState[fooUri], fooUri); | |
130 // var mainStatements = | |
131 // _getProcedureStatements(_getProcedure(library, 'main')); | |
132 // var fProcedure = _getProcedure(library, 'f'); | |
133 // var fStatements = _getProcedureStatements(fProcedure); | |
134 // expect(mainStatements, hasLength(2)); | |
135 // _checkPrintLiteralInt(mainStatements[0], 1); | |
136 // _checkFunctionCall(mainStatements[1], fProcedure); | |
137 // expect(fStatements, hasLength(1)); | |
138 // _checkPrintLiteralInt(fStatements[0], 2); | |
139 // TODO(paulberry): now test incremental updates | |
140 // } | |
141 | |
142 /// Write the given file contents to the virtual filesystem. | 216 /// Write the given file contents to the virtual filesystem. |
143 void writeFiles(Map<String, String> contents) { | 217 void writeFiles(Map<String, String> contents) { |
144 contents.forEach(writeFile); | 218 contents.forEach(writeFile); |
145 } | 219 } |
146 | 220 |
147 Library _getLibrary(Program program, Uri uri) { | 221 Library _getLibrary(Program program, Uri uri) { |
148 for (var library in program.libraries) { | 222 for (var library in program.libraries) { |
149 if (library.importUri == uri) return library; | 223 if (library.importUri == uri) return library; |
150 } | 224 } |
151 throw fail('No library found with URI "$uri"'); | 225 throw fail('No library found with URI "$uri"'); |
152 } | 226 } |
153 | 227 |
154 String _getLibraryText(Library library) { | 228 String _getLibraryText(Library library) { |
155 StringBuffer buffer = new StringBuffer(); | 229 StringBuffer buffer = new StringBuffer(); |
156 new Printer(buffer, syntheticNames: new NameSystem()) | 230 new Printer(buffer, syntheticNames: new NameSystem()) |
157 .writeLibraryFile(library); | 231 .writeLibraryFile(library); |
158 return buffer.toString(); | 232 return buffer.toString(); |
159 } | 233 } |
160 } | 234 } |
OLD | NEW |