2019-12-17 19:54:39 +01:00
|
|
|
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
|
|
|
use nu_test_support::playground::Playground;
|
|
|
|
use nu_test_support::{nu, pipeline};
|
2019-12-15 17:15:06 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn from_ssv_text_to_table() {
|
|
|
|
Playground::setup("filter_from_ssv_test_1", |dirs, sandbox| {
|
2024-05-04 02:53:15 +02:00
|
|
|
sandbox.with_files(&[FileWithContentToBeTrimmed(
|
2019-12-15 17:15:06 +01:00
|
|
|
"oc_get_svc.txt",
|
|
|
|
r#"
|
|
|
|
NAME LABELS SELECTOR IP PORT(S)
|
|
|
|
docker-registry docker-registry=default docker-registry=default 172.30.78.158 5000/TCP
|
|
|
|
kubernetes component=apiserver,provider=kubernetes <none> 172.30.0.2 443/TCP
|
|
|
|
kubernetes-ro component=apiserver,provider=kubernetes <none> 172.30.0.1 80/TCP
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
open oc_get_svc.txt
|
2020-05-04 10:44:33 +02:00
|
|
|
| from ssv
|
2022-02-09 11:58:54 +01:00
|
|
|
| get 0
|
2019-12-15 17:15:06 +01:00
|
|
|
| get IP
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "172.30.78.158");
|
2019-12-15 17:15:06 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn from_ssv_text_to_table_with_separator_specified() {
|
|
|
|
Playground::setup("filter_from_ssv_test_1", |dirs, sandbox| {
|
2024-05-04 02:53:15 +02:00
|
|
|
sandbox.with_files(&[FileWithContentToBeTrimmed(
|
2019-12-15 17:15:06 +01:00
|
|
|
"oc_get_svc.txt",
|
|
|
|
r#"
|
|
|
|
NAME LABELS SELECTOR IP PORT(S)
|
|
|
|
docker-registry docker-registry=default docker-registry=default 172.30.78.158 5000/TCP
|
|
|
|
kubernetes component=apiserver,provider=kubernetes <none> 172.30.0.2 443/TCP
|
|
|
|
kubernetes-ro component=apiserver,provider=kubernetes <none> 172.30.0.1 80/TCP
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
open oc_get_svc.txt
|
2020-05-04 10:44:33 +02:00
|
|
|
| from ssv --minimum-spaces 3
|
2022-02-09 11:58:54 +01:00
|
|
|
| get 0
|
2019-12-15 17:15:06 +01:00
|
|
|
| get IP
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "172.30.78.158");
|
2019-12-15 17:15:06 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn from_ssv_text_treating_first_line_as_data_with_flag() {
|
|
|
|
Playground::setup("filter_from_ssv_test_2", |dirs, sandbox| {
|
2024-05-04 02:53:15 +02:00
|
|
|
sandbox.with_files(&[FileWithContentToBeTrimmed(
|
2019-12-15 17:15:06 +01:00
|
|
|
"oc_get_svc.txt",
|
|
|
|
r#"
|
|
|
|
docker-registry docker-registry=default docker-registry=default 172.30.78.158 5000/TCP
|
|
|
|
kubernetes component=apiserver,provider=kubernetes <none> 172.30.0.2 443/TCP
|
|
|
|
kubernetes-ro component=apiserver,provider=kubernetes <none> 172.30.0.1 80/TCP
|
|
|
|
"#,
|
|
|
|
)]);
|
|
|
|
|
|
|
|
let aligned_columns = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
open oc_get_svc.txt
|
2021-02-22 08:25:17 +01:00
|
|
|
| from ssv --noheaders -a
|
2019-12-15 17:15:06 +01:00
|
|
|
| first
|
Make the subcommands (`from {csv, tsv, ssv}`) 0-based for consistency (#13209)
# Description
fixed #11678
The sub-commands of from command (`from {csv, tsv, ssv}`) name columns
starting from index 0.
This behaviour is inconsistent with other commands such as `detect
columns`.
This PR makes the subcommands index 0-based.
# User-Facing Changes
The subcommands (`from {csv, tsv, ssv}`) return a table with the columns
starting at index 0 if no header data is passed.
```
~/Development/nushell> "foo bar baz" | from ssv -n -m 1
╭───┬─────────┬─────────┬─────────╮
│ # │ column0 │ column1 │ column2 │
├───┼─────────┼─────────┼─────────┤
│ 0 │ foo │ bar │ baz │
╰───┴─────────┴─────────┴─────────╯
~/Development/nushell> "foo,bar,baz" | from csv -n
╭───┬─────────┬─────────┬─────────╮
│ # │ column0 │ column1 │ column2 │
├───┼─────────┼─────────┼─────────┤
│ 0 │ foo │ bar │ baz │
╰───┴─────────┴─────────┴─────────╯
~/Development/nushell> "foo\tbar\tbaz" | from tsv -n
╭───┬─────────┬─────────┬─────────╮
│ # │ column0 │ column1 │ column2 │
├───┼─────────┼─────────┼─────────┤
│ 0 │ foo │ bar │ baz │
╰───┴─────────┴─────────┴─────────╯
```
# Tests + Formatting
When I ran tests, `commands::touch::change_file_mtime_to_reference`
failed with the following error.
The error also occurs in the master branch, so it's probably unrelated
to these changes.
(maybe a problem with my dev environment)
```
$ toolkit check pr
~~~~~~~~
failures:
---- commands::touch::change_file_mtime_to_reference stdout ----
=== stderr
thread 'commands::touch::change_file_mtime_to_reference' panicked at crates/nu-command/tests/commands/touch.rs:298:9:
assertion `left == right` failed
left: SystemTime { tv_sec: 1719149697, tv_nsec: 57576929 }
right: SystemTime { tv_sec: 1719149697, tv_nsec: 78219489 }
failures:
commands::touch::change_file_mtime_to_reference
test result: FAILED. 1533 passed; 1 failed; 32 ignored; 0 measured; 0 filtered out; finished in 10.87s
error: test failed, to rerun pass `-p nu-command --test main`
- :green_circle: `toolkit fmt`
- :green_circle: `toolkit clippy`
- :red_circle: `toolkit test`
- :black_circle: `toolkit test stdlib`
```
# After Submitting
nothing
2024-06-27 00:51:47 +02:00
|
|
|
| get column0
|
2019-12-15 17:15:06 +01:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
let separator_based = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
open oc_get_svc.txt
|
2021-02-22 08:25:17 +01:00
|
|
|
| from ssv --noheaders
|
2019-12-15 17:15:06 +01:00
|
|
|
| first
|
Make the subcommands (`from {csv, tsv, ssv}`) 0-based for consistency (#13209)
# Description
fixed #11678
The sub-commands of from command (`from {csv, tsv, ssv}`) name columns
starting from index 0.
This behaviour is inconsistent with other commands such as `detect
columns`.
This PR makes the subcommands index 0-based.
# User-Facing Changes
The subcommands (`from {csv, tsv, ssv}`) return a table with the columns
starting at index 0 if no header data is passed.
```
~/Development/nushell> "foo bar baz" | from ssv -n -m 1
╭───┬─────────┬─────────┬─────────╮
│ # │ column0 │ column1 │ column2 │
├───┼─────────┼─────────┼─────────┤
│ 0 │ foo │ bar │ baz │
╰───┴─────────┴─────────┴─────────╯
~/Development/nushell> "foo,bar,baz" | from csv -n
╭───┬─────────┬─────────┬─────────╮
│ # │ column0 │ column1 │ column2 │
├───┼─────────┼─────────┼─────────┤
│ 0 │ foo │ bar │ baz │
╰───┴─────────┴─────────┴─────────╯
~/Development/nushell> "foo\tbar\tbaz" | from tsv -n
╭───┬─────────┬─────────┬─────────╮
│ # │ column0 │ column1 │ column2 │
├───┼─────────┼─────────┼─────────┤
│ 0 │ foo │ bar │ baz │
╰───┴─────────┴─────────┴─────────╯
```
# Tests + Formatting
When I ran tests, `commands::touch::change_file_mtime_to_reference`
failed with the following error.
The error also occurs in the master branch, so it's probably unrelated
to these changes.
(maybe a problem with my dev environment)
```
$ toolkit check pr
~~~~~~~~
failures:
---- commands::touch::change_file_mtime_to_reference stdout ----
=== stderr
thread 'commands::touch::change_file_mtime_to_reference' panicked at crates/nu-command/tests/commands/touch.rs:298:9:
assertion `left == right` failed
left: SystemTime { tv_sec: 1719149697, tv_nsec: 57576929 }
right: SystemTime { tv_sec: 1719149697, tv_nsec: 78219489 }
failures:
commands::touch::change_file_mtime_to_reference
test result: FAILED. 1533 passed; 1 failed; 32 ignored; 0 measured; 0 filtered out; finished in 10.87s
error: test failed, to rerun pass `-p nu-command --test main`
- :green_circle: `toolkit fmt`
- :green_circle: `toolkit clippy`
- :red_circle: `toolkit test`
- :black_circle: `toolkit test stdlib`
```
# After Submitting
nothing
2024-06-27 00:51:47 +02:00
|
|
|
| get column0
|
2022-02-20 01:26:47 +01:00
|
|
|
|
2019-12-15 17:15:06 +01:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(aligned_columns.out, separator_based.out);
|
|
|
|
assert_eq!(separator_based.out, "docker-registry");
|
2019-12-15 17:15:06 +01:00
|
|
|
})
|
|
|
|
}
|