From b27c7702f911f1e9e12dec3335833fcd41e3a8cd Mon Sep 17 00:00:00 2001 From: Stefan Holderbach Date: Sat, 25 Feb 2023 19:26:34 +0100 Subject: [PATCH] Test more datatypes in nuon (#8211) # Description While working on #8210 I noticed that we did not explicitly check a number of `Value` variants for proper serialization and deserialization. - Test filesize in `to/from nuon` - Test duration in `from/to nuon` - Test datetime in `from/to nuon` - Test graceful failure of closure in `to nuon` # User-Facing Changes (-) # Tests + Formatting All about them tests --- .../tests/format_conversions/nuon.rs | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/crates/nu-command/tests/format_conversions/nuon.rs b/crates/nu-command/tests/format_conversions/nuon.rs index 1ad03a38fb..72ad87c718 100644 --- a/crates/nu-command/tests/format_conversions/nuon.rs +++ b/crates/nu-command/tests/format_conversions/nuon.rs @@ -204,6 +204,100 @@ fn from_nuon_range() { assert_eq!(actual.out, "range"); } +#[test] +fn to_nuon_filesize() { + let actual = nu!( + cwd: "tests/fixtures/formats", pipeline( + r#" + 1kib + | to nuon + "# + )); + + assert_eq!(actual.out, "1024b"); +} + +#[test] +fn from_nuon_filesize() { + let actual = nu!( + cwd: "tests/fixtures/formats", pipeline( + r#" + "1024b" + | from nuon + | describe + "# + )); + + assert_eq!(actual.out, "filesize"); +} + +#[test] +fn to_nuon_duration() { + let actual = nu!( + cwd: "tests/fixtures/formats", pipeline( + r#" + 1min + | to nuon + "# + )); + + assert_eq!(actual.out, "60000000000ns"); +} + +#[test] +fn from_nuon_duration() { + let actual = nu!( + cwd: "tests/fixtures/formats", pipeline( + r#" + "60000000000ns" + | from nuon + | describe + "# + )); + + assert_eq!(actual.out, "duration"); +} + +#[test] +fn to_nuon_datetime() { + let actual = nu!( + cwd: "tests/fixtures/formats", pipeline( + r#" + 2019-05-10 + | to nuon + "# + )); + + assert_eq!(actual.out, "2019-05-10T00:00:00+00:00"); +} + +#[test] +fn from_nuon_datetime() { + let actual = nu!( + cwd: "tests/fixtures/formats", pipeline( + r#" + "2019-05-10T00:00:00+00:00" + | from nuon + | describe + "# + )); + + assert_eq!(actual.out, "date"); +} + +#[test] +fn to_nuon_errs_on_closure() { + let actual = nu!( + cwd: "tests/fixtures/formats", pipeline( + r#" + {|| to nuon} + | to nuon + "# + )); + + assert!(actual.err.contains("not nuon-compatible")); +} + #[test] fn binary_to() { let actual = nu!(