Skip to content

Commit 94b6544

Browse files
authored
Merge pull request #8806 from Misakait/fix/reference-stdin
fix(ptx): Correct reference format for stdin
2 parents f08f4d0 + e131d31 commit 94b6544

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

src/uu/ptx/src/ptx.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,11 +352,15 @@ fn create_word_set(config: &Config, filter: &WordFilter, file_map: &FileMap) ->
352352

353353
fn get_reference(config: &Config, word_ref: &WordRef, line: &str, context_reg: &Regex) -> String {
354354
if config.auto_ref {
355-
format!(
356-
"{}:{}",
357-
word_ref.filename.maybe_quote(),
358-
word_ref.local_line_nr + 1
359-
)
355+
if word_ref.filename == "-" {
356+
format!(":{}", word_ref.local_line_nr + 1)
357+
} else {
358+
format!(
359+
"{}:{}",
360+
word_ref.filename.maybe_quote(),
361+
word_ref.local_line_nr + 1
362+
)
363+
}
360364
} else if config.input_ref {
361365
let (beg, end) = match context_reg.find(line) {
362366
Some(x) => (x.start(), x.end()),

tests/by-util/test_ptx.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,25 @@ use uutests::new_ucmd;
1010
fn test_invalid_arg() {
1111
new_ucmd!().arg("--definitely-invalid").fails_with_code(1);
1212
}
13-
13+
#[test]
14+
fn test_reference_format_for_stdin() {
15+
let input = "Rust is good language";
16+
let expected_output = concat!(
17+
r#".xx "" "" "Rust is good language" "" ":1""#,
18+
"\n",
19+
r#".xx "" "Rust is" "good language" "" ":1""#,
20+
"\n",
21+
r#".xx "" "Rust" "is good language" "" ":1""#,
22+
"\n",
23+
r#".xx "" "Rust is good" "language" "" ":1""#,
24+
"\n",
25+
);
26+
new_ucmd!()
27+
.args(&["-G", "-A"])
28+
.pipe_in(input)
29+
.succeeds()
30+
.stdout_only(expected_output);
31+
}
1432
#[test]
1533
fn test_tex_format_no_truncation_markers() {
1634
let input = "Hello world Rust is a fun language";

0 commit comments

Comments
 (0)