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

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

Issue 2614063007: Use URIs rather than paths in front end API. (Closed)
Patch Set: Minor fixes Created 3 years, 11 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.physical_file_system_test; 6 library front_end.test.physical_file_system_test;
7 7
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:convert'; 9 import 'dart:convert';
10 import 'dart:io' as io; 10 import 'dart:io' as io;
(...skipping 12 matching lines...) Expand all
23 } 23 }
24 24
25 @reflectiveTest 25 @reflectiveTest
26 class FileTest extends _BaseTest { 26 class FileTest extends _BaseTest {
27 String path; 27 String path;
28 FileSystemEntity file; 28 FileSystemEntity file;
29 29
30 setUp() { 30 setUp() {
31 super.setUp(); 31 super.setUp();
32 path = p.join(tempPath, 'file.txt'); 32 path = p.join(tempPath, 'file.txt');
33 file = PhysicalFileSystem.instance.entityForPath(path); 33 file = PhysicalFileSystem.instance.entityForUri(p.toUri(path));
34 } 34 }
35 35
36 test_equals_differentPaths() { 36 test_equals_differentPaths() {
37 expect( 37 expect(file == entityForPath(p.join(tempPath, 'file2.txt')), isFalse);
38 file ==
39 PhysicalFileSystem.instance
40 .entityForPath(p.join(tempPath, 'file2.txt')),
41 isFalse);
42 } 38 }
43 39
44 test_equals_samePath() { 40 test_equals_samePath() {
45 expect( 41 expect(file == entityForPath(p.join(tempPath, 'file.txt')), isTrue);
46 file ==
47 PhysicalFileSystem.instance
48 .entityForPath(p.join(tempPath, 'file.txt')),
49 isTrue);
50 } 42 }
51 43
52 test_hashCode_samePath() { 44 test_hashCode_samePath() {
53 expect( 45 expect(file.hashCode, entityForPath(p.join(tempPath, 'file.txt')).hashCode);
54 file.hashCode,
55 PhysicalFileSystem.instance
56 .entityForPath(p.join(tempPath, 'file.txt'))
57 .hashCode);
58 }
59
60 test_path() {
61 expect(file.path, path);
62 } 46 }
63 47
64 test_readAsBytes_badUtf8() async { 48 test_readAsBytes_badUtf8() async {
65 // A file containing invalid UTF-8 can still be read as raw bytes. 49 // A file containing invalid UTF-8 can still be read as raw bytes.
66 List<int> bytes = [0xc0, 0x40]; // Invalid UTF-8 50 List<int> bytes = [0xc0, 0x40]; // Invalid UTF-8
67 new io.File(path).writeAsBytesSync(bytes); 51 new io.File(path).writeAsBytesSync(bytes);
68 expect(await file.readAsBytes(), bytes); 52 expect(await file.readAsBytes(), bytes);
69 } 53 }
70 54
71 test_readAsBytes_doesNotExist() { 55 test_readAsBytes_doesNotExist() {
(...skipping 19 matching lines...) Expand all
91 var s = 'contents'; 75 var s = 'contents';
92 new io.File(path).writeAsStringSync(s); 76 new io.File(path).writeAsStringSync(s);
93 expect(await file.readAsString(), s); 77 expect(await file.readAsString(), s);
94 } 78 }
95 79
96 test_readAsString_utf8() async { 80 test_readAsString_utf8() async {
97 var bytes = [0xe2, 0x82, 0xac]; // Unicode € symbol (in UTF-8) 81 var bytes = [0xe2, 0x82, 0xac]; // Unicode € symbol (in UTF-8)
98 new io.File(path).writeAsBytesSync(bytes); 82 new io.File(path).writeAsBytesSync(bytes);
99 expect(await file.readAsString(), '\u20ac'); 83 expect(await file.readAsString(), '\u20ac');
100 } 84 }
85
86 test_uri() {
87 expect(file.uri, p.toUri(path));
88 }
101 } 89 }
102 90
103 @reflectiveTest 91 @reflectiveTest
104 class PhysicalFileSystemTest extends _BaseTest { 92 class PhysicalFileSystemTest extends _BaseTest {
105 Uri tempUri; 93 Uri tempUri;
106 94
107 setUp() { 95 setUp() {
108 super.setUp(); 96 super.setUp();
109 tempUri = new Uri.directory(tempPath); 97 tempUri = new Uri.directory(tempPath);
110 } 98 }
111 99
112 test_entityForPath() { 100 test_entityForPath() {
113 var path = p.join(tempPath, 'file.txt'); 101 var path = p.join(tempPath, 'file.txt');
114 expect(PhysicalFileSystem.instance.entityForPath(path).path, path); 102 expect(entityForPath(path).uri, p.toUri(path));
115 } 103 }
116 104
117 test_entityForPath_absolutize() { 105 test_entityForPath_absolutize() {
118 expect(PhysicalFileSystem.instance.entityForPath('file.txt').path, 106 expect(entityForPath('file.txt').uri,
119 new io.File('file.txt').absolute.path); 107 p.toUri(new io.File('file.txt').absolute.path));
120 } 108 }
121 109
122 test_entityForPath_normalize_dot() { 110 test_entityForPath_normalize_dot() {
123 expect( 111 expect(entityForPath(p.join(tempPath, '.', 'file.txt')).uri,
124 PhysicalFileSystem.instance 112 p.toUri(p.join(tempPath, 'file.txt')));
125 .entityForPath(p.join(tempPath, '.', 'file.txt'))
126 .path,
127 p.join(tempPath, 'file.txt'));
128 } 113 }
129 114
130 test_entityForPath_normalize_dotDot() { 115 test_entityForPath_normalize_dotDot() {
131 expect( 116 expect(entityForPath(p.join(tempPath, 'foo', '..', 'file.txt')).uri,
132 PhysicalFileSystem.instance 117 p.toUri(p.join(tempPath, 'file.txt')));
133 .entityForPath(p.join(tempPath, 'foo', '..', 'file.txt'))
134 .path,
135 p.join(tempPath, 'file.txt'));
136 } 118 }
137 119
138 test_entityForUri() { 120 test_entityForUri() {
139 expect( 121 expect(
140 PhysicalFileSystem.instance 122 PhysicalFileSystem.instance
141 .entityForUri(Uri.parse('$tempUri/file.txt')) 123 .entityForUri(Uri.parse('$tempUri/file.txt'))
142 .path, 124 .uri,
143 p.join(tempPath, 'file.txt')); 125 p.toUri(p.join(tempPath, 'file.txt')));
144 } 126 }
145 127
146 test_entityForUri_bareUri_absolute() { 128 test_entityForUri_bareUri_absolute() {
147 expect( 129 expect(PhysicalFileSystem.instance.entityForUri(Uri.parse('/file.txt')).uri,
148 () => PhysicalFileSystem.instance.entityForUri(Uri.parse('/file.txt')), 130 p.toUri(p.fromUri('/file.txt')));
149 throwsA(new isInstanceOf<Error>()));
150 }
151
152 test_entityForUri_bareUri_relative() {
153 expect(
154 () => PhysicalFileSystem.instance.entityForUri(Uri.parse('file.txt')),
155 throwsA(new isInstanceOf<Error>()));
156 } 131 }
157 132
158 test_entityForUri_fileUri_relative() { 133 test_entityForUri_fileUri_relative() {
159 // A weird quirk of the Uri class is that it doesn't seem possible to create 134 // A weird quirk of the Uri class is that it doesn't seem possible to create
160 // a `file:` uri with a relative path, no matter how many slashes you use or 135 // a `file:` uri with a relative path, no matter how many slashes you use or
161 // if you populate the fields directly. But just to be certain, try to do 136 // if you populate the fields directly. But just to be certain, try to do
162 // so, and make that `file:` uris with relative paths are rejected. 137 // so, and make that `file:` uris with relative paths are rejected.
163 for (var uri in <Uri>[ 138 for (var uri in <Uri>[
164 new Uri(scheme: 'file', path: 'file.txt'), 139 new Uri(scheme: 'file', path: 'file.txt'),
165 Uri.parse('file:file.txt'), 140 Uri.parse('file:file.txt'),
(...skipping 12 matching lines...) Expand all
178 expect( 153 expect(
179 () => PhysicalFileSystem.instance 154 () => PhysicalFileSystem.instance
180 .entityForUri(Uri.parse('package:foo/bar.dart')), 155 .entityForUri(Uri.parse('package:foo/bar.dart')),
181 throwsA(new isInstanceOf<Error>())); 156 throwsA(new isInstanceOf<Error>()));
182 } 157 }
183 158
184 test_entityForUri_normalize_dot() { 159 test_entityForUri_normalize_dot() {
185 expect( 160 expect(
186 PhysicalFileSystem.instance 161 PhysicalFileSystem.instance
187 .entityForUri(Uri.parse('$tempUri/./file.txt')) 162 .entityForUri(Uri.parse('$tempUri/./file.txt'))
188 .path, 163 .uri,
189 p.join(tempPath, 'file.txt')); 164 p.toUri(p.join(tempPath, 'file.txt')));
190 } 165 }
191 166
192 test_entityForUri_normalize_dotDot() { 167 test_entityForUri_normalize_dotDot() {
193 expect( 168 expect(
194 PhysicalFileSystem.instance 169 PhysicalFileSystem.instance
195 .entityForUri(Uri.parse('$tempUri/foo/../file.txt')) 170 .entityForUri(Uri.parse('$tempUri/foo/../file.txt'))
196 .path, 171 .uri,
197 p.join(tempPath, 'file.txt')); 172 p.toUri(p.join(tempPath, 'file.txt')));
198 } 173 }
199 } 174 }
200 175
201 class _BaseTest { 176 class _BaseTest {
202 io.Directory tempDirectory; 177 io.Directory tempDirectory;
203 String tempPath; 178 String tempPath;
204 179
180 FileSystemEntity entityForPath(String path) =>
181 PhysicalFileSystem.instance.entityForUri(p.toUri(path));
182
205 setUp() { 183 setUp() {
206 tempDirectory = io.Directory.systemTemp.createTempSync('test_file_system'); 184 tempDirectory = io.Directory.systemTemp.createTempSync('test_file_system');
207 tempPath = tempDirectory.absolute.path; 185 tempPath = tempDirectory.absolute.path;
208 } 186 }
209 187
210 tearDown() async { 188 tearDown() async {
211 try { 189 try {
212 tempDirectory.deleteSync(recursive: true); 190 tempDirectory.deleteSync(recursive: true);
213 } on io.FileSystemException { 191 } on io.FileSystemException {
214 // Sometimes on Windows the delete fails with errno 32 192 // Sometimes on Windows the delete fails with errno 32
215 // (ERROR_SHARING_VIOLATION: The process cannot access the file because it 193 // (ERROR_SHARING_VIOLATION: The process cannot access the file because it
216 // is being used by another process). Wait 1 second and try again. 194 // is being used by another process). Wait 1 second and try again.
217 await new Future.delayed(new Duration(seconds: 1)); 195 await new Future.delayed(new Duration(seconds: 1));
218 tempDirectory.deleteSync(recursive: true); 196 tempDirectory.deleteSync(recursive: true);
219 } 197 }
220 } 198 }
221 } 199 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698