Skip to content

Commit 4de0686

Browse files
committed
Added more tests, now 119
1 parent 90eb49d commit 4de0686

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

src/parser/path.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,21 @@ mod tests {
2525
assert_eq!(extract_title_from_path(" spaced.txt "), "spaced");
2626
assert_eq!(extract_title_from_path(""), "Untitled");
2727
}
28+
29+
#[test]
30+
fn extracts_title_from_paths_without_extension() {
31+
assert_eq!(extract_title_from_path("README"), "README");
32+
assert_eq!(extract_title_from_path("/var/log/system"), "system");
33+
}
34+
35+
#[test]
36+
fn returns_untitled_for_whitespace_only_or_trailing_separator() {
37+
assert_eq!(extract_title_from_path(" "), "Untitled");
38+
assert_eq!(extract_title_from_path(" /tmp/dir/ "), "Untitled");
39+
}
40+
41+
#[test]
42+
fn extracts_title_from_multi_dot_filename() {
43+
assert_eq!(extract_title_from_path("archive.tar.gz"), "archive.tar");
44+
}
2845
}

src/update.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,21 @@ mod tests {
203203
assert_eq!(parse_semver_value("v"), None);
204204
}
205205

206+
#[test]
207+
fn parse_semver_trims_whitespace() {
208+
assert_eq!(parse_semver_value(" v2.3.4 "), Some((2, 3, 4)));
209+
}
210+
211+
#[test]
212+
fn parse_semver_ignores_extra_segments_after_patch() {
213+
assert_eq!(parse_semver_value("1.2.3.99"), Some((1, 2, 3)));
214+
}
215+
216+
#[test]
217+
fn parse_semver_rejects_missing_major_component() {
218+
assert_eq!(parse_semver_value(".2.3"), None);
219+
}
220+
206221
#[test]
207222
fn pick_download_url_prefers_installer() {
208223
let assets = vec![
@@ -228,4 +243,30 @@ mod tests {
228243
let url = pick_download_url(false, &assets);
229244
assert_eq!(url.as_deref(), Some("https://example.com/PAPERBACK.ZIP"));
230245
}
246+
247+
#[test]
248+
fn pick_download_url_returns_none_when_preferred_asset_missing() {
249+
let assets = vec![ReleaseAsset {
250+
name: "notes.txt".to_string(),
251+
browser_download_url: "https://example.com/notes.txt".to_string(),
252+
}];
253+
assert!(pick_download_url(true, &assets).is_none());
254+
assert!(pick_download_url(false, &assets).is_none());
255+
}
256+
257+
#[test]
258+
fn pick_download_url_uses_flag_to_choose_between_exe_and_zip() {
259+
let assets = vec![
260+
ReleaseAsset {
261+
name: "paperback.zip".to_string(),
262+
browser_download_url: "https://example.com/paperback.zip".to_string(),
263+
},
264+
ReleaseAsset {
265+
name: "paperback_setup.exe".to_string(),
266+
browser_download_url: "https://example.com/paperback_setup.exe".to_string(),
267+
},
268+
];
269+
assert_eq!(pick_download_url(false, &assets).as_deref(), Some("https://example.com/paperback.zip"));
270+
assert_eq!(pick_download_url(true, &assets).as_deref(), Some("https://example.com/paperback_setup.exe"));
271+
}
231272
}

src/zip.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,31 @@ mod tests {
8383
let contents = fs::read_to_string(&output_path).expect("read output");
8484
assert_eq!(contents, "nested");
8585
}
86+
87+
#[test]
88+
fn extract_zip_entry_to_file_reports_missing_entry() {
89+
let mut archive = build_test_archive();
90+
let output_path = unique_temp_path("nested/missing.txt");
91+
assert!(extract_zip_entry_to_file(&mut archive, "does-not-exist.txt", &output_path).is_err());
92+
}
93+
94+
#[test]
95+
fn extract_zip_entry_to_file_overwrites_existing_file_contents() {
96+
let mut archive = build_test_archive();
97+
let output_path = unique_temp_path("nested/overwrite.txt");
98+
if let Some(parent) = output_path.parent() {
99+
fs::create_dir_all(parent).expect("create parent");
100+
}
101+
fs::write(&output_path, "old").expect("seed file");
102+
extract_zip_entry_to_file(&mut archive, "foo.txt", &output_path).expect("extract entry");
103+
let contents = fs::read_to_string(&output_path).expect("read output");
104+
assert_eq!(contents, "hello world");
105+
}
106+
107+
#[test]
108+
fn read_zip_entry_by_name_reads_nested_entry() {
109+
let mut archive = build_test_archive();
110+
let contents = read_zip_entry_by_name(&mut archive, "nested/bar.txt").expect("read nested entry");
111+
assert_eq!(contents, "nested");
112+
}
86113
}

0 commit comments

Comments
 (0)