Merge pull request #8806 from Misakait/fix/reference-stdin

fix(ptx): Correct reference format for stdin
This commit is contained in:
Daniel Hofstetter
2025-10-04 16:04:39 +02:00
committed by GitHub
2 changed files with 28 additions and 6 deletions
+9 -5
View File
@@ -352,11 +352,15 @@ fn create_word_set(config: &Config, filter: &WordFilter, file_map: &FileMap) ->
fn get_reference(config: &Config, word_ref: &WordRef, line: &str, context_reg: &Regex) -> String {
if config.auto_ref {
format!(
"{}:{}",
word_ref.filename.maybe_quote(),
word_ref.local_line_nr + 1
)
if word_ref.filename == "-" {
format!(":{}", word_ref.local_line_nr + 1)
} else {
format!(
"{}:{}",
word_ref.filename.maybe_quote(),
word_ref.local_line_nr + 1
)
}
} else if config.input_ref {
let (beg, end) = match context_reg.find(line) {
Some(x) => (x.start(), x.end()),
+19 -1
View File
@@ -10,7 +10,25 @@ use uutests::new_ucmd;
fn test_invalid_arg() {
new_ucmd!().arg("--definitely-invalid").fails_with_code(1);
}
#[test]
fn test_reference_format_for_stdin() {
let input = "Rust is good language";
let expected_output = concat!(
r#".xx "" "" "Rust is good language" "" ":1""#,
"\n",
r#".xx "" "Rust is" "good language" "" ":1""#,
"\n",
r#".xx "" "Rust" "is good language" "" ":1""#,
"\n",
r#".xx "" "Rust is good" "language" "" ":1""#,
"\n",
);
new_ucmd!()
.args(&["-G", "-A"])
.pipe_in(input)
.succeeds()
.stdout_only(expected_output);
}
#[test]
fn test_tex_format_no_truncation_markers() {
let input = "Hello world Rust is a fun language";