mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
basenc: use last given encoding, instead of priority list
This commit is contained in:
parent
c6f75c98b7
commit
36e142aa15
2 changed files with 65 additions and 6 deletions
|
@ -53,12 +53,14 @@ const ENCODINGS: &[(&str, Format, &str)] = &[
|
|||
pub fn uu_app() -> Command {
|
||||
let mut command = base_common::base_app(ABOUT, USAGE);
|
||||
for encoding in ENCODINGS {
|
||||
command = command.arg(
|
||||
Arg::new(encoding.0)
|
||||
.long(encoding.0)
|
||||
.help(encoding.2)
|
||||
.action(ArgAction::SetTrue),
|
||||
);
|
||||
let raw_arg = Arg::new(encoding.0)
|
||||
.long(encoding.0)
|
||||
.help(encoding.2)
|
||||
.action(ArgAction::SetTrue);
|
||||
let overriding_arg = ENCODINGS
|
||||
.iter()
|
||||
.fold(raw_arg, |arg, enc| arg.overrides_with(enc.0));
|
||||
command = command.arg(overriding_arg);
|
||||
}
|
||||
command
|
||||
}
|
||||
|
|
|
@ -173,3 +173,60 @@ fn test_base2lsbf_decode() {
|
|||
.no_stderr()
|
||||
.stdout_only("lsbf");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_choose_last_encoding_z85() {
|
||||
new_ucmd!()
|
||||
.args(&[
|
||||
"--base2lsbf",
|
||||
"--base2msbf",
|
||||
"--base16",
|
||||
"--base32hex",
|
||||
"--base64url",
|
||||
"--base32",
|
||||
"--base64",
|
||||
"--z85",
|
||||
])
|
||||
.pipe_in("Hello, World")
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.stdout_only("nm=QNz.92jz/PV8\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_choose_last_encoding_base64() {
|
||||
new_ucmd!()
|
||||
.args(&[
|
||||
"--base2msbf",
|
||||
"--base2lsbf",
|
||||
"--base64url",
|
||||
"--base32hex",
|
||||
"--base32",
|
||||
"--base16",
|
||||
"--z85",
|
||||
"--base64",
|
||||
])
|
||||
.pipe_in("Hello, World!")
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.stdout_only("SGVsbG8sIFdvcmxkIQ==\n"); // spell-checker:disable-line
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_choose_last_encoding_base2lsbf() {
|
||||
new_ucmd!()
|
||||
.args(&[
|
||||
"--base64url",
|
||||
"--base16",
|
||||
"--base2msbf",
|
||||
"--base32",
|
||||
"--base64",
|
||||
"--z85",
|
||||
"--base32hex",
|
||||
"--base2lsbf",
|
||||
])
|
||||
.pipe_in("lsbf")
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.stdout_only("00110110110011100100011001100110\n");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue