base32/base64/basenc: permit repeating -d/-i/-w flags

This commit is contained in:
Ben Wiederhake 2024-02-24 20:42:51 +01:00
parent 36e142aa15
commit 445905a045
4 changed files with 87 additions and 5 deletions

View file

@ -102,23 +102,24 @@ pub fn base_app(about: &'static str, usage: &str) -> Command {
.short('d')
.long(options::DECODE)
.help("decode data")
.action(ArgAction::SetTrue),
.action(ArgAction::SetTrue)
.overrides_with(options::DECODE),
)
.arg(
Arg::new(options::IGNORE_GARBAGE)
.short('i')
.long(options::IGNORE_GARBAGE)
.help("when decoding, ignore non-alphabetic characters")
.action(ArgAction::SetTrue),
.action(ArgAction::SetTrue)
.overrides_with(options::IGNORE_GARBAGE),
)
.arg(
Arg::new(options::WRAP)
.short('w')
.long(options::WRAP)
.value_name("COLS")
.help(
"wrap encoded lines after COLS character (default 76, 0 to disable wrapping)",
),
.help("wrap encoded lines after COLS character (default 76, 0 to disable wrapping)")
.overrides_with(options::WRAP),
)
// "multiple" arguments are used to check whether there is more than one
// file passed in.

View file

@ -22,6 +22,26 @@ fn test_encode() {
.stdout_only("JBSWY3DPFQQFO33SNRSCC===\n"); // spell-checker:disable-line
}
#[test]
fn test_encode_repeat_flags_later_wrap_10() {
let input = "Hello, World!\n";
new_ucmd!()
.args(&["-ii", "-w17", "-w10"])
.pipe_in(input)
.succeeds()
.stdout_only("JBSWY3DPFQ\nQFO33SNRSC\nCCQ=\n"); // spell-checker:disable-line
}
#[test]
fn test_encode_repeat_flags_later_wrap_17() {
let input = "Hello, World!\n";
new_ucmd!()
.args(&["-ii", "-w10", "-w17"])
.pipe_in(input)
.succeeds()
.stdout_only("JBSWY3DPFQQFO33SN\nRSCCCQ=\n"); // spell-checker:disable-line
}
#[test]
fn test_base32_encode_file() {
new_ucmd!()
@ -42,6 +62,16 @@ fn test_decode() {
}
}
#[test]
fn test_decode_repeat_flags() {
let input = "JBSWY3DPFQQFO33SNRSCC===\n"; // spell-checker:disable-line
new_ucmd!()
.args(&["-didiw80", "--wrap=17", "--wrap", "8"]) // spell-checker:disable-line
.pipe_in(input)
.succeeds()
.stdout_only("Hello, World!");
}
#[test]
fn test_garbage() {
let input = "aGVsbG8sIHdvcmxkIQ==\0"; // spell-checker:disable-line

View file

@ -20,6 +20,26 @@ fn test_encode() {
.stdout_only("aGVsbG8sIHdvcmxkIQ==\n"); // spell-checker:disable-line
}
#[test]
fn test_encode_repeat_flags_later_wrap_10() {
let input = "hello, world!";
new_ucmd!()
.args(&["-ii", "-w15", "-w10"])
.pipe_in(input)
.succeeds()
.stdout_only("aGVsbG8sIH\ndvcmxkIQ==\n"); // spell-checker:disable-line
}
#[test]
fn test_encode_repeat_flags_later_wrap_15() {
let input = "hello, world!";
new_ucmd!()
.args(&["-ii", "-w10", "-w15"])
.pipe_in(input)
.succeeds()
.stdout_only("aGVsbG8sIHdvcmx\nkIQ==\n"); // spell-checker:disable-line
}
#[test]
fn test_base64_encode_file() {
new_ucmd!()
@ -40,6 +60,16 @@ fn test_decode() {
}
}
#[test]
fn test_decode_repeat_flags() {
let input = "aGVsbG8sIHdvcmxkIQ==\n"; // spell-checker:disable-line
new_ucmd!()
.args(&["-didiw80", "--wrap=17", "--wrap", "8"]) // spell-checker:disable-line
.pipe_in(input)
.succeeds()
.stdout_only("hello, world!");
}
#[test]
fn test_garbage() {
let input = "aGVsbG8sIHdvcmxkIQ==\0"; // spell-checker:disable-line

View file

@ -230,3 +230,24 @@ fn test_choose_last_encoding_base2lsbf() {
.no_stderr()
.stdout_only("00110110110011100100011001100110\n");
}
#[test]
fn test_base32_decode_repeated() {
new_ucmd!()
.args(&[
"--ignore",
"--wrap=80",
"--base32hex",
"--z85",
"--ignore",
"--decode",
"--z85",
"--base32",
"-w",
"10",
])
.pipe_in("NZUWGZJ6MJQXGZJ7") // spell-checker:disable-line
.succeeds()
.no_stderr()
.stdout_only("nice>base?");
}