2020-03-29 04:05:57 +02:00
|
|
|
use nu_test_support::{nu, pipeline};
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn headers_uses_first_row_as_header() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2020-03-29 04:05:57 +02:00
|
|
|
open sample_headers.xlsx
|
|
|
|
| get Sheet1
|
|
|
|
| headers
|
|
|
|
| get header0
|
2023-07-21 17:32:37 +02:00
|
|
|
| to json --raw"
|
2020-03-29 04:05:57 +02:00
|
|
|
));
|
|
|
|
|
2022-02-15 16:08:07 +01:00
|
|
|
assert_eq!(actual.out, r#"["r1c0","r2c0"]"#)
|
2020-03-29 04:05:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn headers_adds_missing_column_name() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2020-03-29 04:05:57 +02:00
|
|
|
open sample_headers.xlsx
|
|
|
|
| get Sheet1
|
|
|
|
| headers
|
2022-02-20 01:26:47 +01:00
|
|
|
| get column1
|
2023-07-21 17:32:37 +02:00
|
|
|
| to json --raw"
|
2020-03-29 04:05:57 +02:00
|
|
|
));
|
|
|
|
|
2022-02-15 16:08:07 +01:00
|
|
|
assert_eq!(actual.out, r#"["r1c1","r2c1"]"#)
|
2020-03-29 04:05:57 +02:00
|
|
|
}
|
2022-11-10 01:43:24 +01:00
|
|
|
|
2023-07-06 19:54:59 +02:00
|
|
|
#[test]
|
|
|
|
fn headers_handles_missing_values() {
|
|
|
|
let actual = nu!(pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2023-07-06 19:54:59 +02:00
|
|
|
[{x: a, y: b}, {x: 1, y: 2}, {x: 1, z: 3}]
|
|
|
|
| headers
|
|
|
|
| to nuon --raw
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2023-07-06 19:54:59 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "[{a: 1, b: 2}, {a: 1}]")
|
|
|
|
}
|
|
|
|
|
2022-11-10 01:43:24 +01:00
|
|
|
#[test]
|
|
|
|
fn headers_invalid_column_type_empty_record() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-11-10 01:43:24 +01:00
|
|
|
[[a b]; [{}, 2], [3,4] ]
|
2023-07-21 17:32:37 +02:00
|
|
|
| headers"
|
2022-11-10 01:43:24 +01:00
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual
|
|
|
|
.err
|
|
|
|
.contains("needs compatible type: Null, String, Bool, Float, Int"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn headers_invalid_column_type_record() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2023-06-20 23:33:01 +02:00
|
|
|
[[a b]; [1 (scope aliases)] [2 2]]
|
2023-07-21 17:32:37 +02:00
|
|
|
| headers"
|
2022-11-10 01:43:24 +01:00
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual
|
|
|
|
.err
|
|
|
|
.contains("needs compatible type: Null, String, Bool, Float, Int"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn headers_invalid_column_type_array() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-11-10 01:43:24 +01:00
|
|
|
[[a b]; [[f,g], 2], [3,4] ]
|
2023-07-21 17:32:37 +02:00
|
|
|
| headers"
|
2022-11-10 01:43:24 +01:00
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual
|
|
|
|
.err
|
|
|
|
.contains("needs compatible type: Null, String, Bool, Float, Int"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn headers_invalid_column_type_range() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-11-10 01:43:24 +01:00
|
|
|
[[a b]; [(1..5), 2], [3,4] ]
|
2023-07-21 17:32:37 +02:00
|
|
|
| headers"
|
2022-11-10 01:43:24 +01:00
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual
|
|
|
|
.err
|
|
|
|
.contains("needs compatible type: Null, String, Bool, Float, Int"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn headers_invalid_column_type_duration() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2022-11-10 01:43:24 +01:00
|
|
|
[[a b]; [((date now) - (date now)), 2], [3,4] ]
|
2023-07-21 17:32:37 +02:00
|
|
|
| headers"
|
2022-11-10 01:43:24 +01:00
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual
|
|
|
|
.err
|
|
|
|
.contains("needs compatible type: Null, String, Bool, Float, Int"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn headers_invalid_column_type_binary() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2022-11-10 01:43:24 +01:00
|
|
|
r#"
|
|
|
|
[[a b]; [("aa" | into binary), 2], [3,4] ]
|
|
|
|
| headers"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual
|
|
|
|
.err
|
|
|
|
.contains("needs compatible type: Null, String, Bool, Float, Int"));
|
|
|
|
}
|