~repos /rust-embed
git clone https://pyrossh.dev/repos/rust-embed.git
rust macro which loads files into the rust binary at compile time during release and loads the file from the fs during dev.
e327b2d2
—
Ryan Lopopolo 6 years ago
Add test for Asset struct with interpolated path
- tests/interpolated_path.rs +47 -0
tests/interpolated_path.rs
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#[macro_use]
|
|
2
|
+
extern crate rust_embed;
|
|
3
|
+
|
|
4
|
+
/// Test doc comment
|
|
5
|
+
#[derive(RustEmbed)]
|
|
6
|
+
#[folder = "$CARGO_MANFEST_ROOT/examples/public/"]
|
|
7
|
+
struct Asset;
|
|
8
|
+
|
|
9
|
+
#[test]
|
|
10
|
+
fn get_works() {
|
|
11
|
+
match Asset::get("index.html") {
|
|
12
|
+
None => assert!(false, "index.html should exist"),
|
|
13
|
+
_ => assert!(true),
|
|
14
|
+
}
|
|
15
|
+
match Asset::get("gg.html") {
|
|
16
|
+
Some(_) => assert!(false, "gg.html should not exist"),
|
|
17
|
+
_ => assert!(true),
|
|
18
|
+
}
|
|
19
|
+
match Asset::get("images/llama.png") {
|
|
20
|
+
None => assert!(false, "llama.png should exist"),
|
|
21
|
+
_ => assert!(true),
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
#[test]
|
|
26
|
+
fn iter_works() {
|
|
27
|
+
let mut num_files = 0;
|
|
28
|
+
for file in Asset::iter() {
|
|
29
|
+
assert!(Asset::get(file.as_ref()).is_some());
|
|
30
|
+
num_files += 1;
|
|
31
|
+
}
|
|
32
|
+
assert_eq!(num_files, 6);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
#[test]
|
|
36
|
+
fn trait_works_generic() {
|
|
37
|
+
trait_works_generic_helper::<Asset>();
|
|
38
|
+
}
|
|
39
|
+
fn trait_works_generic_helper<E: rust_embed::RustEmbed>() {
|
|
40
|
+
let mut num_files = 0;
|
|
41
|
+
for file in E::iter() {
|
|
42
|
+
assert!(E::get(file.as_ref()).is_some());
|
|
43
|
+
num_files += 1;
|
|
44
|
+
}
|
|
45
|
+
assert_eq!(num_files, 6);
|
|
46
|
+
assert!(E::get("gg.html").is_none(), "gg.html should not exist");
|
|
47
|
+
}
|