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

Side by Side Diff: pkg/analyzer/test/file_system/physical_resource_provider_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
« no previous file with comments | « pkg/analyzer/test/file_system/memory_file_system_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.physical_resource_provider_test; 5 library analyzer.test.file_system.physical_resource_provider_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:core' hide Resource; 8 import 'dart:core' hide Resource;
9 import 'dart:io' as io; 9 import 'dart:io' as io;
10 10
11 import 'package:analyzer/file_system/file_system.dart'; 11 import 'package:analyzer/file_system/file_system.dart';
12 import 'package:analyzer/file_system/physical_file_system.dart'; 12 import 'package:analyzer/file_system/physical_file_system.dart';
13 import 'package:analyzer/src/generated/source_io.dart'; 13 import 'package:analyzer/src/generated/source_io.dart';
14 import 'package:path/path.dart'; 14 import 'package:path/path.dart';
15 import 'package:unittest/unittest.dart'; 15 import 'package:unittest/unittest.dart';
16 import 'package:watcher/watcher.dart'; 16 import 'package:watcher/watcher.dart';
17 17
18 import '../reflective_tests.dart'; 18 import '../reflective_tests.dart';
19 import '../utils.dart'; 19 import '../utils.dart';
20 20
21 main() { 21 main() {
22 initializeTestEnvironment(); 22 initializeTestEnvironment();
23 runReflectiveTests(PhysicalResourceProviderTest); 23 if (!new bool.fromEnvironment('skipPhysicalResourceProviderTests')) {
24 runReflectiveTests(FileTest); 24 runReflectiveTests(PhysicalResourceProviderTest);
25 runReflectiveTests(FolderTest); 25 runReflectiveTests(FileTest);
26 runReflectiveTests(FolderTest);
27 }
26 } 28 }
27 29
28 var _isFile = new isInstanceOf<File>(); 30 var _isFile = new isInstanceOf<File>();
29 var _isFileSystemException = new isInstanceOf<FileSystemException>(); 31 var _isFileSystemException = new isInstanceOf<FileSystemException>();
30 var _isFolder = new isInstanceOf<Folder>(); 32 var _isFolder = new isInstanceOf<Folder>();
31 33
32 @reflectiveTest 34 @reflectiveTest
33 class FileTest extends _BaseTest { 35 class FileTest extends _BaseTest {
34 String path; 36 String path;
35 File file; 37 File file;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 File file = PhysicalResourceProvider.INSTANCE.getResource(path); 99 File file = PhysicalResourceProvider.INSTANCE.getResource(path);
98 expect(file.modificationStamp, isNonNegative); 100 expect(file.modificationStamp, isNonNegative);
99 } 101 }
100 102
101 void test_parent() { 103 void test_parent() {
102 Resource parent = file.parent; 104 Resource parent = file.parent;
103 expect(parent, new isInstanceOf<Folder>()); 105 expect(parent, new isInstanceOf<Folder>());
104 expect(parent.path, equals(tempPath)); 106 expect(parent.path, equals(tempPath));
105 } 107 }
106 108
109 void test_readAsBytesSync_doesNotExist() {
110 File file = PhysicalResourceProvider.INSTANCE.getResource('/test.bin');
111 expect(() {
112 file.readAsBytesSync();
113 }, throwsA(_isFileSystemException));
114 }
115
116 void test_readAsBytesSync_exists() {
117 List<int> bytes = <int>[1, 2, 3, 4, 5];
118 new io.File(path).writeAsBytesSync(bytes);
119 expect(file.readAsBytesSync(), bytes);
120 }
121
107 void test_readAsStringSync_doesNotExist() { 122 void test_readAsStringSync_doesNotExist() {
108 File file = PhysicalResourceProvider.INSTANCE.getResource(path); 123 File file = PhysicalResourceProvider.INSTANCE.getResource(path);
109 expect(() { 124 expect(() {
110 file.readAsStringSync(); 125 file.readAsStringSync();
111 }, throwsA(_isFileSystemException)); 126 }, throwsA(_isFileSystemException));
112 } 127 }
113 128
114 void test_readAsStringSync_exists() { 129 void test_readAsStringSync_exists() {
115 new io.File(path).writeAsStringSync('abc'); 130 new io.File(path).writeAsStringSync('abc');
116 File file = PhysicalResourceProvider.INSTANCE.getResource(path); 131 File file = PhysicalResourceProvider.INSTANCE.getResource(path);
117 expect(file.readAsStringSync(), 'abc'); 132 expect(file.readAsStringSync(), 'abc');
118 } 133 }
119 134
120 void test_shortName() { 135 void test_shortName() {
121 expect(file.shortName, 'file.txt'); 136 expect(file.shortName, 'file.txt');
122 } 137 }
123 138
124 void test_toString() { 139 void test_toString() {
125 expect(file.toString(), path); 140 expect(file.toString(), path);
126 } 141 }
142
143 void test_writeAsBytesSync() {
144 new io.File(path).writeAsBytesSync(<int>[1, 2]);
145 expect(file.readAsBytesSync(), <int>[1, 2]);
146 // write new bytes
147 file.writeAsBytesSync(<int>[10, 20]);
148 expect(file.readAsBytesSync(), <int>[10, 20]);
149 }
127 } 150 }
128 151
129 @reflectiveTest 152 @reflectiveTest
130 class FolderTest extends _BaseTest { 153 class FolderTest extends _BaseTest {
131 String path; 154 String path;
132 Folder folder; 155 Folder folder;
133 156
134 setUp() { 157 setUp() {
135 super.setUp(); 158 super.setUp();
136 path = join(tempPath, 'folder'); 159 path = join(tempPath, 'folder');
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 466
444 setUp() { 467 setUp() {
445 tempDirectory = io.Directory.systemTemp.createTempSync('test_resource'); 468 tempDirectory = io.Directory.systemTemp.createTempSync('test_resource');
446 tempPath = tempDirectory.absolute.path; 469 tempPath = tempDirectory.absolute.path;
447 } 470 }
448 471
449 tearDown() { 472 tearDown() {
450 tempDirectory.deleteSync(recursive: true); 473 tempDirectory.deleteSync(recursive: true);
451 } 474 }
452 } 475 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/file_system/memory_file_system_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698