poexam 0.0.12

Blazingly fast PO linter.
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
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
// SPDX-FileCopyrightText: 2026 Sébastien Helleu <flashcode@flashtux.org>
//
// SPDX-License-Identifier: GPL-3.0-or-later

//! Implementation of the whitespace rules: check inconsistent whitespace:
//! - `whitespace-start`: whitespace at the beginning of the string
//! - `whitespace-end`: whitespace at the end of the string
//! - `whitespace-line-start`: whitespace at the beginning of each interior line
//! - `whitespace-line-end`: whitespace at the end of each interior line

use crate::checker::Checker;
use crate::diagnostic::{Diagnostic, Severity};
use crate::fix::{Edit, Fix, FixTarget};
use crate::po::entry::Entry;
use crate::po::message::Message;
use crate::rules::rule::RuleChecker;

pub struct WhitespaceStartRule;

impl RuleChecker for WhitespaceStartRule {
    fn name(&self) -> &'static str {
        "whitespace-start"
    }

    fn description(&self) -> &'static str {
        "Check for inconsistent leading whitespace between source and translation."
    }

    fn is_default(&self) -> bool {
        true
    }

    fn is_check(&self) -> bool {
        true
    }

    /// Check for inconsistent leading whitespace between source and translation.
    ///
    /// Wrong entry:
    /// ```text
    /// msgid " this is a test"
    /// msgstr "ceci est un test"
    /// ```
    ///
    /// Correct entry:
    /// ```text
    /// msgid " this is a test"
    /// msgstr " ceci est un test"
    /// ```
    ///
    /// Diagnostics reported:
    /// - [`info`](Severity::Info): `inconsistent leading whitespace ('…' / '…')` (auto-fixable)
    fn check_msg(
        &self,
        checker: &Checker,
        _entry: &Entry,
        msgid: &Message,
        msgstr: &Message,
    ) -> Vec<Diagnostic> {
        if msgid.value.trim().is_empty() || msgstr.value.trim().is_empty() {
            return vec![];
        }
        let id_ws = get_whitespace_start(&msgid.value);
        let str_ws = get_whitespace_start(&msgstr.value);
        if id_ws == str_ws {
            vec![]
        } else {
            let fix = Fix {
                target: FixTarget::Msgstr {
                    file_byte_range: msgstr.byte_range.clone(),
                },
                edits: vec![Edit {
                    range: 0..str_ws.len(),
                    replacement: id_ws.to_string(),
                }],
            };
            self.new_diag(
                checker,
                Severity::Info,
                format!("inconsistent leading whitespace ('{id_ws}' / '{str_ws}')"),
            )
            .map(|d| {
                d.with_msgs_hl(msgid, [(0, id_ws.len())], msgstr, [(0, str_ws.len())])
                    .with_fix(fix)
            })
            .into_iter()
            .collect()
        }
    }
}

pub struct WhitespaceEndRule;

impl RuleChecker for WhitespaceEndRule {
    fn name(&self) -> &'static str {
        "whitespace-end"
    }

    fn description(&self) -> &'static str {
        "Check for inconsistent trailing whitespace between source and translation."
    }

    fn is_default(&self) -> bool {
        true
    }

    fn is_check(&self) -> bool {
        true
    }

    /// Check for inconsistent trailing whitespace between source and translation.
    ///
    /// Wrong entry:
    /// ```text
    /// msgid "this is a test "
    /// msgstr "ceci est un test"
    /// ```
    ///
    /// Correct entry:
    /// ```text
    /// msgid "this is a test "
    /// msgstr "ceci est un test "
    /// ```
    ///
    /// Diagnostics reported:
    /// - [`info`](Severity::Info): `inconsistent trailing whitespace ('…' / '…')` (auto-fixable)
    fn check_msg(
        &self,
        checker: &Checker,
        _entry: &Entry,
        msgid: &Message,
        msgstr: &Message,
    ) -> Vec<Diagnostic> {
        if msgid.value.trim().is_empty() || msgstr.value.trim().is_empty() {
            return vec![];
        }
        let id_ws = get_whitespace_end(&msgid.value);
        let str_ws = get_whitespace_end(&msgstr.value);
        if id_ws == str_ws {
            vec![]
        } else {
            let str_ws_start = msgstr.value.len() - str_ws.len();
            let fix = Fix {
                target: FixTarget::Msgstr {
                    file_byte_range: msgstr.byte_range.clone(),
                },
                edits: vec![Edit {
                    range: str_ws_start..msgstr.value.len(),
                    replacement: id_ws.to_string(),
                }],
            };
            self.new_diag(
                checker,
                Severity::Info,
                format!("inconsistent trailing whitespace ('{id_ws}' / '{str_ws}')"),
            )
            .map(|d| {
                d.with_msgs_hl(
                    msgid,
                    [(msgid.value.len() - id_ws.len(), msgid.value.len())],
                    msgstr,
                    [(str_ws_start, msgstr.value.len())],
                )
                .with_fix(fix)
            })
            .into_iter()
            .collect()
        }
    }
}

