File: include_exclude.rs

package info (click to toggle)
rust-rust-embed 8.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,184 kB
  • sloc: javascript: 4; makefile: 2
file content (68 lines) | stat: -rw-r--r-- 2,285 bytes parent folder | download
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
use rust_embed::Embed;

#[derive(Embed)]
#[folder = "examples/public/"]
struct AllAssets;

#[test]
fn get_works() {
  assert!(AllAssets::get("index.html").is_some(), "index.html should exist");
  assert!(AllAssets::get("gg.html").is_none(), "gg.html should not exist");
  assert!(AllAssets::get("images/llama.png").is_some(), "llama.png should exist");
  assert!(AllAssets::get("symlinks/main.js").is_some(), "main.js should exist");
  assert_eq!(AllAssets::iter().count(), 7);
}

#[derive(Embed)]
#[folder = "examples/public/"]
#[include = "*.html"]
#[include = "images/*"]
struct IncludeSomeAssets;

#[test]
fn including_some_assets_works() {
  assert!(IncludeSomeAssets::get("index.html").is_some(), "index.html should exist");
  assert!(IncludeSomeAssets::get("main.js").is_none(), "main.js should not exist");
  assert!(IncludeSomeAssets::get("images/llama.png").is_some(), "llama.png should exist");
  assert_eq!(IncludeSomeAssets::iter().count(), 4);
}

#[derive(Embed)]
#[folder = "examples/public/"]
#[exclude = "*.html"]
#[exclude = "images/*"]
struct ExcludeSomeAssets;

#[test]
fn excluding_some_assets_works() {
  assert!(ExcludeSomeAssets::get("index.html").is_none(), "index.html should not exist");
  assert!(ExcludeSomeAssets::get("main.js").is_some(), "main.js should exist");
  assert!(ExcludeSomeAssets::get("symlinks/main.js").is_some(), "main.js symlink should exist");
  assert!(ExcludeSomeAssets::get("images/llama.png").is_none(), "llama.png should not exist");
  assert_eq!(ExcludeSomeAssets::iter().count(), 3);
}

#[derive(Embed)]
#[folder = "examples/public/"]
#[include = "images/*"]
#[exclude = "*.txt"]
struct ExcludePriorityAssets;

#[test]
fn exclude_has_higher_priority() {
  assert!(ExcludePriorityAssets::get("images/doc.txt").is_none(), "doc.txt should not exist");
  assert!(ExcludePriorityAssets::get("images/llama.png").is_some(), "llama.png should exist");
  assert_eq!(ExcludePriorityAssets::iter().count(), 2);
}

#[derive(Embed)]
#[folder = "examples/public/symlinks"]
#[include = "main.js"]
struct IncludeSymlink;

#[test]
fn include_symlink() {
  assert_eq!(IncludeSymlink::iter().count(), 1);
  assert_eq!(IncludeSymlink::iter().next(), Some(std::borrow::Cow::Borrowed("main.js")));
  assert!(IncludeSymlink::get("main.js").is_some())
}