추출 요청과 완료 판정의 선택 범위를 일치시킴
- 작성자
- 호시노 히나타
- 작성 시각
- 커밋
ea7f5213871c65aab62b1c73ce5e0b90badb53d5- 부모
- d90f1d6
변경된 파일 5개
+204-71| @@ -98,75 +98,45 @@ pub fn remove_owned_empty(path: &Path) { | ||
| 98 | 98 | let _ = fs::remove_dir(path); |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 추가: fn requested(entry: &Entry, selection: &Selection) -> bool { | |
| 102 | 추가: match selection { | |
| 103 | 추가: Selection::All => true, | |
| 104 | 추가: Selection::EntryIds(ids) => ids.contains(&entry.id), | |
| 105 | 추가: } | |
| 106 | 추가: } | |
| 107 | 추가: | |
| 101 | 108 | pub fn target_files( |
| 102 | 109 | entries: &[Entry], |
| 103 | 삭제: selected: &BTreeSet<u32>, | |
| 104 | 삭제: only: bool, | |
| 110 | 추가: selection: &Selection, | |
| 105 | 111 | gzip: Option<&str>, |
| 106 | 112 | ) -> Option<BTreeSet<String>> { |
| 107 | 삭제: let selected_names = entries | |
| 108 | 삭제: .iter() | |
| 109 | 삭제: .filter(|e| selected.contains(&e.id)) | |
| 110 | 삭제: .map(|e| (e.name.as_str(), e.kind)) | |
| 111 | 삭제: .collect::<Vec<_>>(); | |
| 112 | 113 | let mut names = BTreeSet::new(); |
| 113 | 삭제: for entry in entries.iter().filter(|e| e.kind == Kind::File) { | |
| 114 | 삭제: let included = !only | |
| 115 | 삭제: || selected_names.iter().any(|(name, kind)| { | |
| 116 | 삭제: *name == entry.name | |
| 117 | 삭제: || (*kind == Kind::Directory | |
| 118 | 삭제: && entry | |
| 119 | 삭제: .name | |
| 120 | 삭제: .starts_with(&format!("{}/", name.trim_end_matches('/')))) | |
| 121 | 삭제: }); | |
| 122 | 삭제: if included && !names.insert(gzip.unwrap_or(&entry.name).replace('\\', "/")) { | |
| 114 | 추가: for entry in entries | |
| 115 | 추가: .iter() | |
| 116 | 추가: .filter(|entry| entry.kind == Kind::File && requested(entry, selection)) | |
| 117 | 추가: { | |
| 118 | 추가: if !names.insert(gzip.unwrap_or(&entry.name).replace('\\', "/")) { | |
| 123 | 119 | return None; |
| 124 | 120 | } |
| 125 | 121 | } |
| 126 | 122 | Some(names) |
| 127 | 123 | } |
| 128 | 124 | |
| 129 | 삭제: pub fn target_directories( | |
| 130 | 삭제: entries: &[Entry], | |
| 131 | 삭제: selected: &BTreeSet<u32>, | |
| 132 | 삭제: only: bool, | |
| 133 | 삭제: ) -> BTreeSet<String> { | |
| 134 | 삭제: let selected_directories = entries | |
| 135 | 삭제: .iter() | |
| 136 | 삭제: .filter(|entry| entry.kind == Kind::Directory && selected.contains(&entry.id)) | |
| 137 | 삭제: .map(|entry| { | |
| 138 | 삭제: entry | |
| 139 | 삭제: .name | |
| 140 | 삭제: .replace('\\', "/") | |
| 141 | 삭제: .trim_end_matches('/') | |
| 142 | 삭제: .to_owned() | |
| 143 | 삭제: }) | |
| 144 | 삭제: .collect::<BTreeSet<_>>(); | |
| 125 | 추가: pub fn target_directories(entries: &[Entry], selection: &Selection) -> BTreeSet<String> { | |
| 145 | 126 | let mut directories = BTreeSet::new(); |
| 146 | 삭제: for entry in entries | |
| 147 | 삭제: .iter() | |
| 148 | 삭제: .filter(|entry| matches!(entry.kind, Kind::File | Kind::Directory)) | |
| 149 | 삭제: { | |
| 127 | 추가: for entry in entries.iter().filter(|entry| { | |
| 128 | 추가: matches!(entry.kind, Kind::File | Kind::Directory) && requested(entry, selection) | |
| 129 | 추가: }) { | |
| 150 | 130 | let normalized = entry.name.replace('\\', "/"); |
| 151 | 131 | let name = normalized.trim_end_matches('/'); |
| 132 | 추가: if entry.kind == Kind::Directory { | |
| 133 | 추가: directories.insert(name.to_owned()); | |
| 134 | 추가: } | |
| 152 | 135 | let mut parent = name; |
| 153 | 삭제: let mut ancestors = Vec::new(); | |
| 154 | 136 | while let Some((directory, _)) = parent.rsplit_once('/') { |
| 155 | 삭제: ancestors.push(directory); | |
| 137 | 추가: directories.insert(directory.to_owned()); | |
| 156 | 138 | parent = directory; |
| 157 | 139 | } |
| 158 | 삭제: if only | |
| 159 | 삭제: && !selected.contains(&entry.id) | |
| 160 | 삭제: && !ancestors | |
| 161 | 삭제: .iter() | |
| 162 | 삭제: .any(|directory| selected_directories.contains(*directory)) | |
| 163 | 삭제: { | |
| 164 | 삭제: continue; | |
| 165 | 삭제: } | |
| 166 | 삭제: if entry.kind == Kind::Directory { | |
| 167 | 삭제: directories.insert(name.to_owned()); | |
| 168 | 삭제: } | |
| 169 | 삭제: directories.extend(ancestors.into_iter().map(str::to_owned)); | |
| 170 | 140 | } |
| 171 | 141 | directories |
| 172 | 142 | } |
| @@ -160,29 +160,25 @@ impl ArchiveApp { | ||
| 160 | 160 | .list_id |
| 161 | 161 | .as_ref() |
| 162 | 162 | .is_some_and(|id| id.format == Format::Gzip); |
| 163 | 추가: let selection = if self.selected_only { | |
| 164 | 추가: Selection::EntryIds(self.model.selected.iter().copied().collect()) | |
| 165 | 추가: } else { | |
| 166 | 추가: Selection::All | |
| 167 | 추가: }; | |
| 163 | 168 | self.targets = present::target_files( |
| 164 | 169 | &self.model.entries, |
| 165 | 삭제: &self.model.selected, | |
| 166 | 삭제: self.selected_only, | |
| 170 | 추가: &selection, | |
| 167 | 171 | gzip.then_some(self.gzip_name.as_str()), |
| 168 | 172 | ); |
| 169 | 173 | self.directories = if gzip { |
| 170 | 174 | BTreeSet::new() |
| 171 | 175 | } else { |
| 172 | 삭제: present::target_directories( | |
| 173 | 삭제: &self.model.entries, | |
| 174 | 삭제: &self.model.selected, | |
| 175 | 삭제: self.selected_only, | |
| 176 | 삭제: ) | |
| 176 | 추가: present::target_directories(&self.model.entries, &selection) | |
| 177 | 177 | }; |
| 178 | 178 | let request = Start::Extract { |
| 179 | 179 | archive: self.model.archive.clone().unwrap(), |
| 180 | 180 | destination: self.destination.clone(), |
| 181 | 삭제: selection: if self.selected_only { | |
| 182 | 삭제: Selection::EntryIds(self.model.selected.iter().copied().collect()) | |
| 183 | 삭제: } else { | |
| 184 | 삭제: Selection::All | |
| 185 | 삭제: }, | |
| 181 | 추가: selection, | |
| 186 | 182 | list_id: self.model.list_id.clone().unwrap(), |
| 187 | 183 | gzip_output_name: gzip.then(|| self.gzip_name.clone()), |
| 188 | 184 | }; |
| @@ -58,6 +58,7 @@ fn binary(name: &str) -> PathBuf { | ||
| 58 | 58 | #[derive(Default)] |
| 59 | 59 | struct Observation { |
| 60 | 60 | jobs: Vec<Vec<&'static str>>, |
| 61 | 추가: starts: Vec<Start>, | |
| 61 | 62 | } |
| 62 | 63 | struct ObservedFactory { |
| 63 | 64 | process: ProcessFactory, |
| @@ -82,6 +83,9 @@ impl Factory for ObservedFactory { | ||
| 82 | 83 | } |
| 83 | 84 | impl Connection for ObservedConnection { |
| 84 | 85 | fn send(&mut self, request: Request) -> Result<(), String> { |
| 86 | 추가: if let Command::Start(start) = &request.command { | |
| 87 | 추가: self.observed.borrow_mut().starts.push(start.clone()); | |
| 88 | 추가: } | |
| 85 | 89 | self.connection.send(request) |
| 86 | 90 | } |
| 87 | 91 | fn poll(&mut self) -> Option<HostEvent> { |
| @@ -287,6 +291,7 @@ mod screen { | ||
| 287 | 291 | } |
| 288 | 292 | } |
| 289 | 293 | include!("password_flows.rs"); |
| 294 | 추가: include!("selection_flows.rs"); | |
| 290 | 295 | |
| 291 | 296 | fn archive_flow(name: &str, format: Format) { |
| 292 | 297 | let scratch = Scratch::new(); |
| @@ -0,0 +1,148 @@ | ||
| 1 | 추가: #[test] | |
| 2 | 추가: fn extraction_completion_matches_actual_worker_selection_matrix() { | |
| 3 | 추가: use std::collections::BTreeSet; | |
| 4 | 추가: | |
| 5 | 추가: fn contents(root: &Path) -> BTreeSet<String> { | |
| 6 | 추가: fn visit(root: &Path, current: &Path, found: &mut BTreeSet<String>) { | |
| 7 | 추가: for entry in fs::read_dir(current).unwrap() { | |
| 8 | 추가: let path = entry.unwrap().path(); | |
| 9 | 추가: found.insert( | |
| 10 | 추가: path.strip_prefix(root) | |
| 11 | 추가: .unwrap() | |
| 12 | 추가: .to_str() | |
| 13 | 추가: .unwrap() | |
| 14 | 추가: .replace('\\', "/"), | |
| 15 | 추가: ); | |
| 16 | 추가: if path.is_dir() { | |
| 17 | 추가: visit(root, &path, found); | |
| 18 | 추가: } | |
| 19 | 추가: } | |
| 20 | 추가: } | |
| 21 | 추가: let mut found = BTreeSet::new(); | |
| 22 | 추가: visit(root, root, &mut found); | |
| 23 | 추가: found | |
| 24 | 추가: } | |
| 25 | 추가: | |
| 26 | 추가: let scratch = Scratch::new(); | |
| 27 | 추가: let docs = make_directory(&scratch.path("docs")); | |
| 28 | 추가: fs::create_dir(docs.join("empty")).unwrap(); | |
| 29 | 추가: fs::create_dir(docs.join("nested")).unwrap(); | |
| 30 | 추가: fs::write(docs.join("nested/one.txt"), b"nested content").unwrap(); | |
| 31 | 추가: let root_file = scratch.path("root.txt"); | |
| 32 | 추가: fs::write(&root_file, b"root content").unwrap(); | |
| 33 | 추가: let archive = scratch.path("selection.zip"); | |
| 34 | 추가: let (factory, observed) = observed_factory(); | |
| 35 | 추가: let mut screen = Screen::new(factory); | |
| 36 | 추가: screen.app.add_sources(vec![docs, root_file]); | |
| 37 | 추가: screen.render(vec![]); | |
| 38 | 추가: screen.set_text("zip-name", "selection.zip"); | |
| 39 | 추가: screen.click("만들기"); | |
| 40 | 추가: screen.settle(); | |
| 41 | 추가: | |
| 42 | 추가: let cases: [(&str, Option<&[&str]>, &[&str]); 6] = [ | |
| 43 | 추가: ( | |
| 44 | 추가: "all", | |
| 45 | 추가: None, | |
| 46 | 추가: &[ | |
| 47 | 추가: "docs", | |
| 48 | 추가: "docs/empty", | |
| 49 | 추가: "docs/nested", | |
| 50 | 추가: "docs/nested/one.txt", | |
| 51 | 추가: "root.txt", | |
| 52 | 추가: ], | |
| 53 | 추가: ), | |
| 54 | 추가: ( | |
| 55 | 추가: "files", | |
| 56 | 추가: Some(&["docs/nested/one.txt", "root.txt"]), | |
| 57 | 추가: &["docs", "docs/nested", "docs/nested/one.txt", "root.txt"], | |
| 58 | 추가: ), | |
| 59 | 추가: ("directory", Some(&["docs"]), &["docs"]), | |
| 60 | 추가: ( | |
| 61 | 추가: "mixed", | |
| 62 | 추가: Some(&["docs", "docs/nested/one.txt"]), | |
| 63 | 추가: &["docs", "docs/nested", "docs/nested/one.txt"], | |
| 64 | 추가: ), | |
| 65 | 추가: ("empty", Some(&["docs/empty"]), &["docs", "docs/empty"]), | |
| 66 | 추가: ( | |
| 67 | 추가: "nested-directory", | |
| 68 | 추가: Some(&["docs/nested"]), | |
| 69 | 추가: &["docs", "docs/nested"], | |
| 70 | 추가: ), | |
| 71 | 추가: ]; | |
| 72 | 추가: for (name, selected, expected) in cases { | |
| 73 | 추가: screen.open(&archive); | |
| 74 | 추가: let ids = selected.map(|names| { | |
| 75 | 추가: names | |
| 76 | 추가: .iter() | |
| 77 | 추가: .map(|name| { | |
| 78 | 추가: screen | |
| 79 | 추가: .app | |
| 80 | 추가: .model | |
| 81 | 추가: .entries | |
| 82 | 추가: .iter() | |
| 83 | 추가: .find(|entry| entry.name.trim_end_matches('/') == *name) | |
| 84 | 추가: .unwrap_or_else(|| panic!("목록 항목 누락: {name}")) | |
| 85 | 추가: .id | |
| 86 | 추가: }) | |
| 87 | 추가: .collect::<BTreeSet<_>>() | |
| 88 | 추가: }); | |
| 89 | 추가: if let Some(ids) = &ids { | |
| 90 | 추가: screen.app.model.selected = ids.clone(); | |
| 91 | 추가: screen.click("선택한 항목만 풀기"); | |
| 92 | 추가: } | |
| 93 | 추가: let output = make_directory(&scratch.path(name)); | |
| 94 | 추가: screen.extract(&output); | |
| 95 | 추가: let terminal = screen.app.model.terminal.as_ref().unwrap(); | |
| 96 | 추가: assert_eq!(terminal.outcome, Outcome::Completed, "{name}"); | |
| 97 | 추가: assert!(screen.app.model.confirmed, "{name}"); | |
| 98 | 추가: assert!(terminal.error.is_none(), "{name}"); | |
| 99 | 추가: let expected = expected | |
| 100 | 추가: .iter() | |
| 101 | 추가: .map(|name| name.to_string()) | |
| 102 | 추가: .collect::<BTreeSet<_>>(); | |
| 103 | 추가: assert_eq!(contents(&output), expected, "{name}"); | |
| 104 | 추가: let reports = screen | |
| 105 | 추가: .app | |
| 106 | 추가: .model | |
| 107 | 추가: .outputs | |
| 108 | 추가: .iter() | |
| 109 | 추가: .map(|(name, disposition)| { | |
| 110 | 추가: assert_eq!(*disposition, Disposition::Created); | |
| 111 | 추가: name.clone() | |
| 112 | 추가: }) | |
| 113 | 추가: .collect::<BTreeSet<_>>(); | |
| 114 | 추가: assert_eq!(reports, expected, "{name}"); | |
| 115 | 추가: assert_eq!(terminal.created_count as usize, expected.len(), "{name}"); | |
| 116 | 추가: for (path, bytes) in [ | |
| 117 | 추가: ("docs/nested/one.txt", b"nested content".as_slice()), | |
| 118 | 추가: ("root.txt", b"root content".as_slice()), | |
| 119 | 추가: ] { | |
| 120 | 추가: if expected.contains(path) { | |
| 121 | 추가: assert_eq!(fs::read(output.join(path)).unwrap(), bytes, "{name}"); | |
| 122 | 추가: } | |
| 123 | 추가: } | |
| 124 | 추가: match observed.borrow().starts.last().unwrap() { | |
| 125 | 추가: Start::Extract { selection, .. } => match (selection, &ids) { | |
| 126 | 추가: (Selection::All, None) => {} | |
| 127 | 추가: (Selection::EntryIds(actual), Some(ids)) => { | |
| 128 | 추가: assert_eq!(actual, &ids.iter().copied().collect::<Vec<_>>(), "{name}"); | |
| 129 | 추가: } | |
| 130 | 추가: _ => panic!("요청 선택 범위 불일치: {name}"), | |
| 131 | 추가: }, | |
| 132 | 추가: _ => panic!("추출 요청 누락: {name}"), | |
| 133 | 추가: } | |
| 134 | 추가: let shown = screen.render(vec![]); | |
| 135 | 추가: assert!( | |
| 136 | 추가: shown.iter().any(|(text, _)| text == "압축을 풀었습니다"), | |
| 137 | 추가: "{name}: {shown:?}" | |
| 138 | 추가: ); | |
| 139 | 추가: assert!( | |
| 140 | 추가: !shown | |
| 141 | 추가: .iter() | |
| 142 | 추가: .any(|(text, _)| text.contains("저장이 끝났는지") || text.contains("일부 파일만")), | |
| 143 | 추가: "{name}" | |
| 144 | 추가: ); | |
| 145 | 추가: screen.click("확인"); | |
| 146 | 추가: } | |
| 147 | 추가: assert_reaped(&observed); | |
| 148 | 추가: } |
| @@ -148,7 +148,7 @@ fn every_error_and_stage_has_user_facing_text() { | ||
| 148 | 148 | assert_eq!(progress_text(Stage::Decode, false), "압축을 푸는 중"); |
| 149 | 149 | } |
| 150 | 150 | #[test] |
| 151 | 삭제: fn folder_selection_expands_only_matching_descendants() { | |
| 151 | 추가: fn file_targets_follow_requested_ids_without_expanding_directories() { | |
| 152 | 152 | let entries = vec![ |
| 153 | 153 | Entry { |
| 154 | 154 | id: 0, |
| @@ -176,9 +176,25 @@ fn folder_selection_expands_only_matching_descendants() { | ||
| 176 | 176 | }, |
| 177 | 177 | ]; |
| 178 | 178 | assert_eq!( |
| 179 | 삭제: target_files(&entries, &[0].into_iter().collect(), true, None), | |
| 179 | 추가: target_files(&entries, &Selection::EntryIds(vec![0]), None), | |
| 180 | 추가: Some(BTreeSet::new()) | |
| 181 | 추가: ); | |
| 182 | 추가: assert_eq!( | |
| 183 | 추가: target_files(&entries, &Selection::EntryIds(vec![0, 2]), None), | |
| 184 | 추가: Some(["docs-old/two.txt".into()].into_iter().collect()) | |
| 185 | 추가: ); | |
| 186 | 추가: assert_eq!( | |
| 187 | 추가: target_files(&entries, &Selection::EntryIds(vec![1]), None), | |
| 180 | 188 | Some(["docs/one.txt".into()].into_iter().collect()) |
| 181 | 189 | ); |
| 190 | 추가: assert_eq!( | |
| 191 | 추가: target_files(&entries, &Selection::All, None), | |
| 192 | 추가: Some( | |
| 193 | 추가: ["docs/one.txt".into(), "docs-old/two.txt".into()] | |
| 194 | 추가: .into_iter() | |
| 195 | 추가: .collect() | |
| 196 | 추가: ) | |
| 197 | 추가: ); | |
| 182 | 198 | } |
| 183 | 199 | |
| 184 | 200 | #[test] |
| @@ -277,13 +293,11 @@ fn directory_targets_include_selected_members_and_implicit_parents() { | ||
| 277 | 293 | }, |
| 278 | 294 | ]; |
| 279 | 295 | assert_eq!( |
| 280 | 삭제: target_directories(&entries, &[0].into_iter().collect(), true), | |
| 281 | 삭제: ["top".into(), "top/empty".into(), "top/nested".into()] | |
| 282 | 삭제: .into_iter() | |
| 283 | 삭제: .collect() | |
| 296 | 추가: target_directories(&entries, &Selection::EntryIds(vec![0])), | |
| 297 | 추가: ["top".into()].into_iter().collect() | |
| 284 | 298 | ); |
| 285 | 299 | assert_eq!( |
| 286 | 삭제: target_directories(&entries, &[2].into_iter().collect(), true), | |
| 300 | 추가: target_directories(&entries, &Selection::EntryIds(vec![2])), | |
| 287 | 301 | ["top".into(), "top/nested".into()].into_iter().collect() |
| 288 | 302 | ); |
| 289 | 303 | } |
| @@ -298,7 +312,7 @@ fn duplicate_names_prevent_file_completion_assumptions() { | ||
| 298 | 312 | packed: None, |
| 299 | 313 | encrypted: false, |
| 300 | 314 | }; |
| 301 | 삭제: assert!(target_files(&[entry.clone(), entry], &BTreeSet::new(), false, None).is_none()); | |
| 315 | 추가: assert!(target_files(&[entry.clone(), entry], &Selection::All, None).is_none()); | |
| 302 | 316 | assert_eq!( |
| 303 | 317 | warnings(Some(&terminal()), true, None, &BTreeSet::new(), &[]), |
| 304 | 318 | vec![UNCERTAIN] |