pub struct WhitespaceLineStartRule;

impl RuleChecker for WhitespaceLineStartRule {
    fn name(&self) -> &'static str {
        "whitespace-line-start"
    }

    fn description(&self) -> &'static str {
        "Check for inconsistent leading whitespace at the start of each line."
    }

    fn is_default(&self) -> bool {
        true
    }

    fn is_check(&self) -> bool {
        true
    }

    /// Check for inconsistent leading whitespace at the start of each *interior*
    /// line (the lines after an embedded newline). The string's own leading
    /// whitespace is handled by `whitespace-start`, so the first line is skipped.
    ///
    /// Wrong entry:
    /// ```text
    /// msgid "first line\n  second line"
    /// msgstr "première ligne\nseconde ligne"
    /// ```
    ///
    /// Correct entry:
    /// ```text
    /// msgid "first line\n  second line"
    /// msgstr "première ligne\n  seconde ligne"
    /// ```
    ///
    /// Diagnostics reported:
    /// - [`info`](Severity::Info): `inconsistent leading whitespace ('…' / '…')` (auto-fixable)
    fn check_msg(
        &self,
        checker: &Checker,
        _entry: &Entry,
        msgid: &Message,
        msgstr: &Message,
    ) -> Vec<Diagnostic> {
        check_interior_whitespace(self, checker, msgid, msgstr, LineEdge::Start)
    }
}

pub struct WhitespaceLineEndRule;

impl RuleChecker for WhitespaceLineEndRule {
    fn name(&self) -> &'static str {
        "whitespace-line-end"
    }

    fn description(&self) -> &'static str {
        "Check for inconsistent trailing whitespace at the end of each line."
    }

    fn is_default(&self) -> bool {
        true
    }

    fn is_check(&self) -> bool {
        true
    }

    /// Check for inconsistent trailing whitespace at the end of each *interior*
    /// line (the lines before an embedded newline). The string's own trailing
    /// whitespace is handled by `whitespace-end`, so the last line is skipped.
    ///
    /// Wrong entry:
    /// ```text
    /// msgid "first line  \nsecond line"
    /// msgstr "première ligne\nseconde ligne"
    /// ```
    ///
    /// Correct entry:
    /// ```text
    /// msgid "first line  \nsecond line"
    /// msgstr "première ligne  \nseconde ligne"
    /// ```
    ///
    /// Diagnostics reported:
    /// - [`info`](Severity::Info): `inconsistent trailing whitespace ('…' / '…')` (auto-fixable)
    fn check_msg(
        &self,
        checker: &Checker,
        _entry: &Entry,
        msgid: &Message,
        msgstr: &Message,
    ) -> Vec<Diagnostic> {
        check_interior_whitespace(self, checker, msgid, msgstr, LineEdge::End)
    }
}

/// Which edge of a line the interior per-line whitespace check inspects.
#[derive(Clone, Copy)]
enum LineEdge {
    /// Leading whitespace, at the start of a line (`whitespace-line-start`).
    Start,
    /// Trailing whitespace, at the end of a line (`whitespace-line-end`).
    End,
}

/// Split `value` on `'\n'` into `(byte_offset, line)` pairs, where `byte_offset`
/// is the start offset of the line within `value`.
fn lines_with_offsets(value: &str) -> Vec<(usize, &str)> {
    let mut offset = 0;
    let mut lines = Vec::new();
    for line in value.split('\n') {
        lines.push((offset, line));
        offset += line.len() + 1;
    }
    lines
}

