2020-07-05 17:46:06 +00:00
|
|
|
use nu_test_support::{nu, pipeline};
|
2020-04-26 06:34:45 +00: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 20:37:21 +00:00
|
|
|
fn columns() {
|
2020-04-26 06:34:45 +00:00
|
|
|
let actual = nu!(
|
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 20:37:21 +00:00
|
|
|
cwd: ".", pipeline(r#"
|
|
|
|
echo [
|
|
|
|
[arepas, color];
|
|
|
|
|
|
|
|
[3, white]
|
|
|
|
[8, yellow]
|
|
|
|
[4, white]
|
|
|
|
]
|
|
|
|
| drop column
|
|
|
|
| get
|
2021-03-13 21:46:40 +00:00
|
|
|
| length
|
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 20:37:21 +00:00
|
|
|
"#)
|
2020-04-26 06:34:45 +00: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 20:37:21 +00:00
|
|
|
assert_eq!(actual.out, "1");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn more_columns_than_table_has() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".", pipeline(r#"
|
|
|
|
echo [
|
|
|
|
[arepas, color];
|
|
|
|
|
|
|
|
[3, white]
|
|
|
|
[8, yellow]
|
|
|
|
[4, white]
|
|
|
|
]
|
|
|
|
| drop column 3
|
|
|
|
| get
|
|
|
|
| empty?
|
|
|
|
"#)
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "true");
|
2020-04-26 06:34:45 +00:00
|
|
|
}
|
2020-07-05 17:46:06 +00: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 20:37:21 +00:00
|
|
|
fn rows() {
|
2020-07-05 17:46:06 +00:00
|
|
|
let actual = nu!(
|
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 20:37:21 +00:00
|
|
|
cwd: ".", pipeline(r#"
|
|
|
|
echo [
|
|
|
|
[arepas];
|
|
|
|
|
|
|
|
[3]
|
|
|
|
[8]
|
|
|
|
[4]
|
|
|
|
]
|
|
|
|
| drop 2
|
|
|
|
| get arepas
|
|
|
|
| math sum
|
|
|
|
"#)
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "3");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn more_rows_than_table_has() {
|
2021-03-13 21:46:40 +00:00
|
|
|
let actual = nu!(cwd: ".", "date | drop 50 | length");
|
2020-07-05 17:46:06 +00:00
|
|
|
|
|
|
|
assert_eq!(actual.out, "0");
|
|
|
|
}
|
2022-02-07 13:02:35 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn nth_range_inclusive() {
|
|
|
|
let actual = nu!(cwd: ".", "echo 10..15 | drop nth (2..3) | to json");
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "[10,11,14,15]");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn nth_range_exclusive() {
|
|
|
|
let actual = nu!(cwd: ".", "echo 10..15 | drop nth (1..<3) | to json");
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "[10,13,14,15]");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn nth_missing_first_argument() {
|
|
|
|
let actual = nu!(cwd: ".", "echo 10..15 | drop nth \"\"");
|
|
|
|
|
|
|
|
assert!(actual.err.contains("Expected int or range"));
|
|
|
|
assert!(actual.err.contains("found string"));
|
|
|
|
}
|