1mod archive;
2mod tool;
3mod ty;
4
5pub use archive::*;
6pub use tool::*;
7pub use ty::*;
8
9#[cfg(test)]
10mod test {
11 use crate::{File, ty::Fmt};
12 use strum::IntoEnumIterator;
13
14 #[test]
15 fn test_decode() {
16 for name in std::fs::read_dir("../assets").unwrap() {
17 let path = name.unwrap().path();
18 let buffer = std::fs::read(&path).unwrap();
19 let fmt = Fmt::guess(&path.to_string_lossy()).unwrap();
20 let files = fmt.decode(buffer).unwrap();
21 let dist = files
22 .iter()
23 .find(|i| i.path == "mujs-build-0.0.11/dist-manifest.json")
24 .unwrap();
25 assert!(!dist.buffer.is_empty());
26 }
27 }
28
29 use std::path::PathBuf;
30
31 #[test]
32 fn encode_decode() {
33 for i in Fmt::iter() {
34 if i == Fmt::TarBz {
36 continue;
37 }
38 let mut v = vec![];
39 let base = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
40 let asset_dir = base.join("../assets");
41 for i in std::fs::read_dir(asset_dir).expect("read dir error") {
42 let file_path = i.expect("get path error").path();
43 let path = file_path
44 .file_name()
45 .expect("get name error")
46 .to_string_lossy()
47 .to_string();
48 let buffer = std::fs::read(&file_path).expect("read file error");
49
50 v.push(File {
51 buffer,
52 path,
53 mode: None,
54 is_dir: false,
55 last_modified: None,
56 })
57 }
58 let compress = i.encode(v).expect("zip error");
59 println!("{:?} {}", i, compress.len());
60 assert!(compress.len() > 0);
61 }
62 }
63}