gitpoulpi-config 1.3.0

GitPoulpi config schema, TOML load/save, defaults, and OS-correct path resolution.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
//! The Windows "Open with" list, from the registry.
//!
//! For an extension `.pdf`:
//!
//! - the default is the `ProgId` of
//!   `HKCU\...\Explorer\FileExts\.pdf\UserChoice`, else the default value of
//!   `HKCR\.pdf`;
//! - the others are the value names of `HKCR\.pdf\OpenWithProgids` and of
//!   `...\FileExts\.pdf\OpenWithProgids`, the programs of
//!   `...\FileExts\.pdf\OpenWithList` (values `a`, `b`, ... except `MRUList`)
//!   and the sub keys of `HKCR\.pdf\OpenWithList`; a program `x.exe` is the
//!   ProgId `Applications\x.exe`;
//! - a ProgId is run through `HKCR\<ProgId>\shell\open\command`. One without a
//!   command (a packaged app that registers a `DelegateExecute`) can not be
//!   launched from here; when it is the default the list still offers
//!   Windows' own `start`, which does open it.
//!
//! The registry is a parameter ([`Registry`]); the real reader (`reg.exe`)
//! lives in the TUI, behind `cfg(windows)`, and its output parser
//! ([`parse_reg_query`]) is here so Linux tests cover it.

use super::{exe_key, quote_arg, Found, OsApp};

/// What the parser reads of the registry. Key paths are
/// `HKCR\.pdf\OpenWithProgids` style; names compare without regard to case.
pub trait Registry {
    /// The names of the sub keys of `key`.
    fn subkeys(&self, key: &str) -> Vec<String>;
    /// The values of `key` as `(name, data)`; the default value's name is "".
    fn values(&self, key: &str) -> Vec<(String, String)>;
}

const FILE_EXTS: &str = r"HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts";

fn value(reg: &dyn Registry, key: &str, name: &str) -> Option<String> {
    reg.values(key)
        .into_iter()
        .find(|(n, _)| n.eq_ignore_ascii_case(name))
        .map(|(_, v)| v)
        .filter(|v| !v.is_empty())
}

/// `%NAME%` replaced from `env` (an unknown variable stays as written).
pub fn expand_percent_vars(text: &str, env: &dyn Fn(&str) -> Option<String>) -> String {
    let mut out = String::new();
    let mut rest = text;
    while let Some(start) = rest.find('%') {
        out.push_str(&rest[..start]);
        let after = &rest[start + 1..];
        match after.find('%') {
            Some(end)
                if end > 0
                    && after[..end]
                        .chars()
                        .all(|c| c.is_ascii_alphanumeric() || c == '_' || c == '(' || c == ')')
                    && !after[..end].chars().all(|c| c.is_ascii_digit()) =>
            {
                match env(&after[..end]) {
                    Some(v) => out.push_str(&v),
                    None => {
                        out.push('%');
                        out.push_str(&after[..end]);
                        out.push('%');
                    }
                }
                rest = &after[end + 1..];
            }
            _ => {
                out.push('%');
                rest = after;
            }
        }
    }
    out.push_str(rest);
    out
}

/// A `shell\open\command` as an argv template: `%1`, `%L`, `%l`, `%V` and `%*`
/// become `${file}`, the other positional codes go, `%VAR%` is expanded, and a
/// command with no file code gets the file as its last (quoted) argument.
pub fn command_template(command: &str, env: &dyn Fn(&str) -> Option<String>) -> Option<String> {
    let command = expand_percent_vars(command.trim(), env);
    let mut out = String::new();
    let mut chars = command.chars().peekable();
    while let Some(c) = chars.next() {
        if c != '%' {
            out.push(c);
            continue;
        }
        match chars.peek().copied() {
            Some('1' | 'L' | 'l' | 'V' | 'v' | '*') => {
                chars.next();
                out.push_str("${file}");
            }
            Some(d) if d.is_ascii_digit() => {
                chars.next();
            }
            Some('%') => {
                chars.next();
                out.push('%');
            }
            _ => out.push('%'),
        }
    }
    let out = out.trim().to_string();
    if out.is_empty() {
        return None;
    }
    let out = if out.contains("${file}") {
        out
    } else {
        format!("{out} \"${{file}}\"")
    };
    // The command must split, and name no variable but the file.
    let argv = crate::launch::split_argv(&out).ok()?;
    if argv.is_empty() || argv[0].contains("${") {
        return None;
    }
    if argv.iter().any(|a| a.replace("${file}", "").contains("${")) {
        return None;
    }
    Some(out)
}

