Files
.azureold
.cargo
.github
assets
crates
nu-ansi-term
nu-cli
nu-color-config
nu-command
assets
src
tests
commands
hash_
keep
math
move_
path
random
skip
str_
all.rs
any.rs
append.rs
cal.rs
cd.rs
compact.rs
cp.rs
def.rs
default.rs
drop.rs
each.rs
echo.rs
empty.rs
enter.rs
every.rs
find.rs
first.rs
flatten.rs
format.rs
get.rs
group_by.rs
headers.rs
help.rs
histogram.rs
into_filesize.rs
into_int.rs
last.rs
length.rs
lines.rs
ls.rs
merge.rs
mkdir.rs
mod.rs
open.rs
parse.rs
prepend.rs
range.rs
reduce.rs
reject.rs
rename.rs
reverse.rs
rm.rs
roll.rs
rotate.rs
save.rs
select.rs
semicolon.rs
sort_by.rs
source.rs
split_by.rs
split_column.rs
split_row.rs
touch.rs
uniq.rs
update.rs
use_.rs
where_.rs
which.rs
with_env.rs
wrap.rs
zip.rs
format_conversions
main.rs
Cargo.toml
build.rs
nu-engine
nu-json
nu-parser
nu-path
nu-plugin
nu-pretty-hex
nu-protocol
nu-system
nu-table
nu-term-grid
nu-test-support
nu_plugin_example
nu_plugin_gstat
nu_plugin_inc
nu_plugin_python
nu_plugin_query
old
README.md
docs
images
pkg_mgrs
samples
src
tests
wix
.gitignore
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Cargo.lock
Cargo.toml
Cargo.toml.old
LICENSE
Makefile.toml
README.build.txt
README.md
build-all-maclin.sh
build-all-windows.cmd
build-all.nu
build.rs
install-all.ps1
install-all.sh
rustfmt.toml
uninstall-all.sh
nushell/crates/nu-command/tests/commands/rename.rs
2022-02-07 14:54:06 -05:00

92 lines
2.4 KiB
Rust

use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
use nu_test_support::playground::Playground;
use nu_test_support::{nu, pipeline};
#[test]
fn changes_the_column_name() {
Playground::setup("rename_test_1", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
"los_cuatro_mosqueteros.txt",
r#"
Andrés N. Robalino
Jonathan Turner
Yehuda Katz
Jason Gedge
"#,
)]);
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
open los_cuatro_mosqueteros.txt
| lines
| wrap name
| rename mosqueteros
| get mosqueteros
| length
"#
));
assert_eq!(actual.out, "4");
})
}
#[test]
fn keeps_remaining_original_names_given_less_new_names_than_total_original_names() {
Playground::setup("rename_test_2", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
"los_cuatro_mosqueteros.txt",
r#"
Andrés N. Robalino
Jonathan Turner
Yehuda Katz
Jason Gedge
"#,
)]);
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
open los_cuatro_mosqueteros.txt
| lines
| wrap name
| default hit "arepa!"
| rename mosqueteros
| get hit
| length
"#
));
assert_eq!(actual.out, "4");
})
}
// FIXME: jt: needs more work
#[ignore]
#[test]
fn errors_if_no_columns_present() {
Playground::setup("rename_test_3", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
"los_cuatro_mosqueteros.txt",
r#"
Andrés N. Robalino
Jonathan Turner
Yehuda Katz
Jason Gedge
"#,
)]);
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
open los_cuatro_mosqueteros.txt
| lines
| rename mosqueteros
"#
));
assert!(actual.err.contains("no column names available"));
assert!(actual.err.contains("can't rename"));
})
}