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

Side by Side Diff: pkg/analyzer/test/file_system/memory_file_system_test.dart

Issue 1811643002: Add File.readAsBytesSync/writeAsBytesSync() methods. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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) 2014, the Dart project authors. Please see the AUTHORS file 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 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 library analyzer.test.file_system.memory_file_system_test; 5 library analyzer.test.file_system.memory_file_system_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:core' hide Resource; 8 import 'dart:core' hide Resource;
9 9
10 import 'package:analyzer/file_system/file_system.dart'; 10 import 'package:analyzer/file_system/file_system.dart';
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } 116 }
117 117
118 void test_parent() { 118 void test_parent() {
119 provider.newFile('/foo/bar/file.txt', 'content'); 119 provider.newFile('/foo/bar/file.txt', 'content');
120 File file = provider.getResource('/foo/bar/file.txt'); 120 File file = provider.getResource('/foo/bar/file.txt');
121 Resource parent = file.parent; 121 Resource parent = file.parent;
122 expect(parent, new isInstanceOf<Folder>()); 122 expect(parent, new isInstanceOf<Folder>());
123 expect(parent.path, equals('/foo/bar')); 123 expect(parent.path, equals('/foo/bar'));
124 } 124 }
125 125
126 void test_readAsBytesSync_doesNotExist() {
127 File file = provider.getResource('/test.bin');
128 expect(() {
129 file.readAsBytesSync();
130 }, throwsA(_isFileSystemException));
131 }
132
133 void test_readAsBytesSync_exists() {
134 List<int> bytes = <int>[1, 2, 3, 4, 5];
135 File file = provider.newFileWithBytes('/file.bin', bytes);
136 expect(file.readAsBytesSync(), bytes);
137 }
138
126 void test_readAsStringSync_doesNotExist() { 139 void test_readAsStringSync_doesNotExist() {
127 File file = provider.getResource('/test.txt'); 140 File file = provider.getResource('/test.txt');
128 expect(() { 141 expect(() {
129 file.readAsStringSync(); 142 file.readAsStringSync();
130 }, throwsA(_isFileSystemException)); 143 }, throwsA(_isFileSystemException));
131 } 144 }
132 145
133 void test_readAsStringSync_exists() { 146 void test_readAsStringSync_exists() {
134 File file = provider.newFile('/file.txt', 'abc'); 147 File file = provider.newFile('/file.txt', 'abc');
135 expect(file.readAsStringSync(), 'abc'); 148 expect(file.readAsStringSync(), 'abc');
136 } 149 }
137 150
138 void test_shortName() { 151 void test_shortName() {
139 File file = provider.getResource('/foo/bar/file.txt'); 152 File file = provider.getResource('/foo/bar/file.txt');
140 expect(file.shortName, 'file.txt'); 153 expect(file.shortName, 'file.txt');
141 } 154 }
142 155
143 void test_toString() { 156 void test_toString() {
144 File file = provider.getResource('/foo/bar/file.txt'); 157 File file = provider.getResource('/foo/bar/file.txt');
145 expect(file.toString(), '/foo/bar/file.txt'); 158 expect(file.toString(), '/foo/bar/file.txt');
146 } 159 }
160
161 void test_writeAsBytesSync() {
162 File file = provider.newFileWithBytes('/file.bin', <int>[1, 2]);
163 expect(file.readAsBytesSync(), <int>[1, 2]);
164 // write new bytes
165 file.writeAsBytesSync(<int>[10, 20]);
166 expect(file.readAsBytesSync(), <int>[10, 20]);
167 }
147 } 168 }
148 169
149 @reflectiveTest 170 @reflectiveTest
150 class FolderTest { 171 class FolderTest {
151 static const String path = '/foo/bar'; 172 static const String path = '/foo/bar';
152 173
153 MemoryResourceProvider provider = new MemoryResourceProvider(); 174 MemoryResourceProvider provider = new MemoryResourceProvider();
154 Folder folder; 175 Folder folder;
155 176
156 void setUp() { 177 void setUp() {
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 String path = '/my/file'; 481 String path = '/my/file';
461 provider.newFile(path, 'contents 1'); 482 provider.newFile(path, 'contents 1');
462 Resource file = provider.getResource(path); 483 Resource file = provider.getResource(path);
463 expect(file, new isInstanceOf<File>()); 484 expect(file, new isInstanceOf<File>());
464 Source source = (file as File).createSource(); 485 Source source = (file as File).createSource();
465 expect(source.contents.data, equals('contents 1')); 486 expect(source.contents.data, equals('contents 1'));
466 provider.modifyFile(path, 'contents 2'); 487 provider.modifyFile(path, 'contents 2');
467 expect(source.contents.data, equals('contents 2')); 488 expect(source.contents.data, equals('contents 2'));
468 } 489 }
469 490
491 void test_newFileWithBytes() {
492 String path = '/my/file';
493 List<int> bytes = <int>[1, 2, 3, 4, 5];
494 provider.newFileWithBytes(path, bytes);
495 File file = provider.getResource(path);
496 expect(file, isNotNull);
497 expect(file.exists, isTrue);
498 expect(file.readAsBytesSync(), bytes);
499 }
500
470 void test_newFolder_aleadyExists_asFile() { 501 void test_newFolder_aleadyExists_asFile() {
471 provider.newFile('/my/file', 'qwerty'); 502 provider.newFile('/my/file', 'qwerty');
472 expect(() { 503 expect(() {
473 provider.newFolder('/my/file'); 504 provider.newFolder('/my/file');
474 }, throwsA(new isInstanceOf<ArgumentError>())); 505 }, throwsA(new isInstanceOf<ArgumentError>()));
475 } 506 }
476 507
477 void test_newFolder_aleadyExists_asFolder() { 508 void test_newFolder_aleadyExists_asFolder() {
478 Folder folder = provider.newFolder('/my/folder'); 509 Folder folder = provider.newFolder('/my/folder');
479 Folder newFolder = provider.newFolder('/my/folder'); 510 Folder newFolder = provider.newFolder('/my/folder');
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 return new Future.delayed(Duration.ZERO, computation); 592 return new Future.delayed(Duration.ZERO, computation);
562 } 593 }
563 594
564 _watchingFolder(String path, test(List<WatchEvent> changesReceived)) { 595 _watchingFolder(String path, test(List<WatchEvent> changesReceived)) {
565 Folder folder = provider.getResource(path); 596 Folder folder = provider.getResource(path);
566 var changesReceived = <WatchEvent>[]; 597 var changesReceived = <WatchEvent>[];
567 folder.changes.listen(changesReceived.add); 598 folder.changes.listen(changesReceived.add);
568 return test(changesReceived); 599 return test(changesReceived);
569 } 600 }
570 } 601 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698