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

Side by Side Diff: pkg/front_end/test/memory_file_system_test.dart

Issue 2850533004: Revert "Extend file-system abstraction with a couple methods, remove context." (Closed)
Patch Set: Created 3 years, 7 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
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 // SharedOptions=--supermixin 4 // SharedOptions=--supermixin
5 5
6 library front_end.test.memory_file_system_test; 6 library front_end.test.memory_file_system_test;
7 7
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:io' as io; 9 import 'dart:io' as io;
10 10
(...skipping 28 matching lines...) Expand all
39 39
40 test_equals_samePath() { 40 test_equals_samePath() {
41 expect(file == entityForPath(join(tempPath, 'file.txt')), isTrue); 41 expect(file == entityForPath(join(tempPath, 'file.txt')), isTrue);
42 } 42 }
43 43
44 test_hashCode_samePath() { 44 test_hashCode_samePath() {
45 expect(file.hashCode, entityForPath(join(tempPath, 'file.txt')).hashCode); 45 expect(file.hashCode, entityForPath(join(tempPath, 'file.txt')).hashCode);
46 } 46 }
47 47
48 test_path() { 48 test_path() {
49 expect(file.uri, context.toUri(path)); 49 expect(file.uri, fileSystem.context.toUri(path));
50 } 50 }
51 51
52 test_readAsBytes_badUtf8() async { 52 test_readAsBytes_badUtf8() async {
53 // A file containing invalid UTF-8 can still be read as raw bytes. 53 // A file containing invalid UTF-8 can still be read as raw bytes.
54 List<int> bytes = [0xc0, 0x40]; // Invalid UTF-8 54 List<int> bytes = [0xc0, 0x40]; // Invalid UTF-8
55 file.writeAsBytesSync(bytes); 55 file.writeAsBytesSync(bytes);
56 expect(await file.readAsBytes(), bytes); 56 expect(await file.readAsBytes(), bytes);
57 } 57 }
58 58
59 test_readAsBytes_doesNotExist() { 59 test_readAsBytes_doesNotExist() {
(...skipping 19 matching lines...) Expand all
79 var s = 'contents'; 79 var s = 'contents';
80 file.writeAsStringSync(s); 80 file.writeAsStringSync(s);
81 expect(await file.readAsString(), s); 81 expect(await file.readAsString(), s);
82 } 82 }
83 83
84 test_readAsString_utf8() async { 84 test_readAsString_utf8() async {
85 file.writeAsBytesSync([0xe2, 0x82, 0xac]); // Unicode € symbol, in UTF-8 85 file.writeAsBytesSync([0xe2, 0x82, 0xac]); // Unicode € symbol, in UTF-8
86 expect(await file.readAsString(), '\u20ac'); 86 expect(await file.readAsString(), '\u20ac');
87 } 87 }
88 88
89 test_exists_doesNotExist() async {
90 expect(await file.exists(), false);
91 }
92
93 test_exists_exists() async {
94 file.writeAsStringSync('x');
95 expect(await file.exists(), true);
96 }
97
98 test_lastModified_doesNotExist() async {
99 expect(file.lastModified(), throwsException);
100 }
101
102 test_lastModified_increasesOnEachChange() async {
103 file.writeAsStringSync('x');
104 var mod1 = await file.lastModified();
105 file.writeAsStringSync('y');
106 var mod2 = await file.lastModified();
107 expect(mod2.isAfter(mod1), isTrue);
108
109 var file2 = entityForPath(join(tempPath, 'file2.txt'));
110 file2.writeAsStringSync('z');
111 var mod3 = await file2.lastModified();
112 expect(mod3.isAfter(mod2), isTrue);
113 }
114
115 test_writeAsBytesSync_modifyAfterRead() async { 89 test_writeAsBytesSync_modifyAfterRead() async {
116 file.writeAsBytesSync([1]); 90 file.writeAsBytesSync([1]);
117 (await file.readAsBytes())[0] = 2; 91 (await file.readAsBytes())[0] = 2;
118 expect(await file.readAsBytes(), [1]); 92 expect(await file.readAsBytes(), [1]);
119 } 93 }
120 94
121 test_writeAsBytesSync_modifyAfterWrite() async { 95 test_writeAsBytesSync_modifyAfterWrite() async {
122 var bytes = [1]; 96 var bytes = [1];
123 file.writeAsBytesSync(bytes); 97 file.writeAsBytesSync(bytes);
124 bytes[0] = 2; 98 bytes[0] = 2;
(...skipping 16 matching lines...) Expand all
141 file.writeAsStringSync('\u20ac'); // Unicode € symbol 115 file.writeAsStringSync('\u20ac'); // Unicode € symbol
142 expect(await file.readAsBytes(), [0xe2, 0x82, 0xac]); 116 expect(await file.readAsBytes(), [0xe2, 0x82, 0xac]);
143 } 117 }
144 } 118 }
145 119
146 abstract class MemoryFileSystemTestMixin extends _BaseTest { 120 abstract class MemoryFileSystemTestMixin extends _BaseTest {
147 Uri tempUri; 121 Uri tempUri;
148 122
149 setUp() { 123 setUp() {
150 super.setUp(); 124 super.setUp();
151 tempUri = context.toUri(tempPath); 125 tempUri = fileSystem.context.toUri(tempPath);
152 } 126 }
153 127
154 test_currentDirectory_trailingSlash() { 128 test_currentDirectory_trailingSlash() {
155 // The currentDirectory should already end in a trailing slash. 129 // The currentDirectory should already end in a trailing slash.
156 expect(fileSystem.currentDirectory.path, endsWith('/')); 130 expect(fileSystem.currentDirectory.path, endsWith('/'));
157 // A trailing slash should automatically be appended when creating a 131 // A trailing slash should automatically be appended when creating a
158 // MemoryFileSystem. 132 // MemoryFileSystem.
159 var path = fileSystem.currentDirectory.path; 133 var path = fileSystem.currentDirectory.path;
160 var currentDirectoryWithoutSlash = fileSystem.currentDirectory 134 var currentDirectoryWithoutSlash = fileSystem.currentDirectory
161 .replace(path: path.substring(0, path.length - 1)); 135 .replace(path: path.substring(0, path.length - 1));
162 expect(new MemoryFileSystem(currentDirectoryWithoutSlash).currentDirectory, 136 expect(
137 new MemoryFileSystem(fileSystem.context, currentDirectoryWithoutSlash)
138 .currentDirectory,
163 fileSystem.currentDirectory); 139 fileSystem.currentDirectory);
164 // If the currentDirectory supplied to the MemoryFileSystem constructor 140 // If the currentDirectory supplied to the MemoryFileSystem constructor
165 // already has a trailing slash, no further trailing slash should be added. 141 // already has a trailing slash, no further trailing slash should be added.
166 expect(new MemoryFileSystem(fileSystem.currentDirectory).currentDirectory, 142 expect(
143 new MemoryFileSystem(fileSystem.context, fileSystem.currentDirectory)
144 .currentDirectory,
167 fileSystem.currentDirectory); 145 fileSystem.currentDirectory);
168 } 146 }
169 147
170 test_entityForPath_absolutize() { 148 test_entityForPath_absolutize() {
171 expect(entityForPath('file.txt').uri, 149 expect(entityForPath('file.txt').uri,
172 fileSystem.currentDirectory.resolve('file.txt')); 150 fileSystem.currentDirectory.resolve('file.txt'));
173 } 151 }
174 152
175 test_entityForPath_normalize_dot() { 153 test_entityForPath_normalize_dot() {
176 expect(entityForPath(join(tempPath, '.', 'file.txt')).uri, 154 expect(entityForPath(join(tempPath, '.', 'file.txt')).uri,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 206
229 @reflectiveTest 207 @reflectiveTest
230 class MemoryFileSystemTestPosix extends _BaseTestPosix 208 class MemoryFileSystemTestPosix extends _BaseTestPosix
231 with MemoryFileSystemTestMixin {} 209 with MemoryFileSystemTestMixin {}
232 210
233 @reflectiveTest 211 @reflectiveTest
234 class MemoryFileSystemTestWindows extends _BaseTestWindows 212 class MemoryFileSystemTestWindows extends _BaseTestWindows
235 with MemoryFileSystemTestMixin {} 213 with MemoryFileSystemTestMixin {}
236 214
237 abstract class _BaseTest { 215 abstract class _BaseTest {
238 pathos.Context get context;
239 MemoryFileSystem get fileSystem; 216 MemoryFileSystem get fileSystem;
240 217
241 String get tempPath; 218 String get tempPath;
242 219
243 MemoryFileSystemEntity entityForPath(String path) => 220 MemoryFileSystemEntity entityForPath(String path) =>
244 fileSystem.entityForUri(context.toUri(path)); 221 fileSystem.entityForUri(fileSystem.context.toUri(path));
245 222
246 String join(String path1, String path2, [String path3, String path4]); 223 String join(String path1, String path2, [String path3, String path4]);
247 224
248 void setUp(); 225 void setUp();
249 } 226 }
250 227
251 class _BaseTestNative extends _BaseTest { 228 class _BaseTestNative extends _BaseTest {
252 final pathos.Context context = pathos.context;
253 MemoryFileSystem fileSystem; 229 MemoryFileSystem fileSystem;
254 String tempPath; 230 String tempPath;
255 231
256 String join(String path1, String path2, [String path3, String path4]) => 232 String join(String path1, String path2, [String path3, String path4]) =>
257 pathos.join(path1, path2, path3, path4); 233 pathos.join(path1, path2, path3, path4);
258 234
259 setUp() { 235 setUp() {
260 tempPath = pathos.join(io.Directory.systemTemp.path, 'test_file_system'); 236 tempPath = pathos.join(io.Directory.systemTemp.path, 'test_file_system');
261 fileSystem = new MemoryFileSystem(pathos.toUri(io.Directory.current.path)); 237 fileSystem = new MemoryFileSystem(
238 pathos.context, pathos.toUri(io.Directory.current.path));
262 } 239 }
263 } 240 }
264 241
265 class _BaseTestPosix extends _BaseTest { 242 class _BaseTestPosix extends _BaseTest {
266 final pathos.Context context = pathos.posix;
267 MemoryFileSystem fileSystem; 243 MemoryFileSystem fileSystem;
268 String tempPath; 244 String tempPath;
269 245
270 String join(String path1, String path2, [String path3, String path4]) => 246 String join(String path1, String path2, [String path3, String path4]) =>
271 pathos.posix.join(path1, path2, path3, path4); 247 pathos.posix.join(path1, path2, path3, path4);
272 248
273 void setUp() { 249 void setUp() {
274 tempPath = '/test_file_system'; 250 tempPath = '/test_file_system';
275 fileSystem = new MemoryFileSystem(Uri.parse('file:///cwd')); 251 fileSystem = new MemoryFileSystem(pathos.posix, Uri.parse('file:///cwd'));
276 } 252 }
277 } 253 }
278 254
279 class _BaseTestWindows extends _BaseTest { 255 class _BaseTestWindows extends _BaseTest {
280 final pathos.Context context = pathos.windows;
281 MemoryFileSystem fileSystem; 256 MemoryFileSystem fileSystem;
282 String tempPath; 257 String tempPath;
283 258
284 String join(String path1, String path2, [String path3, String path4]) => 259 String join(String path1, String path2, [String path3, String path4]) =>
285 pathos.windows.join(path1, path2, path3, path4); 260 pathos.windows.join(path1, path2, path3, path4);
286 261
287 void setUp() { 262 void setUp() {
288 tempPath = r'c:\test_file_system'; 263 tempPath = r'c:\test_file_system';
289 fileSystem = new MemoryFileSystem(Uri.parse('file:///c:/cwd')); 264 fileSystem =
265 new MemoryFileSystem(pathos.windows, Uri.parse('file:///c:/cwd'));
290 } 266 }
291 } 267 }
OLDNEW
« no previous file with comments | « pkg/front_end/test/incremental_resolved_ast_generator_test.dart ('k') | pkg/front_end/test/physical_file_system_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698