/// Check inconsistent leading/trailing whitespace at the *interior* line
/// boundaries (around embedded newlines) between source and translation.
///
/// The string's outer edges are covered by `whitespace-start` / `whitespace-end`,
/// so the first line's leading run and the last line's trailing run are skipped.
/// The comparison is line-by-line, so it runs only when source and translation
/// have the same number of lines; otherwise the lines can not be aligned and
/// nothing is reported. Each mismatching boundary yields its own diagnostic,
/// each carrying a fix for that one whitespace run.
fn check_interior_whitespace<R: RuleChecker>(
    rule: &R,
    checker: &Checker,
    msgid: &Message,
    msgstr: &Message,
    edge: LineEdge,
) -> Vec<Diagnostic> {
    if msgid.value.trim().is_empty() || msgstr.value.trim().is_empty() {
        return vec![];
    }
    let id_lines = lines_with_offsets(&msgid.value);
    let str_lines = lines_with_offsets(&msgstr.value);
    if id_lines.len() != str_lines.len() || str_lines.len() < 2 {
        return vec![];
    }
    // Leading edge: skip the first line (its leading run is the string start).
    // Trailing edge: skip the last line (its trailing run is the string end).
    let indices = match edge {
        LineEdge::Start => 1..str_lines.len(),
        LineEdge::End => 0..str_lines.len() - 1,
    };
    let position = match edge {
        LineEdge::Start => "leading",
        LineEdge::End => "trailing",
    };
    let mut diagnostics = Vec::new();
    for i in indices {
        let (id_off, id_line) = id_lines[i];
        let (str_off, str_line) = str_lines[i];
        let (id_ws, str_ws, id_hl, str_hl) = match edge {
            LineEdge::Start => {
                let id_ws = get_whitespace_start(id_line);
                let str_ws = get_whitespace_start(str_line);
                (
                    id_ws,
                    str_ws,
                    (id_off, id_off + id_ws.len()),
                    (str_off, str_off + str_ws.len()),
                )
            }
            LineEdge::End => {
                let id_ws = get_whitespace_end(id_line);
                let str_ws = get_whitespace_end(str_line);
                let id_end = id_off + id_line.len();
                let str_end = str_off + str_line.len();
                (
                    id_ws,
                    str_ws,
                    (id_end - id_ws.len(), id_end),
                    (str_end - str_ws.len(), str_end),
                )
            }
        };
        if id_ws == str_ws {
            continue;
        }
        let fix = Fix {
            target: FixTarget::Msgstr {
                file_byte_range: msgstr.byte_range.clone(),
            },
            edits: vec![Edit {
                range: str_hl.0..str_hl.1,
                replacement: id_ws.to_string(),
            }],
        };
        if let Some(diag) = rule.new_diag(
            checker,
            Severity::Info,
            format!("inconsistent {position} whitespace ('{id_ws}' / '{str_ws}')"),
        ) {
            diagnostics.push(
                diag.with_msgs_hl(msgid, [id_hl], msgstr, [str_hl])
                    .with_fix(fix),
            );
        }
    }
    diagnostics
}

/// Get the leading whitespace of a string (up to the first non-whitespace character or newline).
fn get_whitespace_start(value: &str) -> &str {
    let pos = value
        .chars()
        .take_while(|c| c.is_whitespace() && *c != '\n')
        .map(char::len_utf8)
        .sum::<usize>();
    &value[..pos]
}

