To csv fix (#7850)

# Description

Fixes #7800 . 
`to csv` and `to tsv` no longer:
- accept anything but records and tables as input,
- accept lists that are not tables,
- accept tables and records with values that are not primitives (other
lists, tables and records).

# User-Facing Changes

Using `to csv` and `to tsv` on any of inputs mentioned above will result
in `cant_convert` error.

# Tests + Formatting

Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.

Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
This commit is contained in:
Artemiy
2023-01-25 17:42:53 +03:00
committed by GitHub
parent e03c354e89
commit b9419e0f36
4 changed files with 162 additions and 80 deletions

View File

@ -207,3 +207,41 @@ fn from_csv_text_skipping_headers_to_table() {
assert_eq!(actual.out, "3");
})
}
#[test]
fn table_with_record_error() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
[[a b]; [1 2] [3 {a: 1 b: 2}]]
| to csv
"#
));
assert!(actual.err.contains("can't convert"))
}
#[test]
fn list_not_table_error() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
[{a: 1 b: 2} {a: 3 b: 4} 1]
| to csv
"#
));
assert!(actual.err.contains("can't convert"))
}
#[test]
fn string_to_csv_error() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
'qwe' | to csv
"#
));
assert!(actual.err.contains("can't convert"))
}