2023-07-17 18:43:51 +02:00
|
|
|
use nu_test_support::nu;
|
2022-12-09 17:20:58 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn append_assign_int() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(r#"
|
2022-12-09 17:20:58 +01:00
|
|
|
mut a = [1 2];
|
|
|
|
$a ++= [3 4];
|
2023-12-06 22:46:37 +01:00
|
|
|
$a == [1 2 3 4]
|
2023-07-17 18:43:51 +02:00
|
|
|
"#);
|
2022-12-09 17:20:58 +01:00
|
|
|
|
2023-12-06 22:46:37 +01:00
|
|
|
assert_eq!(actual.out, "true")
|
2022-12-09 17:20:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn append_assign_string() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(r#"
|
2022-12-09 17:20:58 +01:00
|
|
|
mut a = [a b];
|
|
|
|
$a ++= [c d];
|
2023-12-06 22:46:37 +01:00
|
|
|
$a == [a b c d]
|
2023-07-17 18:43:51 +02:00
|
|
|
"#);
|
2022-12-09 17:20:58 +01:00
|
|
|
|
2023-12-06 22:46:37 +01:00
|
|
|
assert_eq!(actual.out, "true")
|
2022-12-09 17:20:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn append_assign_any() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(r#"
|
2022-12-09 17:20:58 +01:00
|
|
|
mut a = [1 2 a];
|
|
|
|
$a ++= [b 3];
|
2023-12-06 22:46:37 +01:00
|
|
|
$a == [1 2 a b 3]
|
2023-07-17 18:43:51 +02:00
|
|
|
"#);
|
2022-12-09 17:20:58 +01:00
|
|
|
|
2023-12-06 22:46:37 +01:00
|
|
|
assert_eq!(actual.out, "true")
|
2022-12-09 17:20:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn append_assign_both_empty() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(r#"
|
2022-12-09 17:20:58 +01:00
|
|
|
mut a = [];
|
|
|
|
$a ++= [];
|
2023-12-06 22:46:37 +01:00
|
|
|
$a == []
|
2023-07-17 18:43:51 +02:00
|
|
|
"#);
|
2022-12-09 17:20:58 +01:00
|
|
|
|
2023-12-06 22:46:37 +01:00
|
|
|
assert_eq!(actual.out, "true")
|
2022-12-09 17:20:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn append_assign_type_mismatch() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(r#"
|
2022-12-09 17:20:58 +01:00
|
|
|
mut a = [1 2];
|
|
|
|
$a ++= [a];
|
2023-12-06 22:46:37 +01:00
|
|
|
$a == [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";
|
2023-07-17 18:43:51 +02:00
|
|
|
"#);
|
2022-12-09 17:20:58 +01:00
|
|
|
|
2023-12-06 22:46:37 +01:00
|
|
|
assert!(actual.err.contains("nu::parser::unsupported_operation"));
|
2022-12-09 17:20:58 +01:00
|
|
|
}
|