forked from extern/nushell
Match ++=
capabilities with ++
(#11130)
Allow `++=` to work in all situations `++` does, namely for appending single elements: `$list ++= 1`. Resolve #11087 # Description Bring `++=` to parity with `++`. # User-Facing Changes It is now possible to do `$list ++= 1` (appending a single element). Similarly, this can be done: ```Nushell ~> mut a = [1] ~> $a ++= 2 ~> a ╭───┬───╮ │ 0 │ 1 │ │ 1 │ 2 │ ╰───┴───╯ ``` # Tests + Formatting Added two tests: - `commands::assignment::append_assign::append_assign_single_element` - `commands::assignment::append_assign::append_assign_to_single_element`
This commit is contained in:
@ -5,16 +5,10 @@ fn append_assign_int() {
|
||||
let actual = nu!(r#"
|
||||
mut a = [1 2];
|
||||
$a ++= [3 4];
|
||||
$a
|
||||
$a == [1 2 3 4]
|
||||
"#);
|
||||
|
||||
let expected = nu!(r#"
|
||||
[1 2 3 4]
|
||||
"#);
|
||||
|
||||
print!("{}", actual.out);
|
||||
print!("{}", expected.out);
|
||||
assert_eq!(actual.out, expected.out);
|
||||
assert_eq!(actual.out, "true")
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -22,16 +16,10 @@ fn append_assign_string() {
|
||||
let actual = nu!(r#"
|
||||
mut a = [a b];
|
||||
$a ++= [c d];
|
||||
$a
|
||||
$a == [a b c d]
|
||||
"#);
|
||||
|
||||
let expected = nu!(r#"
|
||||
[a b c d]
|
||||
"#);
|
||||
|
||||
print!("{}", actual.out);
|
||||
print!("{}", expected.out);
|
||||
assert_eq!(actual.out, expected.out);
|
||||
assert_eq!(actual.out, "true")
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -39,16 +27,10 @@ fn append_assign_any() {
|
||||
let actual = nu!(r#"
|
||||
mut a = [1 2 a];
|
||||
$a ++= [b 3];
|
||||
$a
|
||||
$a == [1 2 a b 3]
|
||||
"#);
|
||||
|
||||
let expected = nu!(r#"
|
||||
[1 2 a b 3]
|
||||
"#);
|
||||
|
||||
print!("{}", actual.out);
|
||||
print!("{}", expected.out);
|
||||
assert_eq!(actual.out, expected.out);
|
||||
assert_eq!(actual.out, "true")
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -56,16 +38,10 @@ fn append_assign_both_empty() {
|
||||
let actual = nu!(r#"
|
||||
mut a = [];
|
||||
$a ++= [];
|
||||
$a
|
||||
$a == []
|
||||
"#);
|
||||
|
||||
let expected = nu!(r#"
|
||||
[]
|
||||
"#);
|
||||
|
||||
print!("{}", actual.out);
|
||||
print!("{}", expected.out);
|
||||
assert_eq!(actual.out, expected.out);
|
||||
assert_eq!(actual.out, "true")
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -73,8 +49,40 @@ fn append_assign_type_mismatch() {
|
||||
let actual = nu!(r#"
|
||||
mut a = [1 2];
|
||||
$a ++= [a];
|
||||
$a | to json -r;
|
||||
$a == [1 2 "a"]
|
||||
"#);
|
||||
|
||||
assert_eq!(actual.out, r#"[1,2,"a"]"#);
|
||||
assert_eq!(actual.out, "true")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn append_assign_single_element() {
|
||||
let actual = nu!(r#"
|
||||
mut a = ["list" "and"];
|
||||
$a ++= "a single element";
|
||||
$a == ["list" "and" "a single element"]
|
||||
"#);
|
||||
|
||||
assert_eq!(actual.out, "true")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn append_assign_to_single_element() {
|
||||
let actual = nu!(r#"
|
||||
mut a = "string";
|
||||
$a ++= ["and" "the" "list"];
|
||||
$a == ["string" "and" "the" "list"]
|
||||
"#);
|
||||
|
||||
assert_eq!(actual.out, "true")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn append_assign_single_to_single() {
|
||||
let actual = nu!(r#"
|
||||
mut a = 1;
|
||||
$a ++= "and a single element";
|
||||
"#);
|
||||
|
||||
assert!(actual.err.contains("nu::parser::unsupported_operation"));
|
||||
}
|
||||
|
Reference in New Issue
Block a user