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
use rust_embed_for_web::{EmbedableFile, RustEmbed};
// This test is designed to run in debug mode without always-embed feature
// to test the DynamicFile code paths that always return None for compressed data
#[derive(RustEmbed)]
#[folder = "examples/public/"]
struct DynamicAssets;
#[test]
fn dynamic_file_compressed_data_is_none() {
// In debug mode without always-embed, this should use DynamicFile
let file = DynamicAssets::get("index.html").unwrap();
// When always-embed is not enabled, DynamicFile always returns None for compressed data
#[cfg(not(feature = "always-embed"))]
{
assert!(file.data_gzip().is_none());
assert!(file.data_br().is_none());
assert!(file.data_zstd().is_none());
}
// When always-embed is enabled, EmbeddedFile may have compressed data
#[cfg(feature = "always-embed")]
{
// Just verify the file exists and has data - compression depends on the build
assert!(!file.data().is_empty());
}
// But it should always have the original data
assert!(!file.data().is_empty());
}
#[test]
fn dynamic_file_image_compressed_data_is_none() {
// Test with an image file too
let file = DynamicAssets::get("images/flower.jpg").unwrap();
// When always-embed is not enabled, DynamicFile always returns None for compressed data
#[cfg(not(feature = "always-embed"))]
{
assert!(file.data_gzip().is_none());
assert!(file.data_br().is_none());
assert!(file.data_zstd().is_none());
}
// When always-embed is enabled, EmbeddedFile may have compressed data (usually None for images)
#[cfg(feature = "always-embed")]
{
// Just verify the file exists and has data
assert!(!file.data().is_empty());
}
// But it should always have the original data
assert!(!file.data().is_empty());
}
#[test]
fn explicit_dynamic_compression_coverage() {
// Explicitly test to ensure coverage of DynamicFile compression methods
let file = DynamicAssets::get("index.html").unwrap();
// When always-embed is not enabled, test the DynamicFile paths
#[cfg(not(feature = "always-embed"))]
{
// Test each compression method explicitly to ensure coverage
let gzip_result = file.data_gzip();
assert_eq!(gzip_result, None);
let br_result = file.data_br();
assert_eq!(br_result, None);
let zstd_result = file.data_zstd();
assert_eq!(zstd_result, None);
}
// When always-embed is enabled, test the EmbeddedFile paths
#[cfg(feature = "always-embed")]
{
// Just verify the methods work - the actual compressed data depends on build configuration
let _gzip_result = file.data_gzip();
let _br_result = file.data_br();
let _zstd_result = file.data_zstd();
}
// Ensure we have actual data though
let actual_data = file.data();
assert!(!actual_data.is_empty());
}
#[test]
fn specific_dynamic_none_coverage() {
// Create a DynamicFile directly to ensure we test the None paths
use rust_embed_for_web::{DynamicFile, EmbedableFile};
let file = DynamicFile::read_from_fs("examples/public/index.html").unwrap();
// These should all return None for DynamicFile, ensuring coverage of those lines
assert!(file.data_gzip().is_none());
assert!(file.data_br().is_none());
assert!(file.data_zstd().is_none());
// But the regular data should work
assert!(!file.data().is_empty());
}