/// `Viewer.exe` -> `Viewer`, `acrord32` -> `Acrord32`.
fn exe_title(exe: &str) -> String {
    let base = exe.rsplit(['/', '\\']).next().unwrap_or(exe);
    let stem = base
        .strip_suffix(".exe")
        .or_else(|| base.strip_suffix(".EXE"))
        .unwrap_or(base);
    let mut chars = stem.chars();
    match chars.next() {
        Some(first) if first.is_lowercase() => first.to_uppercase().chain(chars).collect(),
        Some(first) => first.to_string() + chars.as_str(),
        None => String::new(),
    }
}

/// The command key a ProgId runs: `shell\open`, else the default verb.
fn command_of(reg: &dyn Registry, prog_id: &str) -> Option<String> {
    let shell = format!(r"HKCR\{prog_id}\shell");
    if let Some(c) = value(reg, &format!(r"{shell}\open\command"), "") {
        return Some(c);
    }
    let verb = value(reg, &shell, "")?;
    value(reg, &format!(r"{shell}\{verb}\command"), "")
}

/// A friendly name the registry gives the application, if it is a plain string
/// (`@shell32.dll,-1234` references need the resource loader).
fn friendly_name(reg: &dyn Registry, prog_id: &str) -> Option<String> {
    let plain = |v: String| (!v.starts_with('@')).then_some(v);
    let open = format!(r"HKCR\{prog_id}\shell\open");
    value(reg, &format!(r"HKCR\{prog_id}"), "FriendlyAppName")
        .and_then(plain)
        .or_else(|| value(reg, &open, "FriendlyAppName").and_then(plain))
        .or_else(|| value(reg, &open, "MUIVerb").and_then(plain))
}

