From 0b6b321ad60d1b52dbc91551c12a231f2a69b690 Mon Sep 17 00:00:00 2001 From: JT <547158+jntrnr@users.noreply.github.com> Date: Mon, 7 Mar 2022 08:39:02 -0500 Subject: [PATCH] More nuon tests, fix table print (#4762) --- .../tests/format_conversions/nuon.rs | 36 +++++++++++++++++++ crates/nu-engine/src/column.rs | 2 ++ tests/fixtures/formats/sample.nuon | 20 +++++++++++ 3 files changed, 58 insertions(+) create mode 100644 tests/fixtures/formats/sample.nuon diff --git a/crates/nu-command/tests/format_conversions/nuon.rs b/crates/nu-command/tests/format_conversions/nuon.rs index fb02c73a8d..eaba7614f0 100644 --- a/crates/nu-command/tests/format_conversions/nuon.rs +++ b/crates/nu-command/tests/format_conversions/nuon.rs @@ -126,3 +126,39 @@ fn binary_roundtrip() { assert_eq!(actual.out, "0x[1FFF]"); } + +#[test] +fn read_binary_data() { + let actual = nu!( + cwd: "tests/fixtures/formats", pipeline( + r#" + open sample.nuon | get 5.3 + "# + )); + + assert_eq!(actual.out, "31") +} + +#[test] +fn read_record() { + let actual = nu!( + cwd: "tests/fixtures/formats", pipeline( + r#" + open sample.nuon | get 4.name + "# + )); + + assert_eq!(actual.out, "Bobby") +} + +#[test] +fn read_bool() { + let actual = nu!( + cwd: "tests/fixtures/formats", pipeline( + r#" + open sample.nuon | get 3 | $in == $true + "# + )); + + assert_eq!(actual.out, "true") +} diff --git a/crates/nu-engine/src/column.rs b/crates/nu-engine/src/column.rs index 834ad2c86c..28e4a7452b 100644 --- a/crates/nu-engine/src/column.rs +++ b/crates/nu-engine/src/column.rs @@ -11,6 +11,8 @@ pub fn get_columns(input: &[Value]) -> Vec { columns.push(col.to_string()); } } + } else { + return vec![]; } } diff --git a/tests/fixtures/formats/sample.nuon b/tests/fixtures/formats/sample.nuon new file mode 100644 index 0000000000..68b93ddfe4 --- /dev/null +++ b/tests/fixtures/formats/sample.nuon @@ -0,0 +1,20 @@ +# Some sample nuon values +[ + # The nuon compact table format + [[a, nuon, table]; [1, 2, 3], [4, 5, 6]], + + # A filesize + 100kib, + + # A duration + 100sec + + # A boolean + true, + + # A record + {name: "Bobby", age: 99} + + # Binary data + 0x[11, ff, ee, 1f] +] \ No newline at end of file