-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.rs
137 lines (108 loc) · 3.03 KB
/
tests.rs
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#[test]
fn simple() {
use staticfilemap::*;
#[derive(StaticFileMap)]
#[names("readme;license")]
#[files("README.md;LICENSE")]
struct StaticMap;
let content = StaticMap::get("license").unwrap();
let string = String::from_utf8_lossy(&content[..10]);
assert!(&string == "Copyright ");
}
#[test]
fn get_match() {
use staticfilemap::*;
#[derive(StaticFileMap)]
#[names("readme;license")]
#[files("README.md;LICENSE")]
struct StaticMap;
let content = StaticMap::get_match("lic").unwrap();
let string = String::from_utf8_lossy(&content[..10]);
assert!(&string == "Copyright ");
}
#[cfg(feature = "lz4")]
#[test]
fn compression_lz4() {
use minilz4::Decoder;
use staticfilemap::*;
use std::io::Read;
#[derive(StaticFileMap)]
#[names("readme;license")]
#[files("README.md;LICENSE")]
#[compression(1)]
#[algorithm("lz4")]
struct StaticMap;
let compressed = StaticMap::get("license").unwrap();
let mut content = Vec::new();
let mut decoder = Decoder::new(compressed).unwrap();
decoder.read_to_end(&mut content).unwrap();
let string = String::from_utf8_lossy(&content[..10]);
assert!(&string == "Copyright ");
}
#[cfg(feature = "zstd")]
#[test]
fn compression_zstd() {
use staticfilemap::*;
use zstd::decode_all;
#[derive(StaticFileMap)]
#[names("readme;license")]
#[files("README.md;LICENSE")]
#[compression(1)]
#[algorithm("zstd")]
struct StaticMap;
let mut compressed = StaticMap::get("license").unwrap();
let content = decode_all(&mut compressed).unwrap();
let string = String::from_utf8_lossy(&content[..10]);
assert!(&string == "Copyright ");
}
#[test]
fn parse_env() {
use staticfilemap::*;
#[derive(StaticFileMap)]
#[parse("env")]
#[names("CARGO_PKG_NAME")]
#[files("CARGO_PKG_LICENSE_FILE")]
struct StaticMap;
let _ = StaticMap::get("staticfilemap").unwrap();
}
#[test]
fn keys() {
use staticfilemap::*;
#[derive(StaticFileMap)]
#[names("readme;license")]
#[files("README.md;LICENSE")]
struct StaticMap;
let keys = StaticMap::keys();
assert_eq!(keys, &["readme", "license"])
}
#[test]
fn types() {
use staticfilemap::*;
#[derive(StaticFileMap)]
#[names("readme;license")]
#[files("README.md;LICENSE")]
struct StaticMap;
let _: &[u8] = StaticMap::get("readme").unwrap();
let _: &[&str] = StaticMap::keys();
}
#[test]
fn implicit_names() {
use staticfilemap::*;
#[derive(StaticFileMap)]
#[files("README.md;LICENSE")]
struct StaticMap;
let content = StaticMap::get("LICENSE").unwrap();
let string = String::from_utf8_lossy(&content[..10]);
assert!(&string == "Copyright ");
}
#[test]
fn iter() {
use staticfilemap::*;
#[derive(StaticFileMap)]
#[files("README.md;LICENSE")]
struct StaticMap;
let data = StaticMap::iter().collect::<Vec<_>>();
assert!(data[1].0 == "LICENSE");
let string = String::from_utf8_lossy(data[1].1);
assert!(&string[..10] == "Copyright ");
}