/// The applications for the extension `ext` (with or without the dot).
pub fn apps_for(ext: &str, reg: &dyn Registry, env: &dyn Fn(&str) -> Option<String>) -> Found {
    let ext = ext.trim_start_matches('.').to_lowercase();
    if ext.is_empty() {
        return Found::default();
    }
    let dot = format!(".{ext}");
    let class = format!(r"HKCR\{dot}");
    let exts = format!(r"{FILE_EXTS}\{dot}");

    let textual = value(reg, &class, "PerceivedType")
        .is_some_and(|t| t.eq_ignore_ascii_case("text"))
        || value(reg, &class, "Content Type").is_some_and(|t| t.starts_with("text/"));

    let chosen =
        value(reg, &format!(r"{exts}\UserChoice"), "ProgId").or_else(|| value(reg, &class, ""));

    let mut ids: Vec<String> = Vec::new();
    ids.extend(chosen.clone());
    for key in [
        format!(r"{class}\OpenWithProgids"),
        format!(r"{exts}\OpenWithProgids"),
    ] {
        ids.extend(reg.values(&key).into_iter().map(|(name, _)| name));
    }
    for (name, data) in reg.values(&format!(r"{exts}\OpenWithList")) {
        if !name.eq_ignore_ascii_case("MRUList") && !data.is_empty() {
            ids.push(format!(r"Applications\{data}"));
        }
    }
    for exe in reg.subkeys(&format!(r"{class}\OpenWithList")) {
        ids.push(format!(r"Applications\{exe}"));
    }

    let mut seen: Vec<String> = Vec::new();
    let mut apps = Vec::new();
    let mut default_resolved = false;
    for id in ids {
        let lower = id.to_lowercase();
        if id.is_empty() || seen.contains(&lower) {
            continue;
        }
        seen.push(lower);
        let is_default = chosen.as_ref().is_some_and(|c| c.eq_ignore_ascii_case(&id));
        let Some(command) = command_of(reg, &id) else {
            continue;
        };
        let Some(template) = command_template(&command, env) else {
            continue;
        };
        let argv = crate::launch::split_argv(&template).unwrap_or_default();
        let exe = argv.first().cloned().unwrap_or_default();
        let name = friendly_name(reg, &id)
            .or_else(|| {
                id.strip_prefix(r"Applications\")
                    .and_then(|app| friendly_name(reg, &format!(r"Applications\{app}")))
            })
            .unwrap_or_else(|| exe_title(&exe));
        default_resolved |= is_default;
        apps.push(OsApp {
            name,
            key: exe_key(&argv),
            command: template,
            default: is_default,
        });
    }
    // The user's choice exists but can not be run from here (a packaged app):
    // Windows' own `start` opens it.
    if chosen.is_some() && !default_resolved {
        apps.push(OsApp {
            name: "Default app".into(), // i18n-english
            command: format!("cmd /C start \"\" {}", quote_arg("${file}")),
            key: "cmd".into(),
            default: true,
        });
    }
    Found { apps, textual }.finish()
}

/// Parses the output of `reg query <key>`: the sub keys (full paths, one per
/// line, starting with `HKEY_`) and the values (`    Name    REG_SZ    Data`;
/// the default value is `(Default)` or `<NO NAME>`). Only string values
/// (`REG_SZ`, `REG_EXPAND_SZ`) carry data; others have an empty one.
pub fn parse_reg_query(output: &str) -> (Vec<String>, Vec<(String, String)>) {
    let mut subkeys = Vec::new();
    let mut values = Vec::new();
    // The first non-empty line is the key itself.
    let mut first = true;
    for line in output.lines() {
        if line.trim().is_empty() {
            continue;
        }
        if !line.starts_with(' ') {
            if first {
                first = false;
            } else if let Some((_, tail)) = line.trim_end().rsplit_once('\\') {
                subkeys.push(tail.to_string());
            }
            continue;
        }
        first = false;
        let body = line.trim_start();
        // Name and type are separated by four spaces; the data by four more.
        let Some((name, rest)) = split_value_line(body) else {
            continue;
        };
        let (kind, data) = rest.split_once("    ").unwrap_or((rest, ""));
        let data = if kind == "REG_SZ" || kind == "REG_EXPAND_SZ" {
            data.trim().to_string()
        } else {
            String::new()
        };
        // `(Default)` is worded by the system's language.
        let name = if name == "<NO NAME>" || (name.starts_with('(') && name.ends_with(')')) {
            String::new()
        } else {
            name.to_string()
        };
        values.push((name, data));
    }
    (subkeys, values)
}

/// `Name    REG_SZ    Data` -> (`Name`, `REG_SZ    Data`): the name ends at
/// the first `REG_` type word that follows four spaces.
fn split_value_line(body: &str) -> Option<(&str, &str)> {
    let at = body.find("    REG_")?;
    Some((body[..at].trim_end(), body[at + 4..].trim_start()))
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::collections::BTreeMap;

    /// A fake registry: keys with their sub keys and values; lookups ignore case.
    #[derive(Default)]
    struct Fake {
        values: BTreeMap<String, Vec<(String, String)>>,
        keys: BTreeMap<String, Vec<String>>,
    }

    impl Fake {
        fn value(mut self, key: &str, name: &str, data: &str) -> Self {
            self.values
                .entry(key.to_lowercase())
                .or_default()
                .push((name.to_string(), data.to_string()));
            self
        }

        fn sub(mut self, key: &str, name: &str) -> Self {
            self.keys
                .entry(key.to_lowercase())
                .or_default()
                .push(name.to_string());
            self
        }
    }

    impl Registry for Fake {
        fn subkeys(&self, key: &str) -> Vec<String> {
            self.keys
                .get(&key.to_lowercase())
                .cloned()
                .unwrap_or_default()
        }

        fn values(&self, key: &str) -> Vec<(String, String)> {
            self.values
                .get(&key.to_lowercase())
                .cloned()
                .unwrap_or_default()
        }
    }

    fn env(k: &str) -> Option<String> {
        match k {
            "ProgramFiles" => Some(r"C:\Program Files".into()),
            "SystemRoot" => Some(r"C:\Windows".into()),
            _ => None,
        }
    }

    fn pdf_machine() -> Fake {
        Fake::default()
            .value(r"HKCR\.pdf", "", "AcroExch.Document.DC")
            .value(r"HKCR\.pdf\OpenWithProgids", "AcroExch.Document.DC", "")
            .value(r"HKCR\.pdf\OpenWithProgids", "MSEdgePDF", "")
            .value(
                &format!(r"{FILE_EXTS}\.pdf\UserChoice"),
                "ProgId",
                "MSEdgePDF",
            )
            .value(
                &format!(r"{FILE_EXTS}\.pdf\OpenWithList"),
                "a",
                "SumatraPDF.exe",
            )
            .value(&format!(r"{FILE_EXTS}\.pdf\OpenWithList"), "MRUList", "a")
            .sub(r"HKCR\.pdf\OpenWithList", "Foxit.exe")
            .value(
                r"HKCR\AcroExch.Document.DC\shell\open\command",
                "",
                r#""C:\Program Files\Adobe\Acrobat\Acrobat.exe" "%1""#,
            )
            .value(
                r"HKCR\MSEdgePDF\shell\open\command",
                "",
                r#""%ProgramFiles%\Edge\msedge.exe" --single-argument %1"#,
            )
            .value(r"HKCR\MSEdgePDF", "FriendlyAppName", "Microsoft Edge")
            .value(
                r"HKCR\Applications\SumatraPDF.exe\shell\open\command",
                "",
                r#""C:\Tools\SumatraPDF.exe" "%1""#,
            )
            .value(
                r"HKCR\Applications\SumatraPDF.exe",
                "FriendlyAppName",
                "Sumatra PDF",
            )
            .value(
                r"HKCR\Applications\Foxit.exe\shell\open\command",
                "",
                r#"C:\Foxit\Foxit.exe /A %1"#,
            )
    }

    #[test]
    fn the_user_choice_is_the_default_and_every_registered_program_is_listed() {
        let found = apps_for(".PDF", &pdf_machine(), &env);
        let names: Vec<_> = found.apps.iter().map(|a| a.name.as_str()).collect();
        assert_eq!(names, ["Microsoft Edge", "Acrobat", "Foxit", "Sumatra PDF"]);
        assert!(found.apps[0].default);
        assert!(found.apps[1..].iter().all(|a| !a.default));
        assert_eq!(
            found.apps[0].command,
            r#""C:\Program Files\Edge\msedge.exe" --single-argument ${file}"#
        );
        assert_eq!(found.apps[2].command, r"C:\Foxit\Foxit.exe /A ${file}");
        assert!(!found.textual);
    }

    #[test]
    fn without_a_user_choice_the_class_default_is_the_default() {
        let reg = Fake::default().value(r"HKCR\.png", "", "pngfile").value(
            r"HKCR\pngfile\shell\open\command",
            "",
            r#"mspaint.exe "%1""#,
        );
        let found = apps_for("png", &reg, &env);
        assert_eq!(found.apps.len(), 1);
        assert_eq!(found.apps[0].name, "Mspaint");
        assert!(found.apps[0].default);
    }

    #[test]
    fn a_packaged_default_without_a_command_falls_back_to_start() {
        let reg = Fake::default()
            .value(
                &format!(r"{FILE_EXTS}\.jpg\UserChoice"),
                "ProgId",
                "AppX1234",
            )
            .value(r"HKCR\.jpg\OpenWithProgids", "jpegfile", "")
            .value(
                r"HKCR\jpegfile\shell\open\command",
                "",
                r#""C:\v\view.exe" %1"#,
            );
        let found = apps_for("jpg", &reg, &env);
        assert_eq!(found.apps[0].name, "Default app");
        assert!(found.apps[0].default);
        assert_eq!(found.apps[0].command, "cmd /C start \"\" ${file}");
        assert_eq!(found.apps[1].name, "View");
    }

    #[test]
    fn an_extension_the_registry_does_not_know_has_no_apps() {
        assert!(apps_for("zzz", &pdf_machine(), &env).apps.is_empty());
        assert!(apps_for("", &pdf_machine(), &env).apps.is_empty());
    }

    #[test]
    fn text_types_are_flagged() {
        let reg = Fake::default()
            .value(r"HKCR\.txt", "", "txtfile")
            .value(r"HKCR\.txt", "PerceivedType", "text")
            .value(r"HKCR\txtfile\shell\open\command", "", r"notepad.exe %1");
        assert!(apps_for("txt", &reg, &env).textual);
    }

    #[test]
    fn commands_become_templates() {
        let t = |c: &str| command_template(c, &env);
        assert_eq!(
            t(r#""C:\a b\x.exe" "%1""#).as_deref(),
            Some(r#""C:\a b\x.exe" "${file}""#)
        );
        assert_eq!(t(r"x.exe /open %L").as_deref(), Some("x.exe /open ${file}"));
        assert_eq!(t(r"x.exe").as_deref(), Some(r#"x.exe "${file}""#));
        assert_eq!(t(r"x.exe %1 %2").as_deref(), Some("x.exe ${file}"));
        assert_eq!(
            t(r#"%SystemRoot%\system32\rundll32.exe a.dll,Open %1"#).as_deref(),
            Some(r"C:\Windows\system32\rundll32.exe a.dll,Open ${file}")
        );
        assert_eq!(
            t(r#"%Unknown%\x.exe %1"#).as_deref(),
            Some(r"%Unknown%\x.exe ${file}")
        );
        assert_eq!(t(""), None);
        assert_eq!(t(r#""unterminated %1"#), None);
    }

    /// The argv the launcher builds for `command` on `file`, and the verbatim
    /// tail a Windows spawn uses instead when there is one.
    fn run_of(command: &str, file: &str) -> (Vec<String>, Option<String>) {
        let template = command_template(command, &env).unwrap();
        let vars = crate::image_editors::ImageVars {
            file,
            dir: "",
            name: "",
            repo: "",
        };
        (
            crate::image_editors::expand(&template, &vars, &|_| None).unwrap(),
            crate::os_apps::verbatim_tail(&template, file),
        )
    }

    #[test]
    fn real_world_commands_run_with_the_path_as_one_correct_argument() {
        let file = r"C:\Users\Jo Doe\My Docs\page.html";
        let s = |v: &[&str]| v.iter().map(|x| x.to_string()).collect::<Vec<_>>();

        // Chrome and Edge read the rest of the line as the address: raw,
        // never quoted (the quote used to become `http://"c/...`).
        let (argv, raw) = run_of(
            r#""C:\Program Files\Google\Chrome\Application\chrome.exe" --single-argument %1"#,
            file,
        );
        assert_eq!(
            argv,
            s(&[
                r"C:\Program Files\Google\Chrome\Application\chrome.exe",
                "--single-argument",
                file
            ])
        );
        assert_eq!(raw, Some(format!("--single-argument {file}")));
        let (_, raw) = run_of(
            r#""C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" --single-argument %1"#,
            file,
        );
        assert_eq!(raw, Some(format!("--single-argument {file}")));
        // A quoted form of the same switch is unquoted too.
        let (_, raw) = run_of(r#"msedge.exe --single-argument "%1""#, file);
        assert_eq!(raw, Some(format!("--single-argument {file}")));

        // Firefox: its own quotes, ordinary arguments.
        let (argv, raw) = run_of(
            r#""C:\Program Files\Mozilla Firefox\firefox.exe" -osint -url "%1""#,
            file,
        );
        assert_eq!(
            argv,
            s(&[
                r"C:\Program Files\Mozilla Firefox\firefox.exe",
                "-osint",
                "-url",
                file
            ])
        );
        assert_eq!(raw, None);

        // Acrobat, Notepad, %V and a command with no placeholder.
        let (argv, raw) = run_of(r#""C:\Adobe\Acrobat.exe" "%1""#, file);
        assert_eq!(argv, s(&[r"C:\Adobe\Acrobat.exe", file]));
        assert_eq!(raw, None);
        let (argv, _) = run_of("notepad.exe %1", file);
        assert_eq!(argv, s(&["notepad.exe", file]));
        let (argv, _) = run_of(r#""C:\v\view.exe" /open %V"#, file);
        assert_eq!(argv, s(&[r"C:\v\view.exe", "/open", file]));
        let (argv, raw) = run_of(r"C:\Tools\view.exe", file);
        assert_eq!(argv, s(&[r"C:\Tools\view.exe", file]));
        assert_eq!(raw, None);
    }

    #[test]
    fn percent_variables_are_expanded_only_when_they_name_a_variable() {
        assert_eq!(expand_percent_vars("100% sure", &env), "100% sure");
        assert_eq!(
            expand_percent_vars("%1 and %SystemRoot%", &env),
            r"%1 and C:\Windows"
        );
    }

    #[test]
    fn reg_query_output_is_parsed_into_keys_and_values() {
        let out = "\r\nHKEY_CLASSES_ROOT\\.pdf\r\n    (Default)    REG_SZ    AcroExch.Document.DC\r\n    Content Type    REG_SZ    application/pdf\r\n    Flags    REG_DWORD    0x1\r\n\r\nHKEY_CLASSES_ROOT\\.pdf\\OpenWithProgids\r\nHKEY_CLASSES_ROOT\\.pdf\\OpenWithList\r\n";
        let (keys, values) = parse_reg_query(out);
        assert_eq!(keys, ["OpenWithProgids", "OpenWithList"]);
        assert_eq!(
            values,
            [
                ("".to_string(), "AcroExch.Document.DC".to_string()),
                ("Content Type".to_string(), "application/pdf".to_string()),
                ("Flags".to_string(), String::new()),
            ]
        );
        // A command with spaces and quotes keeps them.
        let out = "HKEY_CLASSES_ROOT\\x\\shell\\open\\command\r\n    (Default)    REG_SZ    \"C:\\Program Files\\a b\\x.exe\" \"%1\"\r\n";
        let (_, values) = parse_reg_query(out);
        assert_eq!(values[0].1, r#""C:\Program Files\a b\x.exe" "%1""#);
        // A value-less ProgId list.
        let out = "HKEY_CLASSES_ROOT\\.pdf\\OpenWithProgids\r\n    AcroExch.Document.DC    REG_NONE    \r\n";
        let (_, values) = parse_reg_query(out);
        assert_eq!(
            values,
            [("AcroExch.Document.DC".to_string(), String::new())]
        );
    }
}