nushell/crates/nu-command/tests/commands/hash_/mod.rs
Michael Angerman d06f457b2a
nu-cli refactor moving commands into their own crate nu-command (#2910)
* move commands, futures.rs, script.rs, utils

* move over maybe_print_errors

* add nu_command crate references to nu_cli

* in commands.rs open up to pub mod from pub(crate)

* nu-cli, nu-command, and nu tests are now passing

* cargo fmt

* clean up nu-cli/src/prelude.rs

* code cleanup

* for some reason lex.rs was not formatted, may be causing my error

* remove mod completion from lib.rs which was not being used along with quickcheck macros

* add in allow unused imports

* comment out one failing external test; comment out one failing internal test

* revert commenting out failing tests; something else might be going on; someone with a windows machine should check and see what is going on with these failing windows tests

* Update Cargo.toml

Extend the optional features to nu-command

Co-authored-by: Jonathan Turner <jonathandturner@users.noreply.github.com>
2021-01-12 17:59:53 +13:00

86 lines
1.8 KiB
Rust

use nu_test_support::{nu, pipeline};
#[test]
fn base64_defaults_to_encoding_with_standard_character_type() {
let actual = nu!(
cwd: ".", pipeline(
r#"
echo 'username:password' | hash base64
"#
)
);
assert_eq!(actual.out, "dXNlcm5hbWU6cGFzc3dvcmQ=");
}
#[test]
fn base64_encode_characterset_binhex() {
let actual = nu!(
cwd: ".", pipeline(
r#"
echo 'username:password' | hash base64 --character_set binhex --encode
"#
)
);
assert_eq!(actual.out, "F@0NEPjJD97kE\'&bEhFZEP3");
}
#[test]
fn error_when_invalid_character_set_given() {
let actual = nu!(
cwd: ".", pipeline(
r#"
echo 'username:password' | hash base64 --character_set 'this is invalid' --encode
"#
)
);
assert!(actual
.err
.contains("this is invalid is not a valid character-set"));
}
#[test]
fn base64_decode_characterset_binhex() {
let actual = nu!(
cwd: ".", pipeline(
r#"
echo "F@0NEPjJD97kE'&bEhFZEP3" | hash base64 --character_set binhex --decode
"#
)
);
assert_eq!(actual.out, "username:password");
}
#[test]
fn error_invalid_decode_value() {
let actual = nu!(
cwd: ".", pipeline(
r#"
echo "this should not be a valid encoded value" | hash base64 --character_set url-safe --decode
"#
)
);
assert!(actual
.err
.contains("invalid base64 input for character set url-safe"));
}
#[test]
fn error_use_both_flags() {
let actual = nu!(
cwd: ".", pipeline(
r#"
echo 'username:password' | hash base64 --encode --decode
"#
)
);
assert!(actual
.err
.contains("only one of --decode and --encode flags can be used"));
}