mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
printing version unified and tests
This commit is contained in:
parent
ea7df03c0a
commit
5aa68eb716
6 changed files with 79 additions and 4 deletions
1
Makefile
1
Makefile
|
@ -174,6 +174,7 @@ TEST_PROGS := \
|
|||
mv \
|
||||
nl \
|
||||
paste \
|
||||
ptx \
|
||||
pwd \
|
||||
readlink \
|
||||
rm \
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
2
test/fixtures/ptx/ignore
vendored
Normal file
2
test/fixtures/ptx/ignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
maybe
|
||||
about
|
7
test/fixtures/ptx/input
vendored
Normal file
7
test/fixtures/ptx/input
vendored
Normal file
|
@ -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
|
5
test/fixtures/ptx/only
vendored
Normal file
5
test/fixtures/ptx/only
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
roff
|
||||
tex
|
||||
world
|
||||
maybe
|
||||
about
|
60
test/ptx.rs
Normal file
60
test/ptx.rs
Normal file
|
@ -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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue