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

Unified Diff: packages/analyzer/test/file_system/memory_file_system_test.dart

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: packages/analyzer/test/file_system/memory_file_system_test.dart
diff --git a/packages/analyzer/test/file_system/memory_file_system_test.dart b/packages/analyzer/test/file_system/memory_file_system_test.dart
index d0d3e5573f87f201b6cfbf26e8300fe27666ebab..37e985b5a6ab8ff7fcabad05e2f3271097449d19 100644
--- a/packages/analyzer/test/file_system/memory_file_system_test.dart
+++ b/packages/analyzer/test/file_system/memory_file_system_test.dart
@@ -2,30 +2,31 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-library test.memory_file_system;
+library analyzer.test.file_system.memory_file_system_test;
import 'dart:async';
-import 'dart:core' hide Resource;
+import 'dart:core';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/file_system/memory_file_system.dart';
import 'package:analyzer/src/generated/engine.dart' show TimestampedData;
import 'package:analyzer/src/generated/source.dart';
-import 'package:path/path.dart';
+import 'package:analyzer/src/generated/utilities_dart.dart';
+import 'package:path/path.dart' hide equals;
+import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'package:unittest/unittest.dart';
import 'package:watcher/watcher.dart';
-import '../reflective_tests.dart';
import '../utils.dart';
main() {
initializeTestEnvironment();
- runReflectiveTests(FileSystemExceptionTest);
- runReflectiveTests(FileTest);
- runReflectiveTests(FolderTest);
- runReflectiveTests(MemoryFileSourceExistingTest);
- runReflectiveTests(MemoryFileSourceNotExistingTest);
- runReflectiveTests(MemoryResourceProviderTest);
+ defineReflectiveTests(FileSystemExceptionTest);
+ defineReflectiveTests(FileTest);
+ defineReflectiveTests(FolderTest);
+ defineReflectiveTests(MemoryFileSourceExistingTest);
+ defineReflectiveTests(MemoryFileSourceNotExistingTest);
+ defineReflectiveTests(MemoryResourceProviderTest);
}
var _isFile = new isInstanceOf<File>();
@@ -47,8 +48,17 @@ class FileSystemExceptionTest {
class FileTest {
MemoryResourceProvider provider = new MemoryResourceProvider();
+ void test_delete() {
+ File file =
+ provider.newFile(provider.convertPath('/foo/file.txt'), 'content');
+ expect(file.exists, isTrue);
+ // delete
+ file.delete();
+ expect(file.exists, isFalse);
+ }
+
void test_equals_beforeAndAfterCreate() {
- String path = '/file.txt';
+ String path = provider.convertPath('/file.txt');
File file1 = provider.getResource(path);
provider.newFile(path, 'contents');
File file2 = provider.getResource(path);
@@ -56,37 +66,39 @@ class FileTest {
}
void test_equals_false() {
- File fileA = provider.getResource('/fileA.txt');
- File fileB = provider.getResource('/fileB.txt');
+ File fileA = provider.getResource(provider.convertPath('/fileA.txt'));
+ File fileB = provider.getResource(provider.convertPath('/fileB.txt'));
expect(fileA == new Object(), isFalse);
expect(fileA == fileB, isFalse);
}
void test_equals_true() {
- File file = provider.getResource('/file.txt');
+ File file = provider.getResource(provider.convertPath('/file.txt'));
expect(file == file, isTrue);
}
void test_exists_false() {
- File file = provider.getResource('/file.txt');
+ File file = provider.getResource(provider.convertPath('/file.txt'));
expect(file, isNotNull);
expect(file.exists, isFalse);
}
void test_exists_true() {
- provider.newFile('/foo/file.txt', 'qwerty');
- File file = provider.getResource('/foo/file.txt');
+ String path = provider.convertPath('/foo/file.txt');
+ provider.newFile(path, 'qwerty');
+ File file = provider.getResource(path);
expect(file, isNotNull);
expect(file.exists, isTrue);
}
void test_fullName() {
- File file = provider.getResource('/foo/bar/file.txt');
- expect(file.path, '/foo/bar/file.txt');
+ String path = provider.convertPath('/foo/bar/file.txt');
+ File file = provider.getResource(path);
+ expect(file.path, path);
}
void test_hashCode() {
- String path = '/foo/bar/file.txt';
+ String path = provider.convertPath('/foo/bar/file.txt');
File file1 = provider.getResource(path);
provider.newFile(path, 'contents');
File file2 = provider.getResource(path);
@@ -94,14 +106,14 @@ class FileTest {
}
void test_isOrContains() {
- String path = '/foo/bar/file.txt';
+ String path = provider.convertPath('/foo/bar/file.txt');
File file = provider.getResource(path);
expect(file.isOrContains(path), isTrue);
- expect(file.isOrContains('/foo/bar'), isFalse);
+ expect(file.isOrContains(provider.convertPath('/foo/bar')), isFalse);
}
void test_modificationStamp_doesNotExist() {
- String path = '/foo/bar/file.txt';
+ String path = provider.convertPath('/foo/bar/file.txt');
File file = provider.newFile(path, 'qwerty');
provider.deleteFile(path);
expect(() {
@@ -110,71 +122,201 @@ class FileTest {
}
void test_modificationStamp_exists() {
- String path = '/foo/bar/file.txt';
+ String path = provider.convertPath('/foo/bar/file.txt');
File file = provider.newFile(path, 'qwerty');
expect(file.modificationStamp, isNonNegative);
}
void test_parent() {
- provider.newFile('/foo/bar/file.txt', 'content');
- File file = provider.getResource('/foo/bar/file.txt');
+ String path = provider.convertPath('/foo/bar/file.txt');
+ provider.newFile(path, 'content');
+ File file = provider.getResource(path);
Resource parent = file.parent;
expect(parent, new isInstanceOf<Folder>());
- expect(parent.path, equals('/foo/bar'));
+ expect(parent.path, equals(provider.convertPath('/foo/bar')));
+ }
+
+ void test_readAsBytesSync_doesNotExist() {
+ File file = provider.getResource(provider.convertPath('/test.bin'));
+ expect(() {
+ file.readAsBytesSync();
+ }, throwsA(_isFileSystemException));
+ }
+
+ void test_readAsBytesSync_exists() {
+ List<int> bytes = <int>[1, 2, 3, 4, 5];
+ File file =
+ provider.newFileWithBytes(provider.convertPath('/file.bin'), bytes);
+ expect(file.readAsBytesSync(), bytes);
}
void test_readAsStringSync_doesNotExist() {
- File file = provider.getResource('/test.txt');
+ File file = provider.getResource(provider.convertPath('/test.txt'));
expect(() {
file.readAsStringSync();
}, throwsA(_isFileSystemException));
}
void test_readAsStringSync_exists() {
- File file = provider.newFile('/file.txt', 'abc');
+ File file = provider.newFile(provider.convertPath('/file.txt'), 'abc');
expect(file.readAsStringSync(), 'abc');
}
+ void test_renameSync_newDoesNotExist() {
+ String oldPath = provider.convertPath('/foo/bar/file.txt');
+ String newPath = provider.convertPath('/foo/bar/new-file.txt');
+ File file = provider.newFile(oldPath, 'text');
+ File newFile = file.renameSync(newPath);
+ expect(file.path, oldPath);
+ expect(file.exists, isFalse);
+ expect(newFile.path, newPath);
+ expect(newFile.exists, isTrue);
+ expect(newFile.readAsStringSync(), 'text');
+ }
+
+ void test_renameSync_newExists_file() {
+ String oldPath = provider.convertPath('/foo/bar/file.txt');
+ String newPath = provider.convertPath('/foo/bar/new-file.txt');
+ File file = provider.newFile(oldPath, 'text');
+ provider.newFile(newPath, 'new text');
+ File newFile = file.renameSync(newPath);
+ expect(file.path, oldPath);
+ expect(file.exists, isFalse);
+ expect(newFile.path, newPath);
+ expect(newFile.exists, isTrue);
+ expect(newFile.readAsStringSync(), 'text');
+ }
+
+ void test_renameSync_newExists_folder() {
+ String oldPath = provider.convertPath('/foo/bar/file.txt');
+ String newPath = provider.convertPath('/foo/bar/baz');
+ File file = provider.newFile(oldPath, 'text');
+ provider.newFolder(newPath);
+ expect(() {
+ file.renameSync(newPath);
+ }, throwsA(_isFileSystemException));
+ expect(file.path, oldPath);
+ expect(file.exists, isTrue);
+ }
+
+ void test_resolveSymbolicLinksSync() {
+ File file = provider.newFile(provider.convertPath('/test.txt'), 'text');
+ expect(file.resolveSymbolicLinksSync(), file);
+ }
+
void test_shortName() {
- File file = provider.getResource('/foo/bar/file.txt');
+ File file = provider.getResource(provider.convertPath('/foo/bar/file.txt'));
expect(file.shortName, 'file.txt');
}
void test_toString() {
- File file = provider.getResource('/foo/bar/file.txt');
- expect(file.toString(), '/foo/bar/file.txt');
+ String path = provider.convertPath('/foo/bar/file.txt');
+ File file = provider.getResource(path);
+ expect(file.toString(), path);
+ }
+
+ void test_toUri() {
+ String path = provider.convertPath('/foo/file.txt');
+ File file = provider.newFile(path, '');
+ expect(file.toUri(), provider.pathContext.toUri(path));
+ }
+
+ void test_writeAsBytesSync_existing() {
+ List<int> content = <int>[1, 2];
+ File file = provider.newFileWithBytes(
+ provider.convertPath('/foo/file.bin'), content);
+ expect(file.readAsBytesSync(), content);
+ // write new bytes
+ content = <int>[10, 20];
+ file.writeAsBytesSync(content);
+ expect(file.readAsBytesSync(), content);
+ }
+
+ void test_writeAsBytesSync_new() {
+ File file = provider.getFile(provider.convertPath('/foo/file.bin'));
+ expect(file.exists, false);
+ // write new bytes
+ List<int> content = <int>[10, 20];
+ file.writeAsBytesSync(content);
+ expect(file.exists, true);
+ expect(file.readAsBytesSync(), content);
+ }
+
+ void test_writeAsStringSync_existing() {
+ String content = 'ab';
+ File file =
+ provider.newFile(provider.convertPath('/foo/file.txt'), content);
+ expect(file.readAsStringSync(), content);
+ // write new bytes
+ content = 'CD';
+ file.writeAsStringSync(content);
+ expect(file.readAsStringSync(), content);
+ }
+
+ void test_writeAsStringSync_new() {
+ File file = provider.getFile(provider.convertPath('/foo/file.txt'));
+ expect(file.exists, false);
+ // write new bytes
+ String content = 'ef';
+ file.writeAsStringSync(content);
+ expect(file.exists, true);
+ expect(file.readAsStringSync(), content);
}
}
@reflectiveTest
class FolderTest {
- static const String path = '/foo/bar';
-
MemoryResourceProvider provider = new MemoryResourceProvider();
+ String path;
Folder folder;
void setUp() {
+ path = provider.convertPath('/foo/bar');
folder = provider.newFolder(path);
}
void test_canonicalizePath() {
- expect(folder.canonicalizePath('baz'), equals('/foo/bar/baz'));
- expect(folder.canonicalizePath('/baz'), equals('/baz'));
- expect(folder.canonicalizePath('../baz'), equals('/foo/baz'));
- expect(folder.canonicalizePath('/a/b/../c'), equals('/a/c'));
- expect(folder.canonicalizePath('./baz'), equals('/foo/bar/baz'));
- expect(folder.canonicalizePath('/a/b/./c'), equals('/a/b/c'));
+ expect(folder.canonicalizePath(provider.convertPath('baz')),
+ equals(provider.convertPath('/foo/bar/baz')));
+ expect(folder.canonicalizePath(provider.convertPath('/baz')),
+ equals(provider.convertPath('/baz')));
+ expect(folder.canonicalizePath(provider.convertPath('../baz')),
+ equals(provider.convertPath('/foo/baz')));
+ expect(folder.canonicalizePath(provider.convertPath('/a/b/../c')),
+ equals(provider.convertPath('/a/c')));
+ expect(folder.canonicalizePath(provider.convertPath('./baz')),
+ equals(provider.convertPath('/foo/bar/baz')));
+ expect(folder.canonicalizePath(provider.convertPath('/a/b/./c')),
+ equals(provider.convertPath('/a/b/c')));
}
void test_contains() {
- expect(folder.contains('/foo/bar/aaa.txt'), isTrue);
- expect(folder.contains('/foo/bar/aaa/bbb.txt'), isTrue);
- expect(folder.contains('/baz.txt'), isFalse);
- expect(folder.contains('/foo/bar'), isFalse);
+ expect(folder.contains(provider.convertPath('/foo/bar/aaa.txt')), isTrue);
+ expect(
+ folder.contains(provider.convertPath('/foo/bar/aaa/bbb.txt')), isTrue);
+ expect(folder.contains(provider.convertPath('/baz.txt')), isFalse);
+ expect(folder.contains(provider.convertPath('/foo/bar')), isFalse);
+ }
+
+ void test_delete() {
+ Folder folder = provider.newFolder(provider.convertPath('/foo'));
+ Folder barFolder = provider.newFolder(provider.convertPath('/foo/bar'));
+ File aFile = provider.newFile(provider.convertPath('/foo/bar/a.txt'), '');
+ File bFile = provider.newFile(provider.convertPath('/foo/b.txt'), '');
+ expect(folder.exists, isTrue);
+ expect(barFolder.exists, isTrue);
+ expect(aFile.exists, isTrue);
+ expect(bFile.exists, isTrue);
+ // delete 'folder'
+ folder.delete();
+ expect(folder.exists, isFalse);
+ expect(barFolder.exists, isFalse);
+ expect(aFile.exists, isFalse);
+ expect(bFile.exists, isFalse);
}
void test_equal_false() {
- String path2 = '/foo/baz';
+ String path2 = provider.convertPath('/foo/baz');
Folder folder2 = provider.newFolder(path2);
expect(folder == folder2, isFalse);
}
@@ -191,19 +333,39 @@ class FolderTest {
}
void test_getChild_file() {
- provider.newFile('/foo/bar/file.txt', 'content');
+ provider.newFile(provider.convertPath('/foo/bar/file.txt'), 'content');
File child = folder.getChild('file.txt');
expect(child, isNotNull);
expect(child.exists, isTrue);
}
void test_getChild_folder() {
- provider.newFolder('/foo/bar/baz');
+ provider.newFolder(provider.convertPath('/foo/bar/baz'));
Folder child = folder.getChild('baz');
expect(child, isNotNull);
expect(child.exists, isTrue);
}
+ void test_getChildAssumingFile_doesNotExist() {
+ File child = folder.getChildAssumingFile('name');
+ expect(child, isNotNull);
+ expect(child.exists, isFalse);
+ }
+
+ void test_getChildAssumingFile_file() {
+ provider.newFile(provider.convertPath('/foo/bar/name'), 'content');
+ File child = folder.getChildAssumingFile('name');
+ expect(child, isNotNull);
+ expect(child.exists, isTrue);
+ }
+
+ void test_getChildAssumingFile_folder() {
+ provider.newFolder(provider.convertPath('/foo/bar/name'));
+ File child = folder.getChildAssumingFile('name');
+ expect(child, isNotNull);
+ expect(child.exists, isFalse);
+ }
+
void test_getChildAssumingFolder_doesNotExist() {
Folder child = folder.getChildAssumingFolder('foldername');
expect(child, isNotNull);
@@ -211,14 +373,14 @@ class FolderTest {
}
void test_getChildAssumingFolder_file() {
- provider.newFile('/foo/bar/foldername', 'content');
+ provider.newFile(provider.convertPath('/foo/bar/foldername'), 'content');
Folder child = folder.getChildAssumingFolder('foldername');
expect(child, isNotNull);
expect(child.exists, isFalse);
}
void test_getChildAssumingFolder_folder() {
- provider.newFolder('/foo/bar/foldername');
+ provider.newFolder(provider.convertPath('/foo/bar/foldername'));
Folder child = folder.getChildAssumingFolder('foldername');
expect(child, isNotNull);
expect(child.exists, isTrue);
@@ -232,9 +394,9 @@ class FolderTest {
}
void test_getChildren_exists() {
- provider.newFile('/foo/bar/a.txt', 'aaa');
- provider.newFolder('/foo/bar/bFolder');
- provider.newFile('/foo/bar/c.txt', 'ccc');
+ provider.newFile(provider.convertPath('/foo/bar/a.txt'), 'aaa');
+ provider.newFolder(provider.convertPath('/foo/bar/bFolder'));
+ provider.newFile(provider.convertPath('/foo/bar/c.txt'), 'ccc');
// prepare 3 children
List<Resource> children = folder.getChildren();
expect(children, hasLength(3));
@@ -259,30 +421,40 @@ class FolderTest {
}
void test_isOrContains() {
- expect(folder.isOrContains('/foo/bar'), isTrue);
- expect(folder.isOrContains('/foo/bar/aaa.txt'), isTrue);
- expect(folder.isOrContains('/foo/bar/aaa/bbb.txt'), isTrue);
- expect(folder.isOrContains('/baz.txt'), isFalse);
+ expect(folder.isOrContains(provider.convertPath('/foo/bar')), isTrue);
+ expect(
+ folder.isOrContains(provider.convertPath('/foo/bar/aaa.txt')), isTrue);
+ expect(folder.isOrContains(provider.convertPath('/foo/bar/aaa/bbb.txt')),
+ isTrue);
+ expect(folder.isOrContains(provider.convertPath('/baz.txt')), isFalse);
}
void test_parent() {
Resource parent1 = folder.parent;
expect(parent1, new isInstanceOf<Folder>());
- expect(parent1.path, equals('/foo'));
+ expect(parent1.path, equals(provider.convertPath('/foo')));
Resource parent2 = parent1.parent;
expect(parent2, new isInstanceOf<Folder>());
- expect(parent2.path, equals('/'));
+ expect(parent2.path, equals(provider.convertPath('/')));
expect(parent2.parent, isNull);
}
+
+ void test_toUri() {
+ String path = provider.convertPath('/foo/directory');
+ Folder folder = provider.newFolder(path);
+ expect(folder.toUri(), provider.pathContext.toUri(path));
+ }
}
@reflectiveTest
class MemoryFileSourceExistingTest {
MemoryResourceProvider provider = new MemoryResourceProvider();
+ String path;
Source source;
setUp() {
- File file = provider.newFile('/foo/test.dart', 'library test;');
+ path = provider.convertPath('/foo/test.dart');
+ File file = provider.newFile(path, 'library test;');
source = file.createSource();
}
@@ -292,32 +464,36 @@ class MemoryFileSourceExistingTest {
}
void test_encoding() {
- expect(source.encoding, 'file:///foo/test.dart');
+ String expected = 'file:///foo/test.dart';
+ if (provider.pathContext.style == windows.style) {
+ expected = 'file:///C:/foo/test.dart';
+ }
+ expect(source.encoding, expected);
}
void test_equals_false_differentFile() {
- File fileA = provider.newFile('/foo/a.dart', '');
- File fileB = provider.newFile('/foo/b.dart', '');
+ File fileA = provider.newFile(provider.convertPath('/foo/a.dart'), '');
+ File fileB = provider.newFile(provider.convertPath('/foo/b.dart'), '');
Source sourceA = fileA.createSource();
Source sourceB = fileB.createSource();
expect(sourceA == sourceB, isFalse);
}
void test_equals_false_notMemorySource() {
- File file = provider.newFile('/foo/test.dart', '');
+ File file = provider.newFile(path, '');
Source source = file.createSource();
expect(source == new Object(), isFalse);
}
void test_equals_true_sameFile() {
- File file = provider.newFile('/foo/test.dart', '');
+ File file = provider.newFile(path, '');
Source sourceA = file.createSource();
Source sourceB = file.createSource();
expect(sourceA == sourceB, isTrue);
}
void test_equals_true_self() {
- File file = provider.newFile('/foo/test.dart', '');
+ File file = provider.newFile(path, '');
Source source = file.createSource();
expect(source == source, isTrue);
}
@@ -327,7 +503,7 @@ class MemoryFileSourceExistingTest {
}
void test_fullName() {
- expect(source.fullName, '/foo/test.dart');
+ expect(source.fullName, path);
}
void test_hashCode() {
@@ -335,14 +511,19 @@ class MemoryFileSourceExistingTest {
}
void test_resolveRelative() {
- Uri relative = source.resolveRelativeUri(new Uri.file('bar/baz.dart'));
- expect(relative.path, '/foo/bar/baz.dart');
+ Uri relative = resolveRelativeUri(
+ source.uri,
+ provider.pathContext
+ .toUri(provider.pathContext.join('bar', 'baz.dart')));
+ expect(relative,
+ provider.pathContext.toUri(provider.convertPath('/foo/bar/baz.dart')));
}
void test_resolveRelative_dart() {
- File file = provider.newFile('/sdk/lib/core/core.dart', '');
+ File file =
+ provider.newFile(provider.convertPath('/sdk/lib/core/core.dart'), '');
Source source = file.createSource(Uri.parse('dart:core'));
- Uri resolved = source.resolveRelativeUri(Uri.parse('int.dart'));
+ Uri resolved = resolveRelativeUri(source.uri, Uri.parse('int.dart'));
expect(resolved.toString(), 'dart:core/int.dart');
}
@@ -354,10 +535,12 @@ class MemoryFileSourceExistingTest {
@reflectiveTest
class MemoryFileSourceNotExistingTest {
MemoryResourceProvider provider = new MemoryResourceProvider();
+ String path;
Source source;
setUp() {
- File file = provider.getResource('/foo/test.dart');
+ path = provider.convertPath('/foo/test.dart');
+ File file = provider.getResource(path);
source = file.createSource();
}
@@ -368,7 +551,11 @@ class MemoryFileSourceNotExistingTest {
}
void test_encoding() {
- expect(source.encoding, 'file:///foo/test.dart');
+ String expected = 'file:///foo/test.dart';
+ if (provider.pathContext.style == windows.style) {
+ expected = 'file:///C:/foo/test.dart';
+ }
+ expect(source.encoding, expected);
}
void test_exists() {
@@ -376,7 +563,7 @@ class MemoryFileSourceNotExistingTest {
}
void test_fullName() {
- expect(source.fullName, '/foo/test.dart');
+ expect(source.fullName, path);
}
void test_modificationStamp() {
@@ -384,8 +571,12 @@ class MemoryFileSourceNotExistingTest {
}
void test_resolveRelative() {
- Uri relative = source.resolveRelativeUri(new Uri.file('bar/baz.dart'));
- expect(relative.path, '/foo/bar/baz.dart');
+ Uri relative = resolveRelativeUri(
+ source.uri,
+ provider.pathContext
+ .toUri(provider.pathContext.join('bar', 'baz.dart')));
+ expect(relative,
+ provider.pathContext.toUri(provider.convertPath('/foo/bar/baz.dart')));
}
void test_shortName() {
@@ -398,7 +589,7 @@ class MemoryResourceProviderTest {
MemoryResourceProvider provider = new MemoryResourceProvider();
void test_deleteFile_folder() {
- String path = '/my/file';
+ String path = provider.convertPath('/my/file');
provider.newFolder(path);
expect(() {
provider.deleteFile(path);
@@ -407,7 +598,7 @@ class MemoryResourceProviderTest {
}
void test_deleteFile_notExistent() {
- String path = '/my/file';
+ String path = provider.convertPath('/my/file');
expect(() {
provider.deleteFile(path);
}, throwsA(new isInstanceOf<ArgumentError>()));
@@ -417,7 +608,7 @@ class MemoryResourceProviderTest {
}
void test_deleteFile_success() {
- String path = '/my/file';
+ String path = provider.convertPath('/my/file');
provider.newFile(path, 'contents');
Resource file = provider.getResource(path);
expect(file, new isInstanceOf<File>());
@@ -426,6 +617,13 @@ class MemoryResourceProviderTest {
expect(file.exists, isFalse);
}
+ test_getModificationTimes() async {
+ File file = provider.newFile(provider.convertPath('/test.dart'), '');
+ Source source = file.createSource();
+ List<int> times = await provider.getModificationTimes([source]);
+ expect(times, [source.modificationStamp]);
+ }
+
void test_getStateLocation_uniqueness() {
String idOne = 'one';
Folder folderOne = provider.getStateLocation(idOne);
@@ -438,7 +636,7 @@ class MemoryResourceProviderTest {
}
void test_modifyFile_isFolder() {
- String path = '/my/file';
+ String path = provider.convertPath('/my/file');
provider.newFolder(path);
expect(() {
provider.modifyFile(path, 'contents');
@@ -447,7 +645,7 @@ class MemoryResourceProviderTest {
}
void test_modifyFile_notExistent() {
- String path = '/my/file';
+ String path = provider.convertPath('/my/file');
expect(() {
provider.modifyFile(path, 'contents');
}, throwsA(new isInstanceOf<ArgumentError>()));
@@ -457,7 +655,7 @@ class MemoryResourceProviderTest {
}
void test_modifyFile_success() {
- String path = '/my/file';
+ String path = provider.convertPath('/my/file');
provider.newFile(path, 'contents 1');
Resource file = provider.getResource(path);
expect(file, new isInstanceOf<File>());
@@ -467,16 +665,27 @@ class MemoryResourceProviderTest {
expect(source.contents.data, equals('contents 2'));
}
- void test_newFolder_aleadyExists_asFile() {
- provider.newFile('/my/file', 'qwerty');
+ void test_newFileWithBytes() {
+ String path = provider.convertPath('/my/file');
+ List<int> bytes = <int>[1, 2, 3, 4, 5];
+ provider.newFileWithBytes(path, bytes);
+ File file = provider.getResource(path);
+ expect(file, isNotNull);
+ expect(file.exists, isTrue);
+ expect(file.readAsBytesSync(), bytes);
+ }
+
+ void test_newFolder_alreadyExists_asFile() {
+ provider.newFile(provider.convertPath('/my/file'), 'qwerty');
expect(() {
- provider.newFolder('/my/file');
+ provider.newFolder(provider.convertPath('/my/file'));
}, throwsA(new isInstanceOf<ArgumentError>()));
}
- void test_newFolder_aleadyExists_asFolder() {
- Folder folder = provider.newFolder('/my/folder');
- Folder newFolder = provider.newFolder('/my/folder');
+ void test_newFolder_alreadyExists_asFolder() {
+ String path = provider.convertPath('/my/folder');
+ Folder folder = provider.newFolder(path);
+ Folder newFolder = provider.newFolder(path);
expect(newFolder, folder);
}
@@ -493,11 +702,11 @@ class MemoryResourceProviderTest {
}
test_watch_createFile() {
- String rootPath = '/my/path';
+ String rootPath = provider.convertPath('/my/path');
provider.newFolder(rootPath);
return _watchingFolder(rootPath, (changesReceived) {
expect(changesReceived, hasLength(0));
- String path = posix.join(rootPath, 'foo');
+ String path = provider.pathContext.join(rootPath, 'foo');
provider.newFile(path, 'contents');
return _delayed(() {
expect(changesReceived, hasLength(1));
@@ -508,9 +717,9 @@ class MemoryResourceProviderTest {
}
test_watch_deleteFile() {
- String rootPath = '/my/path';
+ String rootPath = provider.convertPath('/my/path');
provider.newFolder(rootPath);
- String path = posix.join(rootPath, 'foo');
+ String path = provider.pathContext.join(rootPath, 'foo');
provider.newFile(path, 'contents 1');
return _watchingFolder(rootPath, (changesReceived) {
expect(changesReceived, hasLength(0));
@@ -524,9 +733,9 @@ class MemoryResourceProviderTest {
}
test_watch_modifyFile() {
- String rootPath = '/my/path';
+ String rootPath = provider.convertPath('/my/path');
provider.newFolder(rootPath);
- String path = posix.join(rootPath, 'foo');
+ String path = provider.pathContext.join(rootPath, 'foo');
provider.newFile(path, 'contents 1');
return _watchingFolder(rootPath, (changesReceived) {
expect(changesReceived, hasLength(0));
@@ -540,11 +749,11 @@ class MemoryResourceProviderTest {
}
test_watch_modifyFile_inSubDir() {
- String rootPath = '/my/path';
+ String rootPath = provider.convertPath('/my/path');
provider.newFolder(rootPath);
- String subdirPath = posix.join(rootPath, 'foo');
+ String subdirPath = provider.pathContext.join(rootPath, 'foo');
provider.newFolder(subdirPath);
- String path = posix.join(rootPath, 'bar');
+ String path = provider.pathContext.join(rootPath, 'bar');
provider.newFile(path, 'contents 1');
return _watchingFolder(rootPath, (changesReceived) {
expect(changesReceived, hasLength(0));
« no previous file with comments | « packages/analyzer/test/enum_test.dart ('k') | packages/analyzer/test/file_system/physical_resource_provider_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698