Add insert and update back (#4864)

This commit is contained in:
JT
2022-03-18 06:55:02 +13:00
committed by GitHub
parent 6e69d40bb9
commit 0986eefb64
14 changed files with 624 additions and 56 deletions

View File

@ -0,0 +1,28 @@
use nu_test_support::{nu, pipeline};
#[test]
fn insert_the_column() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
open cargo_sample.toml
| insert dev-dependencies.new_assertions "0.7.0"
| get dev-dependencies.new_assertions
"#
));
assert_eq!(actual.out, "0.7.0");
}
#[test]
fn insert_the_column_conflict() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
open cargo_sample.toml
| insert dev-dependencies.pretty_assertions "0.7.0"
"#
));
assert!(actual.err.contains("column already exists"));
}

View File

@ -23,6 +23,7 @@ mod hash_;
mod headers;
mod help;
mod histogram;
mod insert;
mod into_filesize;
mod into_int;
mod keep;
@ -61,6 +62,7 @@ mod str_;
mod touch;
mod uniq;
mod update;
mod upsert;
mod use_;
mod where_;
#[cfg(feature = "which")]

View File

@ -6,7 +6,7 @@ fn sets_the_column() {
cwd: "tests/fixtures/formats", pipeline(
r#"
open cargo_sample.toml
| upsert dev-dependencies.pretty_assertions "0.7.0"
| update dev-dependencies.pretty_assertions "0.7.0"
| get dev-dependencies.pretty_assertions
"#
));
@ -21,7 +21,7 @@ fn sets_the_column_from_a_block_run_output() {
cwd: "tests/fixtures/formats", pipeline(
r#"
open cargo_sample.toml
| upsert dev-dependencies.pretty_assertions { open cargo_sample.toml | get dev-dependencies.pretty_assertions | inc --minor }
| update dev-dependencies.pretty_assertions { open cargo_sample.toml | get dev-dependencies.pretty_assertions | inc --minor }
| get dev-dependencies.pretty_assertions
"#
));
@ -35,7 +35,7 @@ fn sets_the_column_from_a_block_full_stream_output() {
cwd: "tests/fixtures/formats", pipeline(
r#"
wrap content
| upsert content { open --raw cargo_sample.toml | lines | first 5 }
| update content { open --raw cargo_sample.toml | lines | first 5 }
| get content.1
| str contains "nu"
"#
@ -50,7 +50,7 @@ fn sets_the_column_from_a_subexpression() {
cwd: "tests/fixtures/formats", pipeline(
r#"
wrap content
| upsert content (open --raw cargo_sample.toml | lines | first 5)
| update content (open --raw cargo_sample.toml | lines | first 5)
| get content.1
| str contains "nu"
"#
@ -58,3 +58,16 @@ fn sets_the_column_from_a_subexpression() {
assert_eq!(actual.out, "true");
}
#[test]
fn upsert_column_missing() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
open cargo_sample.toml
| update dev-dependencies.new_assertions "0.7.0"
"#
));
assert!(actual.err.contains("cannot find column"));
}

View File

@ -0,0 +1,60 @@
use nu_test_support::{nu, pipeline};
#[test]
fn sets_the_column() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
open cargo_sample.toml
| upsert dev-dependencies.pretty_assertions "0.7.0"
| get dev-dependencies.pretty_assertions
"#
));
assert_eq!(actual.out, "0.7.0");
}
#[cfg(features = "inc")]
#[test]
fn sets_the_column_from_a_block_run_output() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
open cargo_sample.toml
| upsert dev-dependencies.pretty_assertions { open cargo_sample.toml | get dev-dependencies.pretty_assertions | inc --minor }
| get dev-dependencies.pretty_assertions
"#
));
assert_eq!(actual.out, "0.7.0");
}
#[test]
fn sets_the_column_from_a_block_full_stream_output() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
wrap content
| upsert content { open --raw cargo_sample.toml | lines | first 5 }
| get content.1
| str contains "nu"
"#
));
assert_eq!(actual.out, "true");
}
#[test]
fn sets_the_column_from_a_subexpression() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
wrap content
| upsert content (open --raw cargo_sample.toml | lines | first 5)
| get content.1
| str contains "nu"
"#
));
assert_eq!(actual.out, "true");
}