2020-07-05 19:46:06 +02:00
|
|
|
use nu_test_support::{nu, pipeline};
|
2020-04-26 08:34:45 +02:00
|
|
|
|
|
|
|
#[test]
|
Allow dropping columns. (#3107)
`drop` is used for removing the last row. Passing a number allows dropping N rows.
Here we introduce the same logic for dropping columns instead.
You can certainly remove columns by using `reject`, however, there could be cases
where we are interested in removing columns from tables that contain, say, a big
number of columns. Using `reject` becomes impractical, especially when you don't
care about the column names that could either be known or not known when exploring
tables.
```
> echo [[lib, extension]; [nu-core, rs] [rake, rb]]
─────────┬───────────
lib │ extension
─────────┼───────────
nu-core │ rs
rake │ rb
─────────┴───────────
```
```
> echo [[lib, extension]; [nu-core, rs] [rake, rb]] | drop column
─────────
lib
─────────
nu-core
rake
─────────
```
2021-02-25 21:37:21 +01:00
|
|
|
fn columns() {
|
2023-04-07 23:09:55 +02:00
|
|
|
let actual = nu!(pipeline(
|
|
|
|
"
|
Allow dropping columns. (#3107)
`drop` is used for removing the last row. Passing a number allows dropping N rows.
Here we introduce the same logic for dropping columns instead.
You can certainly remove columns by using `reject`, however, there could be cases
where we are interested in removing columns from tables that contain, say, a big
number of columns. Using `reject` becomes impractical, especially when you don't
care about the column names that could either be known or not known when exploring
tables.
```
> echo [[lib, extension]; [nu-core, rs] [rake, rb]]
─────────┬───────────
lib │ extension
─────────┼───────────
nu-core │ rs
rake │ rb
─────────┴───────────
```
```
> echo [[lib, extension]; [nu-core, rs] [rake, rb]] | drop column
─────────
lib
─────────
nu-core
rake
─────────
```
2021-02-25 21:37:21 +01:00
|
|
|
echo [
|
|
|
|
[arepas, color];
|
|
|
|
[3, white]
|
|
|
|
[8, yellow]
|
|
|
|
[4, white]
|
2022-02-16 02:48:32 +01:00
|
|
|
] | drop column | columns | length
|
2023-04-07 23:09:55 +02:00
|
|
|
"
|
|
|
|
));
|
2020-04-26 08:34:45 +02:00
|
|
|
|
Allow dropping columns. (#3107)
`drop` is used for removing the last row. Passing a number allows dropping N rows.
Here we introduce the same logic for dropping columns instead.
You can certainly remove columns by using `reject`, however, there could be cases
where we are interested in removing columns from tables that contain, say, a big
number of columns. Using `reject` becomes impractical, especially when you don't
care about the column names that could either be known or not known when exploring
tables.
```
> echo [[lib, extension]; [nu-core, rs] [rake, rb]]
─────────┬───────────
lib │ extension
─────────┼───────────
nu-core │ rs
rake │ rb
─────────┴───────────
```
```
> echo [[lib, extension]; [nu-core, rs] [rake, rb]] | drop column
─────────
lib
─────────
nu-core
rake
─────────
```
2021-02-25 21:37:21 +01:00
|
|
|
assert_eq!(actual.out, "1");
|
|
|
|
}
|
|
|
|
|
2022-08-25 18:03:18 +02:00
|
|
|
#[test]
|
|
|
|
fn drop_columns_positive_value() {
|
2023-04-07 23:09:55 +02:00
|
|
|
let actual = nu!("echo [[a, b];[1,2]] | drop column -1");
|
2022-08-25 18:03:18 +02:00
|
|
|
|
|
|
|
assert!(actual.err.contains("use a positive value"));
|
|
|
|
}
|
|
|
|
|
Allow dropping columns. (#3107)
`drop` is used for removing the last row. Passing a number allows dropping N rows.
Here we introduce the same logic for dropping columns instead.
You can certainly remove columns by using `reject`, however, there could be cases
where we are interested in removing columns from tables that contain, say, a big
number of columns. Using `reject` becomes impractical, especially when you don't
care about the column names that could either be known or not known when exploring
tables.
```
> echo [[lib, extension]; [nu-core, rs] [rake, rb]]
─────────┬───────────
lib │ extension
─────────┼───────────
nu-core │ rs
rake │ rb
─────────┴───────────
```
```
> echo [[lib, extension]; [nu-core, rs] [rake, rb]] | drop column
─────────
lib
─────────
nu-core
rake
─────────
```
2021-02-25 21:37:21 +01:00
|
|
|
#[test]
|
|
|
|
fn more_columns_than_table_has() {
|
2023-04-07 23:09:55 +02:00
|
|
|
let actual = nu!(pipeline(
|
|
|
|
"
|
Allow dropping columns. (#3107)
`drop` is used for removing the last row. Passing a number allows dropping N rows.
Here we introduce the same logic for dropping columns instead.
You can certainly remove columns by using `reject`, however, there could be cases
where we are interested in removing columns from tables that contain, say, a big
number of columns. Using `reject` becomes impractical, especially when you don't
care about the column names that could either be known or not known when exploring
tables.
```
> echo [[lib, extension]; [nu-core, rs] [rake, rb]]
─────────┬───────────
lib │ extension
─────────┼───────────
nu-core │ rs
rake │ rb
─────────┴───────────
```
```
> echo [[lib, extension]; [nu-core, rs] [rake, rb]] | drop column
─────────
lib
─────────
nu-core
rake
─────────
```
2021-02-25 21:37:21 +01:00
|
|
|
echo [
|
|
|
|
[arepas, color];
|
|
|
|
[3, white]
|
|
|
|
[8, yellow]
|
|
|
|
[4, white]
|
2022-09-05 16:41:06 +02:00
|
|
|
] | drop column 3 | columns | is-empty
|
2023-04-07 23:09:55 +02:00
|
|
|
"
|
|
|
|
));
|
Allow dropping columns. (#3107)
`drop` is used for removing the last row. Passing a number allows dropping N rows.
Here we introduce the same logic for dropping columns instead.
You can certainly remove columns by using `reject`, however, there could be cases
where we are interested in removing columns from tables that contain, say, a big
number of columns. Using `reject` becomes impractical, especially when you don't
care about the column names that could either be known or not known when exploring
tables.
```
> echo [[lib, extension]; [nu-core, rs] [rake, rb]]
─────────┬───────────
lib │ extension
─────────┼───────────
nu-core │ rs
rake │ rb
─────────┴───────────
```
```
> echo [[lib, extension]; [nu-core, rs] [rake, rb]] | drop column
─────────
lib
─────────
nu-core
rake
─────────
```
2021-02-25 21:37:21 +01:00
|
|
|
|
|
|
|
assert_eq!(actual.out, "true");
|
2020-04-26 08:34:45 +02:00
|
|
|
}
|
2020-07-05 19:46:06 +02:00
|
|
|
|
|
|
|
#[test]
|
Allow dropping columns. (#3107)
`drop` is used for removing the last row. Passing a number allows dropping N rows.
Here we introduce the same logic for dropping columns instead.
You can certainly remove columns by using `reject`, however, there could be cases
where we are interested in removing columns from tables that contain, say, a big
number of columns. Using `reject` becomes impractical, especially when you don't
care about the column names that could either be known or not known when exploring
tables.
```
> echo [[lib, extension]; [nu-core, rs] [rake, rb]]
─────────┬───────────
lib │ extension
─────────┼───────────
nu-core │ rs
rake │ rb
─────────┴───────────
```
```
> echo [[lib, extension]; [nu-core, rs] [rake, rb]] | drop column
─────────
lib
─────────
nu-core
rake
─────────
```
2021-02-25 21:37:21 +01:00
|
|
|
fn rows() {
|
2023-04-07 23:09:55 +02:00
|
|
|
let actual = nu!(pipeline(
|
|
|
|
"
|
Allow dropping columns. (#3107)
`drop` is used for removing the last row. Passing a number allows dropping N rows.
Here we introduce the same logic for dropping columns instead.
You can certainly remove columns by using `reject`, however, there could be cases
where we are interested in removing columns from tables that contain, say, a big
number of columns. Using `reject` becomes impractical, especially when you don't
care about the column names that could either be known or not known when exploring
tables.
```
> echo [[lib, extension]; [nu-core, rs] [rake, rb]]
─────────┬───────────
lib │ extension
─────────┼───────────
nu-core │ rs
rake │ rb
─────────┴───────────
```
```
> echo [[lib, extension]; [nu-core, rs] [rake, rb]] | drop column
─────────
lib
─────────
nu-core
rake
─────────
```
2021-02-25 21:37:21 +01:00
|
|
|
echo [
|
|
|
|
[arepas];
|
|
|
|
|
|
|
|
[3]
|
|
|
|
[8]
|
|
|
|
[4]
|
|
|
|
]
|
|
|
|
| drop 2
|
|
|
|
| get arepas
|
|
|
|
| math sum
|
2023-04-07 23:09:55 +02:00
|
|
|
"
|
|
|
|
));
|
Allow dropping columns. (#3107)
`drop` is used for removing the last row. Passing a number allows dropping N rows.
Here we introduce the same logic for dropping columns instead.
You can certainly remove columns by using `reject`, however, there could be cases
where we are interested in removing columns from tables that contain, say, a big
number of columns. Using `reject` becomes impractical, especially when you don't
care about the column names that could either be known or not known when exploring
tables.
```
> echo [[lib, extension]; [nu-core, rs] [rake, rb]]
─────────┬───────────
lib │ extension
─────────┼───────────
nu-core │ rs
rake │ rb
─────────┴───────────
```
```
> echo [[lib, extension]; [nu-core, rs] [rake, rb]] | drop column
─────────
lib
─────────
nu-core
rake
─────────
```
2021-02-25 21:37:21 +01:00
|
|
|
|
|
|
|
assert_eq!(actual.out, "3");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn more_rows_than_table_has() {
|
2023-04-07 23:09:55 +02:00
|
|
|
let actual = nu!("[date] | drop 50 | length");
|
2020-07-05 19:46:06 +02:00
|
|
|
|
|
|
|
assert_eq!(actual.out, "0");
|
|
|
|
}
|
2022-02-07 14:02:35 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn nth_range_inclusive() {
|
2023-04-07 23:09:55 +02:00
|
|
|
let actual = nu!("echo 10..15 | drop nth (2..3) | to json --raw");
|
2022-02-07 14:02:35 +01:00
|
|
|
|
|
|
|
assert_eq!(actual.out, "[10,11,14,15]");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn nth_range_exclusive() {
|
2023-04-07 23:09:55 +02:00
|
|
|
let actual = nu!("echo 10..15 | drop nth (1..<3) | to json --raw");
|
2022-02-07 14:02:35 +01:00
|
|
|
|
|
|
|
assert_eq!(actual.out, "[10,13,14,15]");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn nth_missing_first_argument() {
|
2023-04-07 23:09:55 +02:00
|
|
|
let actual = nu!("echo 10..15 | drop nth \"\"");
|
2022-02-07 14:02:35 +01:00
|
|
|
|
2022-02-07 20:54:06 +01:00
|
|
|
assert!(actual.err.contains("int or range"));
|
2022-02-07 14:02:35 +01:00
|
|
|
}
|
last, skip, drop, take until, take while, skip until, skip while, where, reverse, shuffle, append, prepend and sort-by raise error when given non-lists (#7623)
Closes https://github.com/nushell/nushell/issues/6941
2022-12-31 12:35:12 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fail_on_non_iterator() {
|
2023-04-07 23:09:55 +02:00
|
|
|
let actual = nu!("1 | drop 50");
|
last, skip, drop, take until, take while, skip until, skip while, where, reverse, shuffle, append, prepend and sort-by raise error when given non-lists (#7623)
Closes https://github.com/nushell/nushell/issues/6941
2022-12-31 12:35:12 +01:00
|
|
|
|
2023-07-14 05:20:35 +02:00
|
|
|
assert!(actual.err.contains("command doesn't support"));
|
last, skip, drop, take until, take while, skip until, skip while, where, reverse, shuffle, append, prepend and sort-by raise error when given non-lists (#7623)
Closes https://github.com/nushell/nushell/issues/6941
2022-12-31 12:35:12 +01:00
|
|
|
}
|
2023-11-09 13:51:46 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn disjoint_columns_first_row_becomes_empty() {
|
|
|
|
let actual = nu!(pipeline(
|
|
|
|
"
|
|
|
|
[{a: 1}, {b: 2, c: 3}]
|
|
|
|
| drop column
|
|
|
|
| columns
|
|
|
|
| to nuon
|
|
|
|
"
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "[b, c]");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn disjoint_columns() {
|
|
|
|
let actual = nu!(pipeline(
|
|
|
|
"
|
|
|
|
[{a: 1, b: 2}, {c: 3}]
|
|
|
|
| drop column
|
|
|
|
| columns
|
|
|
|
| to nuon
|
|
|
|
"
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "[a, c]");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn record() {
|
|
|
|
let actual = nu!("{a: 1, b: 2} | drop column | to nuon");
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "{a: 1}");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn more_columns_than_record_has() {
|
|
|
|
let actual = nu!("{a: 1, b: 2} | drop column 3 | to nuon");
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "{}");
|
|
|
|
}
|