fix tests

This commit is contained in:
amtoine
2024-11-13 19:33:29 +01:00
parent 1e2d00d69c
commit b74370a6c7
2 changed files with 48 additions and 26 deletions

View File

@@ -2,8 +2,18 @@
use std/assert use std/assert
use std/formats * use std/formats *
def test_data_multiline [] { def test_data_multiline [--nuon] {
let lines = [ let lines = if $nuon {
[
"{a: 1}",
"{a: 2}",
"{a: 3}",
"{a: 4}",
"{a: 5}",
"{a: 6}",
]
} else {
[
"{\"a\":1}", "{\"a\":1}",
"{\"a\":2}", "{\"a\":2}",
"{\"a\":3}", "{\"a\":3}",
@@ -11,6 +21,7 @@ def test_data_multiline [] {
"{\"a\":5}", "{\"a\":5}",
"{\"a\":6}", "{\"a\":6}",
] ]
}
if $nu.os-info.name == "windows" { if $nu.os-info.name == "windows" {
$lines | str join "\r\n" $lines | str join "\r\n"
@@ -87,14 +98,14 @@ def to_jsonl_single_object [] {
#[test] #[test]
def from_ndnuon_multiple_objects [] { def from_ndnuon_multiple_objects [] {
let result = test_data_multiline | formats from ndnuon let result = test_data_multiline | from ndnuon
let expect = [{a:1},{a:2},{a:3},{a:4},{a:5},{a:6}] let expect = [{a:1},{a:2},{a:3},{a:4},{a:5},{a:6}]
assert equal $result $expect "could not convert from NDNUON" assert equal $result $expect "could not convert from NDNUON"
} }
#[test] #[test]
def from_ndnuon_single_object [] { def from_ndnuon_single_object [] {
let result = '{a: 1}' | formats from ndnuon let result = '{a: 1}' | from ndnuon
let expect = [{a:1}] let expect = [{a:1}]
assert equal $result $expect "could not convert from NDNUON" assert equal $result $expect "could not convert from NDNUON"
} }
@@ -106,14 +117,14 @@ def from_ndnuon_invalid_object [] {
#[test] #[test]
def to_ndnuon_multiple_objects [] { def to_ndnuon_multiple_objects [] {
let result = [{a:1},{a:2},{a:3},{a:4},{a:5},{a:6}] | formats to ndnuon | str trim let result = [{a:1},{a:2},{a:3},{a:4},{a:5},{a:6}] | to ndnuon | str trim
let expect = test_data_multiline let expect = test_data_multiline --nuon
assert equal $result $expect "could not convert to NDNUON" assert equal $result $expect "could not convert to NDNUON"
} }
#[test] #[test]
def to_ndnuon_single_object [] { def to_ndnuon_single_object [] {
let result = [{a:1}] | formats to ndnuon | str trim let result = [{a:1}] | to ndnuon | str trim
let expect = "{a: 1}" let expect = "{a: 1}"
assert equal $result $expect "could not convert to NDNUON" assert equal $result $expect "could not convert to NDNUON"
} }

View File

@@ -1,9 +1,19 @@
# Test std/formats when importing `use std *` # Test std/formats when importing `use std *`
use std * use std *
def test_data_multiline [] { def test_data_multiline [--nuon] {
use std * use std *
let lines = [ let lines = if $nuon {
[
"{a: 1}",
"{a: 2}",
"{a: 3}",
"{a: 4}",
"{a: 5}",
"{a: 6}",
]
} else {
[
"{\"a\":1}", "{\"a\":1}",
"{\"a\":2}", "{\"a\":2}",
"{\"a\":3}", "{\"a\":3}",
@@ -11,6 +21,7 @@ def test_data_multiline [] {
"{\"a\":5}", "{\"a\":5}",
"{\"a\":6}", "{\"a\":6}",
] ]
}
if $nu.os-info.name == "windows" { if $nu.os-info.name == "windows" {
$lines | str join "\r\n" $lines | str join "\r\n"
@@ -107,7 +118,7 @@ def from_ndnuon_invalid_object [] {
#[test] #[test]
def to_ndnuon_multiple_objects [] { def to_ndnuon_multiple_objects [] {
let result = [{a:1},{a:2},{a:3},{a:4},{a:5},{a:6}] | formats to ndnuon | str trim let result = [{a:1},{a:2},{a:3},{a:4},{a:5},{a:6}] | formats to ndnuon | str trim
let expect = test_data_multiline let expect = test_data_multiline --nuon
assert equal $result $expect "could not convert to NDNUON" assert equal $result $expect "could not convert to NDNUON"
} }