summaryrefslogtreecommitdiffstats
path: root/vendor/xz2/tests
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/xz2/tests')
-rw-r--r--vendor/xz2/tests/drop-incomplete.rs17
-rw-r--r--vendor/xz2/tests/tokio.rs73
-rw-r--r--vendor/xz2/tests/xz.rs19
3 files changed, 56 insertions, 53 deletions
diff --git a/vendor/xz2/tests/drop-incomplete.rs b/vendor/xz2/tests/drop-incomplete.rs
index 15815be40..2515cb558 100644
--- a/vendor/xz2/tests/drop-incomplete.rs
+++ b/vendor/xz2/tests/drop-incomplete.rs
@@ -1,14 +1,12 @@
-extern crate xz2;
-
use std::io::prelude::*;
use xz2::write::XzDecoder;
// This is a XZ file generated by head -c10 /dev/urandom | xz -c
-const DATA: &'static [u8] =
- &[253, 55, 122, 88, 90, 0, 0, 4, 230, 214, 180, 70, 2, 0, 33, 1, 22, 0, 0, 0, 116, 47, 229,
- 163, 1, 0, 9, 7, 122, 65, 14, 253, 214, 121, 128, 230, 115, 0, 0, 0, 158, 47, 174, 196, 175,
- 10, 34, 254, 0, 1, 34, 10, 21, 26, 225, 103, 31, 182, 243, 125, 1, 0, 0, 0, 0, 4, 89, 90];
-
+const DATA: &'static [u8] = &[
+ 253, 55, 122, 88, 90, 0, 0, 4, 230, 214, 180, 70, 2, 0, 33, 1, 22, 0, 0, 0, 116, 47, 229, 163,
+ 1, 0, 9, 7, 122, 65, 14, 253, 214, 121, 128, 230, 115, 0, 0, 0, 158, 47, 174, 196, 175, 10, 34,
+ 254, 0, 1, 34, 10, 21, 26, 225, 103, 31, 182, 243, 125, 1, 0, 0, 0, 0, 4, 89, 90,
+];
/// In this test, we drop a write::XzDecoder after supplying it a truncated input stream.
///
@@ -27,5 +25,8 @@ fn finish_writer_incomplete_input_error() {
let mut decoder = XzDecoder::new(Vec::new());
const PREFIX_LEN: usize = 50;
decoder.write_all(&DATA[..PREFIX_LEN]).unwrap();
- decoder.finish().err().expect("finish should error because of incomplete input");
+ decoder
+ .finish()
+ .err()
+ .expect("finish should error because of incomplete input");
}
diff --git a/vendor/xz2/tests/tokio.rs b/vendor/xz2/tests/tokio.rs
index be30ed099..0d771282c 100644
--- a/vendor/xz2/tests/tokio.rs
+++ b/vendor/xz2/tests/tokio.rs
@@ -1,23 +1,17 @@
#![cfg(feature = "tokio")]
-extern crate tokio_core;
-extern crate xz2;
-extern crate tokio_io;
-extern crate futures;
-extern crate rand;
-
-use std::thread;
-use std::net::{Shutdown, TcpListener};
use std::io::{Read, Write};
+use std::net::{Shutdown, TcpListener};
+use std::thread;
-use xz2::read;
-use xz2::write;
use futures::Future;
-use rand::{Rng, thread_rng};
+use rand::Rng;
use tokio_core::net::TcpStream;
use tokio_core::reactor::Core;
-use tokio_io::AsyncRead;
use tokio_io::io::{copy, shutdown};
+use tokio_io::AsyncRead;
+use xz2::read;
+use xz2::write;
#[test]
fn tcp_stream_echo_pattern() {
@@ -49,24 +43,25 @@ fn tcp_stream_echo_pattern() {
let buf = [i; M];
a.write_all(&buf).unwrap();
}
- a.finish().unwrap()
- .shutdown(Shutdown::Write).unwrap();
+ a.finish().unwrap().shutdown(Shutdown::Write).unwrap();
t.join().unwrap();
});
let handle = core.handle();
let stream = TcpStream::connect(&addr, &handle);
- let copy = stream.and_then(|s| {
- let (a, b) = s.split();
- let a = read::XzDecoder::new(a);
- let b = write::XzEncoder::new(b, 6);
- copy(a, b)
- }).then(|result| {
- let (amt, _a, b) = result.unwrap();
- assert_eq!(amt, (N as u64) * (M as u64));
- shutdown(b).map(|_| ())
- });
+ let copy = stream
+ .and_then(|s| {
+ let (a, b) = s.split();
+ let a = read::XzDecoder::new(a);
+ let b = write::XzEncoder::new(b, 6);
+ copy(a, b)
+ })
+ .then(|result| {
+ let (amt, _a, b) = result.unwrap();
+ assert_eq!(amt, (N as u64) * (M as u64));
+ shutdown(b).map(|_| ())
+ });
core.run(copy).unwrap();
t.join().unwrap();
@@ -74,7 +69,10 @@ fn tcp_stream_echo_pattern() {
#[test]
fn echo_random() {
- let v = thread_rng().gen_iter::<u8>().take(1024 * 1024).collect::<Vec<_>>();
+ let v = std::iter::repeat(())
+ .map(|_| rand::thread_rng().gen::<u8>())
+ .take(1024 * 1024)
+ .collect::<Vec<_>>();
let mut core = Core::new().unwrap();
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
let addr = listener.local_addr().unwrap();
@@ -100,24 +98,25 @@ fn echo_random() {
let mut a = write::XzEncoder::new(a, 6);
a.write_all(&v2).unwrap();
- a.finish().unwrap()
- .shutdown(Shutdown::Write).unwrap();
+ a.finish().unwrap().shutdown(Shutdown::Write).unwrap();
t.join().unwrap();
});
let handle = core.handle();
let stream = TcpStream::connect(&addr, &handle);
- let copy = stream.and_then(|s| {
- let (a, b) = s.split();
- let a = read::XzDecoder::new(a);
- let b = write::XzEncoder::new(b, 6);
- copy(a, b)
- }).then(|result| {
- let (amt, _a, b) = result.unwrap();
- assert_eq!(amt, v.len() as u64);
- shutdown(b).map(|_| ())
- });
+ let copy = stream
+ .and_then(|s| {
+ let (a, b) = s.split();
+ let a = read::XzDecoder::new(a);
+ let b = write::XzEncoder::new(b, 6);
+ copy(a, b)
+ })
+ .then(|result| {
+ let (amt, _a, b) = result.unwrap();
+ assert_eq!(amt, v.len() as u64);
+ shutdown(b).map(|_| ())
+ });
core.run(copy).unwrap();
t.join().unwrap();
diff --git a/vendor/xz2/tests/xz.rs b/vendor/xz2/tests/xz.rs
index 5b1dd6bb8..ad178e95d 100644
--- a/vendor/xz2/tests/xz.rs
+++ b/vendor/xz2/tests/xz.rs
@@ -1,31 +1,32 @@
-extern crate xz2;
-
use std::fs::File;
use std::io::prelude::*;
use std::path::Path;
use xz2::read;
-use xz2::write;
use xz2::stream;
+use xz2::write;
#[test]
fn standard_files() {
for file in Path::new("lzma-sys/xz-5.2/tests/files").read_dir().unwrap() {
let file = file.unwrap();
if file.path().extension().and_then(|s| s.to_str()) != Some("xz") {
- continue
+ continue;
}
let filename = file.file_name().into_string().unwrap();
// This appears to be implementation-defined how it's handled
if filename.contains("unsupported-check") {
- continue
+ continue;
}
println!("testing {:?}", file.path());
let mut contents = Vec::new();
- File::open(&file.path()).unwrap().read_to_end(&mut contents).unwrap();
+ File::open(&file.path())
+ .unwrap()
+ .read_to_end(&mut contents)
+ .unwrap();
if filename.starts_with("bad") || filename.starts_with("unsupported") {
test_bad(&contents);
} else {
@@ -36,7 +37,9 @@ fn standard_files() {
fn test_good(data: &[u8]) {
let mut ret = Vec::new();
- read::XzDecoder::new_multi_decoder(data).read_to_end(&mut ret).unwrap();
+ read::XzDecoder::new_multi_decoder(data)
+ .read_to_end(&mut ret)
+ .unwrap();
let mut w = write::XzDecoder::new_multi_decoder(ret);
w.write_all(data).unwrap();
w.finish().unwrap();
@@ -49,7 +52,7 @@ fn test_bad(data: &[u8]) {
assert!(w.write_all(data).is_err() || w.finish().is_err());
}
-fn assert_send_sync<T: Send + Sync>() { }
+fn assert_send_sync<T: Send + Sync>() {}
#[test]
fn impls_send_and_sync() {