diff --git a/Makefile b/Makefile index 7ab1b0921..957fcbb40 100644 --- a/Makefile +++ b/Makefile @@ -174,6 +174,7 @@ TEST_PROGS := \ mv \ nl \ paste \ + ptx \ pwd \ readlink \ rm \ diff --git a/src/ptx/ptx.rs b/src/ptx/ptx.rs index a029bb144..be5837e61 100644 --- a/src/ptx/ptx.rs +++ b/src/ptx/ptx.rs @@ -133,7 +133,7 @@ struct WordRef { } fn print_version() { - println!("{} version {}", NAME, VERSION); + println!("{} {}", NAME, VERSION); } fn print_usage(opts: &Options) { @@ -408,7 +408,6 @@ fn tex_mapper(x: char) -> String { match x { '\\' => "\\backslash{}".to_string(), '$' | '%' | '#' | '&' | '_' => format!("\\{}", x), - '^' | '~' => format!("{}\\{}{}", x, "{", "}"), '}' | '{' => format!("$\\{}$", x), _ => x.to_string() } @@ -441,7 +440,8 @@ fn format_tex_line(config: &Config, word_ref: &WordRef, line: &String, output.push_str(format!("{5}{0}{6}{5}{1}{6}{5}{2}{6}{5}{3}{6}{5}{4}{6}", tail, before, keyword, after, head, "{", "}").as_str()); if config.auto_ref || config.input_ref { - output.push_str(&format!("{}{}{}", "{", reference, "}")); + output.push_str( + &format!("{}{}{}", "{", adjust_tex_str(&reference), "}")); } output } @@ -470,7 +470,7 @@ fn format_roff_line(config: &Config, word_ref: &WordRef, line: &str, output.push_str(format!(" \"{}\" \"{}\" \"{}{}\" \"{}\"", tail, before, keyword, after, head).as_str()); if config.auto_ref || config.input_ref { - output.push_str(&format!(" \"{}\"", reference)); + output.push_str(&format!(" \"{}\"", adjust_roff_str(&reference))); } output } diff --git a/test/fixtures/ptx/ignore b/test/fixtures/ptx/ignore new file mode 100644 index 000000000..d671622f8 --- /dev/null +++ b/test/fixtures/ptx/ignore @@ -0,0 +1,2 @@ +maybe +about diff --git a/test/fixtures/ptx/input b/test/fixtures/ptx/input new file mode 100644 index 000000000..6ba595bc0 --- /dev/null +++ b/test/fixtures/ptx/input @@ -0,0 +1,7 @@ +hello world! +let's check special characters: +"quotes", for roff +{brackets} for tex +and some other like %a, b#, c$c +maybe also~or^ +oh, and back\slash diff --git a/test/fixtures/ptx/only b/test/fixtures/ptx/only new file mode 100644 index 000000000..917aa2431 --- /dev/null +++ b/test/fixtures/ptx/only @@ -0,0 +1,5 @@ +roff +tex +world +maybe +about diff --git a/test/ptx.rs b/test/ptx.rs new file mode 100644 index 000000000..d248a12f9 --- /dev/null +++ b/test/ptx.rs @@ -0,0 +1,60 @@ +use std::process::Command; +use util::*; + +static PROGNAME: &'static str = "./ptx"; + +#[path = "common/util.rs"] +#[macro_use] +mod util; + +#[test] +fn gnu_ext_disabled_roff_no_ref() { + let opts = vec!["-G", "-R"]; + test_ptx(&opts); +} + +#[test] +fn gnu_ext_disabled_roff_input_ref() { + let opts = vec!["-G", "-r", "-R"]; + test_ptx(&opts); +} + +#[test] +fn gnu_ext_disabled_roff_auto_ref() { + let opts = vec!["-G", "-A", "-R"]; + test_ptx(&opts); +} + +#[test] +fn gnu_ext_disabled_tex_no_ref() { + let opts = vec!["-G", "-T", "-R"]; + test_ptx(&opts); +} + +#[test] +fn gnu_ext_disabled_tex_input_ref() { + let opts = vec!["-G", "-T", "-r", "-R"]; + test_ptx(&opts); +} + +#[test] +fn gnu_ext_disabled_tex_auto_ref() { + let opts = vec!["-G", "-T", "-A", "-R"]; + test_ptx(&opts); +} + +#[test] +fn gnu_ext_disabled_ignore_and_only_file() { + let opts = vec!["-G", "-o", "only", "-i", "ignore"]; + test_ptx(&opts); +} + +fn test_ptx(opts: &Vec<&str>) { + let mut ptx = Command::new(PROGNAME); + let result = run(&mut ptx.args(opts).arg("input")); + let mut gnu_ptx = Command::new("ptx"); + let gnu_result = run(&mut gnu_ptx.args(opts).arg("input")); + assert_eq!(result.success, true); + assert_eq!(result.stdout, gnu_result.stdout); + assert_empty_stderr!(&result); +} \ No newline at end of file