| 1 | use std::{collections::BTreeSet, path::Path}; |
| 2 | use zipelo_ui_memory_app::{ |
| 3 | archive_dialog::archive_filters, |
| 4 | archive_present::{gzip_output_name, valid_output_leaf}, |
| 5 | }; |
| 6 | |
| 7 | #[test] |
| 8 | fn archive_filter_contains_every_case_variant_and_all_files_option() { |
| 9 | let filters = archive_filters(); |
| 10 | assert_eq!(filters.len(), 2); |
| 11 | assert_eq!(filters[0].0, "압축파일"); |
| 12 | let expected = [ |
| 13 | "zip", "ziP", "zIp", "zIP", "Zip", "ZiP", "ZIp", "ZIP", "7z", "7Z", "tar", "taR", "tAr", |
| 14 | "tAR", "Tar", "TaR", "TAr", "TAR", "gz", "gZ", "Gz", "GZ", "tgz", "tgZ", "tGz", "tGZ", |
| 15 | "Tgz", "TgZ", "TGz", "TGZ", |
| 16 | ] |
| 17 | .into_iter() |
| 18 | .map(str::to_owned) |
| 19 | .collect::<BTreeSet<_>>(); |
| 20 | assert_eq!( |
| 21 | filters[0].1.iter().cloned().collect::<BTreeSet<_>>(), |
| 22 | expected |
| 23 | ); |
| 24 | assert_eq!(filters[0].1.len(), expected.len()); |
| 25 | assert_eq!(filters[1], ("모든 파일", vec!["*".to_owned()])); |
| 26 | } |
| 27 | |
| 28 | #[test] |
| 29 | fn gzip_suggested_names_are_portable_and_preserve_valid_stems() { |
| 30 | for name in [ |
| 31 | ".gz", |
| 32 | ".GZ", |
| 33 | "report:2026.gz", |
| 34 | "report?2026.gz", |
| 35 | "CON.gz", |
| 36 | "COM1.gz", |
| 37 | "name..gz", |
| 38 | "name .gz", |
| 39 | ] { |
| 40 | assert_eq!( |
| 41 | gzip_output_name(Path::new(name)), |
| 42 | "압축 해제 파일", |
| 43 | "{name}" |
| 44 | ); |
| 45 | } |
| 46 | for (name, expected) in [ |
| 47 | ("report.gz", "report"), |
| 48 | ("report.GZ", "report"), |
| 49 | ("report.Gz", "report"), |
| 50 | ("한글.gz", "한글"), |
| 51 | ("input.archive", "input.archive"), |
| 52 | ] { |
| 53 | assert_eq!(gzip_output_name(Path::new(name)), expected); |
| 54 | } |
| 55 | for name in [ |
| 56 | "", |
| 57 | ".", |
| 58 | "..", |
| 59 | "../file", |
| 60 | "dir/file", |
| 61 | "dir\\file", |
| 62 | "a:b", |
| 63 | "a*", |
| 64 | "a?", |
| 65 | "a|b", |
| 66 | "a<b", |
| 67 | "a>b", |
| 68 | "a\"b", |
| 69 | "NUL.txt", |
| 70 | "name.", |
| 71 | "name ", |
| 72 | "control\n", |
| 73 | ] { |
| 74 | assert!(!valid_output_leaf(name), "{name:?}"); |
| 75 | } |
| 76 | assert!(valid_output_leaf("사용자 이름.txt")); |
| 77 | } |