/// Get the trailing whitespace of a string (up to the last non-whitespace character or newline).
fn get_whitespace_end(value: &str) -> &str {
    let pos = value
        .chars()
        .rev()
        .take_while(|c| c.is_whitespace() && *c != '\n')
        .map(char::len_utf8)
        .sum::<usize>();
    &value[value.len() - pos..]
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::{diagnostic::Diagnostic, rules::rule::Rules};

    fn check_whitespace_start(content: &str) -> Vec<Diagnostic> {
        let mut checker = Checker::new(content.as_bytes());
        let rules = Rules::new(vec![Box::new(WhitespaceStartRule {})]);
        checker.do_all_checks(&rules);
        checker.diagnostics
    }

    fn check_whitespace_end(content: &str) -> Vec<Diagnostic> {
        let mut checker = Checker::new(content.as_bytes());
        let rules = Rules::new(vec![Box::new(WhitespaceEndRule {})]);
        checker.do_all_checks(&rules);
        checker.diagnostics
    }

    fn check_whitespace_line_start(content: &str) -> Vec<Diagnostic> {
        let mut checker = Checker::new(content.as_bytes());
        let rules = Rules::new(vec![Box::new(WhitespaceLineStartRule {})]);
        checker.do_all_checks(&rules);
        checker.diagnostics
    }

    fn check_whitespace_line_end(content: &str) -> Vec<Diagnostic> {
        let mut checker = Checker::new(content.as_bytes());
        let rules = Rules::new(vec![Box::new(WhitespaceLineEndRule {})]);
        checker.do_all_checks(&rules);
        checker.diagnostics
    }

    #[test]
    fn test_get_whitespace_start() {
        assert_eq!(get_whitespace_start(""), "");
        assert_eq!(get_whitespace_start("test"), "");
        assert_eq!(get_whitespace_start("  test"), "  ");
        assert_eq!(get_whitespace_start("\ttest"), "\t");
        assert_eq!(get_whitespace_start(" \ttest"), " \t");
        assert_eq!(get_whitespace_start("\n test"), "");
    }

    #[test]
    fn test_get_whitespace_end() {
        assert_eq!(get_whitespace_end(""), "");
        assert_eq!(get_whitespace_end("test"), "");
        assert_eq!(get_whitespace_end("test  "), "  ");
        assert_eq!(get_whitespace_end("test\t"), "\t");
        assert_eq!(get_whitespace_end("test\t "), "\t ");
        assert_eq!(get_whitespace_end("test \n"), "");
    }

    #[test]
    fn test_no_whitespace() {
        let diags = check_whitespace_start(
            r#"
msgid "tested"
msgstr "testé"
"#,
        );
        assert!(diags.is_empty());
        let diags = check_whitespace_end(
            r#"
msgid "tested"
msgstr "testé"
"#,
        );
        assert!(diags.is_empty());
    }

    #[test]
    fn test_whitespace_ok() {
        let diags = check_whitespace_start(
            r#"
msgid "  tested  "
msgstr "  testé  "
"#,
        );
        assert!(diags.is_empty());
        let diags = check_whitespace_end(
            r#"
msgid "  tested  "
msgstr "  testé  "
"#,
        );
        assert!(diags.is_empty());
    }

    #[test]
    fn test_whitespace_error_noqa() {
        let diags = check_whitespace_start(
            r#"
#, noqa:whitespace-start
msgid " tested "
msgstr "testé  "
"#,
        );
        assert!(diags.is_empty());
        let diags = check_whitespace_end(
            r#"
#, noqa:whitespace-end
msgid " tested "
msgstr "testé  "
"#,
        );
        assert!(diags.is_empty());
    }

    #[test]
    fn test_whitespace_error() {
        let diags = check_whitespace_start(
            r#"
msgid " tested "
msgstr "testé  "
"#,
        );
        assert_eq!(diags.len(), 1);
        let diag = &diags[0];
        assert_eq!(diag.severity, Severity::Info);
        assert_eq!(diag.message, "inconsistent leading whitespace (' ' / '')");
        let diags = check_whitespace_end(
            r#"
msgid " tested "
msgstr "testé  "
"#,
        );
        assert_eq!(diags.len(), 1);
        let diag = &diags[0];
        assert_eq!(diag.severity, Severity::Info);
        assert_eq!(
            diag.message,
            "inconsistent trailing whitespace (' ' / '  ')"
        );
    }

    #[test]
    fn test_whitespace_start_fix() {
        // msgstr is missing the leading space the msgid has.
        let diags = check_whitespace_start(
            r#"
msgid " tested"
msgstr "testé"
"#,
        );
        assert_eq!(diags.len(), 1);
        let fix = diags[0].fix.as_ref().expect("fix should be attached");
        let FixTarget::Msgstr { file_byte_range } = &fix.target else {
            panic!("expected FixTarget::Msgstr, got {:?}", fix.target);
        };
        // The fix replaces the leading whitespace run (currently empty, 0..0)
        // of msgstr with " ".
        assert_eq!(fix.edits.len(), 1);
        assert_eq!(fix.edits[0].range, 0..0);
        assert_eq!(fix.edits[0].replacement, " ");
        // The target byte range must point at the msgstr block in the file.
        assert!(file_byte_range.start < file_byte_range.end);
    }

    #[test]
    fn test_whitespace_end_fix() {
        // msgstr has two trailing spaces; msgid has one.
        let diags = check_whitespace_end(
            r#"
msgid "tested "
msgstr "testé  "
"#,
        );
        assert_eq!(diags.len(), 1);
        let fix = diags[0].fix.as_ref().expect("fix should be attached");
        let FixTarget::Msgstr { file_byte_range } = &fix.target else {
            panic!("expected FixTarget::Msgstr, got {:?}", fix.target);
        };
        // Decoded msgstr value is "testé  " (= 7 bytes: t-e-s-t-é(2)-space-space).
        // The fix replaces the trailing 2-byte whitespace run with " ".
        assert_eq!(fix.edits.len(), 1);
        assert_eq!(fix.edits[0].range, 6..8);
        assert_eq!(fix.edits[0].replacement, " ");
        assert!(file_byte_range.start < file_byte_range.end);
    }

    #[test]
    fn test_whitespace_line_consistent_ok() {
        // Interior leading and trailing whitespace match line-by-line.
        let content = r#"
msgid "one\n two \nthree"
msgstr "un\n deux \ntrois"
"#;
        assert!(check_whitespace_line_start(content).is_empty());
        assert!(check_whitespace_line_end(content).is_empty());
    }

    #[test]
    fn test_whitespace_line_ignores_outer_edges() {
        // The leading run of the first line and the trailing run of the last
        // line are the string's outer edges (whitespace-start / whitespace-end),
        // so the per-line rules must ignore them.
        let content = r#"
msgid " one\ntwo "
msgstr "un\ndeux"
"#;
        assert!(check_whitespace_line_start(content).is_empty());
        assert!(check_whitespace_line_end(content).is_empty());
    }

    #[test]
    fn test_whitespace_line_different_line_count_skipped() {
        // Source has two lines, translation one: lines can't be aligned.
        let content = r#"
msgid "one\ntwo"
msgstr "un deux"
"#;
        assert!(check_whitespace_line_start(content).is_empty());
        assert!(check_whitespace_line_end(content).is_empty());
    }

    #[test]
    fn test_whitespace_line_single_line_skipped() {
        // No embedded newline means no interior boundary to check.
        let content = r#"
msgid " one "
msgstr "un"
"#;
        assert!(check_whitespace_line_start(content).is_empty());
        assert!(check_whitespace_line_end(content).is_empty());
    }

    #[test]
    fn test_whitespace_line_start_error() {
        let diags = check_whitespace_line_start(
            r#"
msgid "one\n two"
msgstr "un\ndeux"
"#,
        );
        assert_eq!(diags.len(), 1);
        assert_eq!(diags[0].severity, Severity::Info);
        assert_eq!(
            diags[0].message,
            "inconsistent leading whitespace (' ' / '')"
        );
    }

    #[test]
    fn test_whitespace_line_end_error() {
        let diags = check_whitespace_line_end(
            r#"
msgid "one \ntwo"
msgstr "un\ndeux"
"#,
        );
        assert_eq!(diags.len(), 1);
        assert_eq!(diags[0].severity, Severity::Info);
        assert_eq!(
            diags[0].message,
            "inconsistent trailing whitespace (' ' / '')"
        );
    }

    #[test]
    fn test_whitespace_line_error_noqa() {
        let diags = check_whitespace_line_start(
            r#"
#, noqa:whitespace-line-start
msgid "one\n two"
msgstr "un\ndeux"
"#,
        );
        assert!(diags.is_empty());
    }

    #[test]
    fn test_whitespace_line_start_multiple_errors() {
        // Two interior lines each miss the source's leading space.
        let diags = check_whitespace_line_start(
            r#"
msgid "x\n a\n b"
msgstr "u\nc\nd"
"#,
        );
        assert_eq!(diags.len(), 2);
    }

    #[test]
    fn test_whitespace_line_start_fix() {
        // Interior line of msgstr is missing the leading space the msgid has.
        let diags = check_whitespace_line_start(
            r#"
msgid "x\n y"
msgstr "a\nb"
"#,
        );
        assert_eq!(diags.len(), 1);
        let fix = diags[0].fix.as_ref().expect("fix should be attached");
        let FixTarget::Msgstr { file_byte_range } = &fix.target else {
            panic!("expected FixTarget::Msgstr, got {:?}", fix.target);
        };
        // Decoded msgstr value is "a\nb"; the second line "b" starts at byte 2.
        // Its (empty) leading run is replaced with " " (insertion at 2..2).
        assert_eq!(fix.edits.len(), 1);
        assert_eq!(fix.edits[0].range, 2..2);
        assert_eq!(fix.edits[0].replacement, " ");
        assert!(file_byte_range.start < file_byte_range.end);
    }

    #[test]
    fn test_whitespace_line_end_fix() {
        // Interior line of msgstr is missing the trailing space the msgid has.
        let diags = check_whitespace_line_end(
            r#"
msgid "x \ny"
msgstr "a\nb"
"#,
        );
        assert_eq!(diags.len(), 1);
        let fix = diags[0].fix.as_ref().expect("fix should be attached");
        let FixTarget::Msgstr { file_byte_range } = &fix.target else {
            panic!("expected FixTarget::Msgstr, got {:?}", fix.target);
        };
        // Decoded msgstr value is "a\nb"; the first line "a" ends at byte 1
        // (just before the newline). Its (empty) trailing run is replaced with
        // " " (insertion at 1..1).
        assert_eq!(fix.edits.len(), 1);
        assert_eq!(fix.edits[0].range, 1..1);
        assert_eq!(fix.edits[0].replacement, " ");
        assert!(file_byte_range.start < file_byte_range.end);
    }
}