mirror of
https://github.com/nushell/nushell.git
synced 2025-07-29 12:59:48 +02:00
.cargo
.github
assets
benches
crates
nu-cli
nu-cmd-lang
nu-color-config
nu-command
assets
src
tests
commands
assignment
bytes
date
hash_
mod.rs
math
move_
network
path
platform
query
random
skip
str_
take
url
alias.rs
all.rs
any.rs
append.rs
break_.rs
cal.rs
cd.rs
compact.rs
continue_.rs
cp.rs
def.rs
default.rs
do_.rs
drop.rs
each.rs
echo.rs
empty.rs
enter.rs
error_make.rs
every.rs
exec.rs
export_def.rs
fill.rs
find.rs
first.rs
flatten.rs
for_.rs
format.rs
g.rs
get.rs
glob.rs
group_by.rs
headers.rs
help.rs
histogram.rs
insert.rs
into_filesize.rs
into_int.rs
join.rs
last.rs
length.rs
let_.rs
lines.rs
loop_.rs
ls.rs
match_.rs
merge.rs
mkdir.rs
mod.rs
mut_.rs
n.rs
nu_check.rs
open.rs
p.rs
parse.rs
prepend.rs
print.rs
range.rs
redirection.rs
reduce.rs
reject.rs
rename.rs
return_.rs
reverse.rs
rm.rs
roll.rs
rotate.rs
run_external.rs
save.rs
select.rs
semicolon.rs
seq.rs
seq_char.rs
shells.rs
sort.rs
sort_by.rs
source_env.rs
split_by.rs
split_column.rs
split_row.rs
table.rs
to_text.rs
touch.rs
transpose.rs
try_.rs
uniq.rs
uniq_by.rs
update.rs
upsert.rs
use_.rs
where_.rs
which.rs
while_.rs
with_env.rs
wrap.rs
zip.rs
format_conversions
main.rs
Cargo.toml
LICENSE
nu-engine
nu-explore
nu-glob
nu-json
nu-parser
nu-path
nu-plugin
nu-pretty-hex
nu-protocol
nu-std
nu-system
nu-table
nu-term-grid
nu-test-support
nu-utils
nu_plugin_custom_values
nu_plugin_example
nu_plugin_formats
nu_plugin_gstat
nu_plugin_inc
nu_plugin_python
nu_plugin_query
README.md
docker
docs
images
pkg_mgrs
src
tests
wix
.gitignore
.typos.toml
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Cargo.lock
Cargo.toml
Cross.toml
LICENSE
README.md
README.release.txt
build-all-maclin.sh
build-all-windows.cmd
build-all.nu
build.rs
codecov.yml
coverage-local.nu
coverage-local.sh
install-all.ps1
install-all.sh
register-plugins.nu
rust-toolchain.toml
toolkit.nu
uninstall-all.sh
* feat: deprecate `hash base64` command * feat: extend `decode` and `encode` command families This commit - Adds `encode` command family - Backports `hash base64` features to `encode base64` and `decode base64` subcommands. - Refactors code a bit and extends tests for encodings - `decode base64` returns a binary `Value` (that may be decoded into a string using `decode` command) * feat: add `--binary(-b)` flag to `decode base64` Default output type is now string, but binary can be requested using this new flag.
100 lines
2.1 KiB
Rust
100 lines
2.1 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' | encode base64
|
|
"#
|
|
)
|
|
);
|
|
|
|
assert_eq!(actual.out, "dXNlcm5hbWU6cGFzc3dvcmQ=");
|
|
}
|
|
|
|
#[test]
|
|
fn base64_encode_characterset_binhex() {
|
|
let actual = nu!(
|
|
cwd: ".", pipeline(
|
|
r#"
|
|
echo 'username:password' | encode base64 --character-set binhex
|
|
"#
|
|
)
|
|
);
|
|
|
|
assert_eq!(actual.out, "F@0NEPjJD97kE\'&bEhFZEP3");
|
|
}
|
|
|
|
#[test]
|
|
fn error_when_invalid_character_set_given() {
|
|
let actual = nu!(
|
|
cwd: ".", pipeline(
|
|
r#"
|
|
echo 'username:password' | encode base64 --character-set 'this is invalid'
|
|
"#
|
|
)
|
|
);
|
|
|
|
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" | decode base64 --character-set binhex --binary | decode utf-8
|
|
"#
|
|
)
|
|
);
|
|
|
|
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" | decode base64 --character-set url-safe
|
|
"#
|
|
)
|
|
);
|
|
|
|
assert!(actual
|
|
.err
|
|
.contains("invalid base64 input for character set url-safe"));
|
|
}
|
|
|
|
#[test]
|
|
fn md5_works_with_file() {
|
|
let actual = nu!(
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
r#"
|
|
open sample.db --raw | hash md5
|
|
"#
|
|
)
|
|
);
|
|
|
|
assert_eq!(actual.out, "4de97601d232c427977ef11db396c951");
|
|
}
|
|
|
|
#[test]
|
|
fn sha256_works_with_file() {
|
|
let actual = nu!(
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
r#"
|
|
open sample.db --raw | hash sha256
|
|
"#
|
|
)
|
|
);
|
|
|
|
assert_eq!(
|
|
actual.out,
|
|
"2f5050e7eea415c1f3d80b5d93355efd15043ec9157a2bb167a9e73f2ae651f2"
|
|
);
|
|
}
|