Skip to content

Commit 094ea68

Browse files
authored
Better toString() implementations (flutter#68)
Fixes flutter#67
1 parent 47f0655 commit 094ea68

File tree

8 files changed

+53
-1
lines changed

8 files changed

+53
-1
lines changed

lib/src/backends/local/local_directory.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ class _LocalDirectory
88
extends _LocalFileSystemEntity<_LocalDirectory, io.Directory>
99
with ForwardingDirectory {
1010
_LocalDirectory(FileSystem fs, io.Directory delegate) : super(fs, delegate);
11+
12+
@override
13+
String toString() => "LocalDirectory: '$path'";
1114
}

lib/src/backends/local/local_file.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ part of file.src.backends.local;
77
class _LocalFile extends _LocalFileSystemEntity<File, io.File>
88
with ForwardingFile {
99
_LocalFile(FileSystem fs, io.File delegate) : super(fs, delegate);
10+
11+
@override
12+
String toString() => "LocalFile: '$path'";
1013
}

lib/src/backends/local/local_link.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ part of file.src.backends.local;
77
class _LocalLink extends _LocalFileSystemEntity<Link, io.Link>
88
with ForwardingLink {
99
_LocalLink(FileSystem fs, io.Link delegate) : super(fs, delegate);
10+
11+
@override
12+
String toString() => "LocalLink: '$path'";
1013
}

lib/src/backends/memory/memory_directory.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ class _MemoryDirectory extends _MemoryFileSystemEntity implements Directory {
137137

138138
@override
139139
Directory _clone(String path) => new _MemoryDirectory(fileSystem, path);
140+
141+
@override
142+
String toString() => "MemoryDirectory: '$path'";
140143
}
141144

142145
class _PendingListTask {

lib/src/backends/memory/memory_file.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ class _MemoryFile extends _MemoryFileSystemEntity implements File {
240240
node.content.clear();
241241
}
242242
}
243+
244+
@override
245+
String toString() => "MemoryFile: '$path'";
243246
}
244247

245248
/// Implementation of an [io.IOSink] that's backed by a [_FileNode].

lib/src/backends/memory/memory_link.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,7 @@ class _MemoryLink extends _MemoryFileSystemEntity implements Link {
9292

9393
@override
9494
Link _clone(String path) => new _MemoryLink(fileSystem, path);
95+
96+
@override
97+
String toString() => "MemoryLink: '$path'";
9598
}

test/local_test.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,19 @@ void main() {
6767
'Link > rename > throwsIfDestinationExistsAsFile',
6868
],
6969
);
70+
71+
group('toString', () {
72+
test('File', () {
73+
expect(fs.file('/foo').toString(), "LocalFile: '/foo'");
74+
});
75+
76+
test('Directory', () {
77+
expect(fs.directory('/foo').toString(), "LocalDirectory: '/foo'");
78+
});
79+
80+
test('Link', () {
81+
expect(fs.link('/foo').toString(), "LocalLink: '/foo'");
82+
});
83+
});
7084
});
7185
}

test/memory_test.dart

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,31 @@ import 'common_tests.dart';
99

1010
void main() {
1111
group('MemoryFileSystem', () {
12+
MemoryFileSystem fs;
13+
14+
setUp(() {
15+
fs = new MemoryFileSystem();
16+
});
17+
1218
runCommonTests(
13-
() => new MemoryFileSystem(),
19+
() => fs,
1420
skip: <String>[
1521
'File > open', // Not yet implemented
1622
],
1723
);
24+
25+
group('toString', () {
26+
test('File', () {
27+
expect(fs.file('/foo').toString(), "MemoryFile: '/foo'");
28+
});
29+
30+
test('Directory', () {
31+
expect(fs.directory('/foo').toString(), "MemoryDirectory: '/foo'");
32+
});
33+
34+
test('Link', () {
35+
expect(fs.link('/foo').toString(), "MemoryLink: '/foo'");
36+
});
37+
});
1838
});
1939
}

0 commit comments

Comments
 (0)