@@ -29,7 +29,7 @@ pub fn get(path: &str) -> Option<&'static [u8]> {
29
29
pub fn get_by_name ( filename : & str ) -> Option < & ' static [ u8 ] > {
30
30
FILES
31
31
. iter ( )
32
- . find ( |& & ( p, _) | p. split ( '/' ) . last ( ) == Some ( filename) )
32
+ . find ( |& & ( p, _) | p. split ( '/' ) . next_back ( ) == Some ( filename) )
33
33
. map ( |& ( _, d) | d)
34
34
}
35
35
@@ -46,8 +46,8 @@ pub fn fonts() -> impl Iterator<Item = &'static [u8]> {
46
46
files ! {
47
47
"bib/bad.bib" ,
48
48
"bib/scifi-authors.yaml" ,
49
- "bib/works_too.bib" ,
50
49
"bib/works.bib" ,
50
+ "bib/works_too.bib" ,
51
51
"data/bad.csv" ,
52
52
"data/bad.json" ,
53
53
"data/bad.toml" ,
@@ -111,13 +111,13 @@ files! {
111
111
"images/molecular.jpg" ,
112
112
"images/monkey.svg" ,
113
113
"images/pattern.svg" ,
114
- "images/rhino.png" ,
115
114
"images/relative.svg" ,
115
+ "images/rhino.png" ,
116
116
"images/tetrahedron.svg" ,
117
117
"images/tiger.jpg" ,
118
118
"images/typing.jpg" ,
119
- "plugins/hello.wasm" ,
120
119
"plugins/hello-mut.wasm" ,
120
+ "plugins/hello.wasm" ,
121
121
"plugins/plugin-oob.wasm" ,
122
122
"screenshots/1-writing-app.png" ,
123
123
"screenshots/1-writing-upload.png" ,
@@ -133,6 +133,8 @@ files! {
133
133
134
134
#[ cfg( test) ]
135
135
mod tests {
136
+ use std:: path:: { Path , PathBuf } ;
137
+
136
138
use super :: * ;
137
139
138
140
#[ test]
@@ -146,4 +148,45 @@ mod tests {
146
148
assert ! ( get( "data\\ zoo.csv" ) . is_some( ) ) ;
147
149
assert ! ( get( "data\\ zoos.csv" ) . is_none( ) ) ;
148
150
}
151
+
152
+ #[ test]
153
+ fn test_list_sorted ( ) {
154
+ for window in FILES . windows ( 2 ) {
155
+ let ( a, _) = window[ 0 ] ;
156
+ let ( b, _) = window[ 1 ] ;
157
+ if a > b {
158
+ panic ! ( "{a:?} and {b:?} are out of order" ) ;
159
+ }
160
+ }
161
+ }
162
+
163
+ #[ test]
164
+ fn test_all_files_included ( ) {
165
+ let root = Path :: new ( "files" ) ;
166
+ walk ( root, & mut |path| {
167
+ let stringified = path
168
+ . strip_prefix ( root)
169
+ . unwrap ( )
170
+ . to_string_lossy ( )
171
+ . replace ( std:: path:: MAIN_SEPARATOR_STR , "/" ) ;
172
+ let data = std:: fs:: read ( & path) . unwrap ( ) ;
173
+ if get ( & stringified) != Some ( data. as_slice ( ) ) {
174
+ panic ! ( "{} is not listed in {}" , path. display( ) , file!( ) ) ;
175
+ }
176
+ } )
177
+ }
178
+
179
+ fn walk ( dir : & Path , f : & mut impl FnMut ( PathBuf ) ) {
180
+ for entry in std:: fs:: read_dir ( dir) . unwrap ( ) {
181
+ let path = entry. unwrap ( ) . path ( ) ;
182
+ if path. is_dir ( ) {
183
+ walk ( & path, f) ;
184
+ } else if let Some ( stem) = path. file_stem ( )
185
+ && let Some ( stem_str) = stem. to_str ( )
186
+ && !stem_str. starts_with ( "." )
187
+ {
188
+ f ( path) ;
189
+ }
190
+ }
191
+ }
149
192
}
0 commit comments