1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
mod utils;
macro_rules! tests {
($($name:ident),*) => {
$(
mod $name {
mod stream {
use crate::utils;
use proptest::{prelude::any, proptest};
use std::iter::FromIterator;
proptest! {
#[test]
fn compress(ref input in any::<utils::InputStream>()) {
let compressed = utils::$name::stream::compress(input.stream());
let output = utils::$name::sync::decompress(&compressed);
assert_eq!(output, input.bytes());
}
#[test]
fn decompress(
ref input in any::<Vec<u8>>(),
chunk_size in 1..20usize,
) {
let compressed = utils::$name::sync::compress(input);
let stream = utils::InputStream::from(Vec::from_iter(compressed.chunks(chunk_size).map(Vec::from)));
let output = utils::$name::stream::decompress(stream.stream());
assert_eq!(&output, input);
}
}
}
mod futures {
mod bufread {
use crate::utils;
use proptest::{prelude::any, proptest};
use std::iter::FromIterator;
proptest! {
#[test]
fn compress(ref input in any::<utils::InputStream>()) {
let compressed = utils::$name::futures::bufread::compress(input.reader());
let output = utils::$name::sync::decompress(&compressed);
assert_eq!(output, input.bytes());
}
#[test]
fn decompress(
ref input in any::<Vec<u8>>(),
chunk_size in 1..20usize,
) {
let compressed = utils::$name::sync::compress(input);
let stream = utils::InputStream::from(Vec::from_iter(compressed.chunks(chunk_size).map(Vec::from)));
let output = utils::$name::futures::bufread::decompress(stream.reader());
assert_eq!(&output, input);
}
}
}
mod write {
use crate::utils;
use proptest::{prelude::any, proptest};
proptest! {
#[test]
fn compress(
ref input in any::<utils::InputStream>(),
limit in 1..20usize,
) {
let compressed = utils::$name::futures::write::compress(input.as_ref(), limit);
let output = utils::$name::sync::decompress(&compressed);
assert_eq!(output, input.bytes());
}
}
}
}
}
)*
}
}
tests!(brotli, bzip2, deflate, gzip, lzma, xz, zlib, zstd);