OLD | NEW |
1 // Copyright 2013 Google Inc. All Rights Reserved. | 1 // Copyright 2013 Google Inc. All Rights Reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 10 matching lines...) Expand all Loading... |
21 import 'package:path/path.dart' as path; | 21 import 'package:path/path.dart' as path; |
22 import 'package:quiver/io.dart'; | 22 import 'package:quiver/io.dart'; |
23 import 'package:test/test.dart'; | 23 import 'package:test/test.dart'; |
24 | 24 |
25 main() { | 25 main() { |
26 group('byteStreamToString', () { | 26 group('byteStreamToString', () { |
27 test('should decode UTF8 text by default', () { | 27 test('should decode UTF8 text by default', () { |
28 var string = '箙、靫'; | 28 var string = '箙、靫'; |
29 var encoded = UTF8.encoder.convert(string); | 29 var encoded = UTF8.encoder.convert(string); |
30 var data = [encoded.sublist(0, 3), encoded.sublist(3)]; | 30 var data = [encoded.sublist(0, 3), encoded.sublist(3)]; |
31 var stream = new Stream.fromIterable(data); | 31 var stream = new Stream<List<int>>.fromIterable(data); |
32 byteStreamToString(stream).then((decoded) { | 32 byteStreamToString(stream).then((decoded) { |
33 expect(decoded, string); | 33 expect(decoded, string); |
34 }); | 34 }); |
35 }); | 35 }); |
36 | 36 |
37 test('should decode text with the specified encoding', () { | 37 test('should decode text with the specified encoding', () { |
38 var string = 'blåbærgrød'; | 38 var string = 'blåbærgrød'; |
39 var encoded = LATIN1.encoder.convert(string); | 39 var encoded = LATIN1.encoder.convert(string); |
40 var data = [encoded.sublist(0, 4), encoded.sublist(4)]; | 40 var data = [encoded.sublist(0, 4), encoded.sublist(4)]; |
41 var stream = new Stream.fromIterable(data); | 41 var stream = new Stream<List<int>>.fromIterable(data); |
42 byteStreamToString(stream, encoding: LATIN1).then((decoded) { | 42 byteStreamToString(stream, encoding: LATIN1).then((decoded) { |
43 expect(decoded, string); | 43 expect(decoded, string); |
44 }); | 44 }); |
45 }); | 45 }); |
46 }); | 46 }); |
47 | 47 |
48 group('visitDirectory', () { | 48 group('visitDirectory', () { |
49 var testPath; | 49 var testPath; |
50 var testDir; | 50 var testDir; |
51 | 51 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 new Directory(path.join(testPath, 'dir')).createSync(); | 107 new Directory(path.join(testPath, 'dir')).createSync(); |
108 new File(path.join(testPath, 'dir/file')).createSync(); | 108 new File(path.join(testPath, 'dir/file')).createSync(); |
109 new Directory(path.join(testPath, 'dir2')).createSync(); | 109 new Directory(path.join(testPath, 'dir2')).createSync(); |
110 new File(path.join(testPath, 'dir2/file')).createSync(); | 110 new File(path.join(testPath, 'dir2/file')).createSync(); |
111 | 111 |
112 var files = []; | 112 var files = []; |
113 return visitDirectory(testDir, (e) { | 113 return visitDirectory(testDir, (e) { |
114 files.add(e); | 114 files.add(e); |
115 return new Future.value(!e.path.endsWith('dir2')); | 115 return new Future.value(!e.path.endsWith('dir2')); |
116 }).then((_) { | 116 }).then((_) { |
117 expect(files.map((e) => e.path), unorderedEquals( | 117 expect( |
118 ["$testPath/dir", "$testPath/dir/file", "$testPath/dir2",])); | 118 files.map((e) => e.path), |
| 119 unorderedEquals([ |
| 120 "$testPath/dir", |
| 121 "$testPath/dir/file", |
| 122 "$testPath/dir2", |
| 123 ])); |
119 }); | 124 }); |
120 }); | 125 }); |
121 | 126 |
122 test('should not infinitely recurse on symlink cycles', () { | 127 test('should not infinitely recurse on symlink cycles', () { |
123 var dir = new Directory(path.join(testPath, 'dir'))..createSync(); | 128 var dir = new Directory(path.join(testPath, 'dir'))..createSync(); |
124 new Link(path.join(testPath, 'dir/link')).createSync('../dir'); | 129 new Link(path.join(testPath, 'dir/link')).createSync('../dir'); |
125 var files = []; | 130 var files = []; |
126 return visitDirectory(dir, (e) { | 131 return visitDirectory(dir, (e) { |
127 files.add(e); | 132 files.add(e); |
128 return new Future.value(true); | 133 return new Future.value(true); |
129 }).then((_) { | 134 }).then((_) { |
130 expect(files.length, 1); | 135 expect(files.length, 1); |
131 expect(files.first.targetSync(), '../dir'); | 136 expect(files.first.targetSync(), '../dir'); |
132 }); | 137 }); |
133 }); | 138 }); |
134 }); | 139 }); |
135 } | 140 } |
OLD | NEW |