mirror of
https://github.com/nushell/nushell
synced 2024-12-28 22:13:10 +00:00
fbf3f7cf1c
# Description This splits off `scope` from `$nu`, creating a set of `scope` commands for the various types of scope you might be interested in. This also simplifies the `$nu` variable a bit. # User-Facing Changes This changes `$nu` to be a bit simpler and introduces a set of `scope` subcommands. # 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 -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # 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. -->
115 lines
2.6 KiB
Rust
115 lines
2.6 KiB
Rust
use nu_test_support::{nu, pipeline};
|
|
|
|
#[test]
|
|
fn headers_uses_first_row_as_header() {
|
|
let actual = nu!(
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
r#"
|
|
open sample_headers.xlsx
|
|
| get Sheet1
|
|
| headers
|
|
| get header0
|
|
| to json --raw"#
|
|
));
|
|
|
|
assert_eq!(actual.out, r#"["r1c0","r2c0"]"#)
|
|
}
|
|
|
|
#[test]
|
|
fn headers_adds_missing_column_name() {
|
|
let actual = nu!(
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
r#"
|
|
open sample_headers.xlsx
|
|
| get Sheet1
|
|
| headers
|
|
| get column1
|
|
| to json --raw"#
|
|
));
|
|
|
|
assert_eq!(actual.out, r#"["r1c1","r2c1"]"#)
|
|
}
|
|
|
|
#[test]
|
|
fn headers_invalid_column_type_empty_record() {
|
|
let actual = nu!(
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
r#"
|
|
[[a b]; [{}, 2], [3,4] ]
|
|
| headers"#
|
|
));
|
|
|
|
assert!(actual
|
|
.err
|
|
.contains("needs compatible type: Null, String, Bool, Float, Int"));
|
|
}
|
|
|
|
#[test]
|
|
fn headers_invalid_column_type_record() {
|
|
let actual = nu!(
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
r#"
|
|
[[a b]; [1 (scope aliases)] [2 2]]
|
|
| headers"#
|
|
));
|
|
|
|
assert!(actual
|
|
.err
|
|
.contains("needs compatible type: Null, String, Bool, Float, Int"));
|
|
}
|
|
|
|
#[test]
|
|
fn headers_invalid_column_type_array() {
|
|
let actual = nu!(
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
r#"
|
|
[[a b]; [[f,g], 2], [3,4] ]
|
|
| headers"#
|
|
));
|
|
|
|
assert!(actual
|
|
.err
|
|
.contains("needs compatible type: Null, String, Bool, Float, Int"));
|
|
}
|
|
|
|
#[test]
|
|
fn headers_invalid_column_type_range() {
|
|
let actual = nu!(
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
r#"
|
|
[[a b]; [(1..5), 2], [3,4] ]
|
|
| headers"#
|
|
));
|
|
|
|
assert!(actual
|
|
.err
|
|
.contains("needs compatible type: Null, String, Bool, Float, Int"));
|
|
}
|
|
|
|
#[test]
|
|
fn headers_invalid_column_type_duration() {
|
|
let actual = nu!(
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
r#"
|
|
[[a b]; [((date now) - (date now)), 2], [3,4] ]
|
|
| headers"#
|
|
));
|
|
|
|
assert!(actual
|
|
.err
|
|
.contains("needs compatible type: Null, String, Bool, Float, Int"));
|
|
}
|
|
|
|
#[test]
|
|
fn headers_invalid_column_type_binary() {
|
|
let actual = nu!(
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
r#"
|
|
[[a b]; [("aa" | into binary), 2], [3,4] ]
|
|
| headers"#
|
|
));
|
|
|
|
assert!(actual
|
|
.err
|
|
.contains("needs compatible type: Null, String, Bool, Float, Int"));
|
|
}
|