~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.
e411b7be
—
Bernardo 7 years ago
no need for separate tests since implementations are the same
- tests/lib.rs +6 -32
tests/lib.rs
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
#[macro_use]
|
|
2
2
|
extern crate rust_embed;
|
|
3
3
|
|
|
4
|
-
#[test]
|
|
5
|
-
#[cfg(debug_assertions)]
|
|
6
|
-
fn dev() {
|
|
7
|
-
|
|
4
|
+
#[derive(RustEmbed)]
|
|
8
|
-
|
|
5
|
+
#[folder = "examples/public/"]
|
|
9
|
-
|
|
6
|
+
struct Asset;
|
|
10
7
|
|
|
8
|
+
#[test]
|
|
9
|
+
fn get_works() {
|
|
11
10
|
match Asset::get("index.html") {
|
|
12
11
|
None => assert!(false, "index.html should exist"),
|
|
13
12
|
_ => assert!(true),
|
|
@@ -20,35 +19,10 @@ fn dev() {
|
|
|
20
19
|
None => assert!(false, "llama.png should exist"),
|
|
21
20
|
_ => assert!(true),
|
|
22
21
|
}
|
|
23
|
-
|
|
24
|
-
let mut num_files = 0;
|
|
25
|
-
for file in Asset::iter() {
|
|
26
|
-
assert!(Asset::get(file.as_ref()).is_some());
|
|
27
|
-
num_files += 1;
|
|
28
|
-
}
|
|
29
|
-
assert_eq!(num_files, 6);
|
|
30
22
|
}
|
|
31
23
|
|
|
32
24
|
#[test]
|
|
33
|
-
#[cfg(not(debug_assertions))]
|
|
34
|
-
fn
|
|
25
|
+
fn iter_works() {
|
|
35
|
-
#[derive(RustEmbed)]
|
|
36
|
-
#[folder = "examples/public/"]
|
|
37
|
-
struct Asset;
|
|
38
|
-
|
|
39
|
-
match Asset::get("index.html") {
|
|
40
|
-
None => assert!(false, "index.html should exist"),
|
|
41
|
-
_ => assert!(true),
|
|
42
|
-
}
|
|
43
|
-
match Asset::get("gg.html") {
|
|
44
|
-
Some(_) => assert!(false, "gg.html should not exist"),
|
|
45
|
-
_ => assert!(true),
|
|
46
|
-
}
|
|
47
|
-
match Asset::get("images/llama.png") {
|
|
48
|
-
None => assert!(false, "llama.png should exist"),
|
|
49
|
-
_ => assert!(true),
|
|
50
|
-
}
|
|
51
|
-
|
|
52
26
|
let mut num_files = 0;
|
|
53
27
|
for file in Asset::iter() {
|
|
54
28
|
assert!(Asset::get(file.as_ref()).is_some());
|