| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 reader_test; | 5 library reader_test; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 import '../../../pkg/unittest/lib/unittest.dart' | 8 import '../../../pkg/unittest/lib/unittest.dart' |
| 9 import '../../archive/archive.dart'; | 9 import '../../archive/archive.dart'; |
| 10 | 10 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 expect(future, completes); | 49 expect(future, completes); |
| 50 }); | 50 }); |
| 51 | 51 |
| 52 test('reading a .tar.gz file with readAll', () { | 52 test('reading a .tar.gz file with readAll', () { |
| 53 var reader = new ArchiveReader(); | 53 var reader = new ArchiveReader(); |
| 54 reader.format.tar = true; | 54 reader.format.tar = true; |
| 55 reader.filter.gzip = true; | 55 reader.filter.gzip = true; |
| 56 | 56 |
| 57 var future = reader.openFilename("$dataPath/test-archive.tar.gz") | 57 var future = reader.openFilename("$dataPath/test-archive.tar.gz") |
| 58 .chain((input) => input.readAll()) | 58 .then((input) => input.readAll()) |
| 59 .then((entries) { | 59 .then((entries) { |
| 60 entries = entries | 60 entries = entries |
| 61 .mappedBy((entry) => [entry.pathname, entry.contents.trim()]) | 61 .mappedBy((entry) => [entry.pathname, entry.contents.trim()]) |
| 62 .toList(); | 62 .toList(); |
| 63 expect(entries[0], orderedEquals(["filename1", "contents 1"])); | 63 expect(entries[0], orderedEquals(["filename1", "contents 1"])); |
| 64 expect(entries[1], orderedEquals(["filename2", "contents 2"])); | 64 expect(entries[1], orderedEquals(["filename2", "contents 2"])); |
| 65 expect(entries[2], orderedEquals(["filename3", "contents 3"])); | 65 expect(entries[2], orderedEquals(["filename3", "contents 3"])); |
| 66 }); | 66 }); |
| 67 | 67 |
| 68 expect(future, completes); | 68 expect(future, completes); |
| 69 }); | 69 }); |
| 70 | 70 |
| 71 test('reading an in-memory .tar.gz', () { | 71 test('reading an in-memory .tar.gz', () { |
| 72 var asyncDone = expectAsync0(() {}); | 72 var asyncDone = expectAsync0(() {}); |
| 73 | 73 |
| 74 var reader = new ArchiveReader(); | 74 var reader = new ArchiveReader(); |
| 75 reader.format.tar = true; | 75 reader.format.tar = true; |
| 76 reader.filter.gzip = true; | 76 reader.filter.gzip = true; |
| 77 | 77 |
| 78 var future = new File("$dataPath/test-archive.tar.gz").readAsBytes() | 78 var future = new File("$dataPath/test-archive.tar.gz").readAsBytes() |
| 79 .chain((bytes) => reader.openData(bytes)) | 79 .then((bytes) => reader.openData(bytes)) |
| 80 .then((input) { | 80 .then((input) { |
| 81 var log = <String>[]; | 81 var log = <String>[]; |
| 82 input.onEntry = (entry) => guardAsync(() { | 82 input.onEntry = (entry) => guardAsync(() { |
| 83 log.add("Entry: ${entry.pathname}"); | 83 log.add("Entry: ${entry.pathname}"); |
| 84 var stream = new StringInputStream(entry.openInputStream()); | 84 var stream = new StringInputStream(entry.openInputStream()); |
| 85 stream.onData = () => log.add("Contents: ${stream.read().trim()}"); | 85 stream.onData = () => log.add("Contents: ${stream.read().trim()}"); |
| 86 stream.onClosed = () => log.add("Closed: ${entry.pathname}"); | 86 stream.onClosed = () => log.add("Closed: ${entry.pathname}"); |
| 87 }); | 87 }); |
| 88 input.onError = registerException; | 88 input.onError = registerException; |
| 89 | 89 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 test("opening a non-existent archive", () { | 191 test("opening a non-existent archive", () { |
| 192 var reader = new ArchiveReader(); | 192 var reader = new ArchiveReader(); |
| 193 reader.format.tar = true; | 193 reader.format.tar = true; |
| 194 reader.filter.gzip = true; | 194 reader.filter.gzip = true; |
| 195 | 195 |
| 196 expect(reader.openFilename("$dataPath/non-existent.tar.gz"), | 196 expect(reader.openFilename("$dataPath/non-existent.tar.gz"), |
| 197 throwsA((e) => e is ArchiveException)); | 197 throwsA((e) => e is ArchiveException)); |
| 198 }); | 198 }); |
| 199 } | 199 } |
| 200 | 200 |
| OLD | NEW |