mirror of
https://github.com/nushell/nushell.git
synced 2025-01-07 14:59:36 +01:00
add from ndnuon
and to ndnuon
to stdlib
This commit is contained in:
parent
30f98f7e64
commit
e33d621311
@ -28,3 +28,13 @@ export def "to ndjson" []: any -> string {
|
||||
export def "to jsonl" []: any -> string {
|
||||
each { to json --raw } | to text
|
||||
}
|
||||
|
||||
# Convert from NDNUON, i.e. newline-delimited NUON, to structured
|
||||
def "from ndnuon" []: [string -> any] {
|
||||
lines | each { from nuon }
|
||||
}
|
||||
|
||||
# Convert structured data to NDNUON, i.e. newline-delimited NUON
|
||||
def "to ndnuon" []: [any -> string] {
|
||||
each { to nuon --raw } | to text
|
||||
}
|
||||
|
@ -84,3 +84,22 @@ def to_jsonl_single_object [] {
|
||||
let expect = "{\"a\":1}"
|
||||
assert equal $result $expect "could not convert to JSONL"
|
||||
}
|
||||
|
||||
#[test]
|
||||
def from_ndnuon_multiple_objects [] {
|
||||
let result = test_data_multiline | formats from ndnuon
|
||||
let expect = [{a:1},{a:2},{a:3},{a:4},{a:5},{a:6}]
|
||||
assert equal $result $expect "could not convert from NDNUON"
|
||||
}
|
||||
|
||||
#[test]
|
||||
def from_ndnuon_single_object [] {
|
||||
let result = '{a: 1}' | formats from ndnuon
|
||||
let expect = [{a:1}]
|
||||
assert equal $result $expect "could not convert from NDNUON"
|
||||
}
|
||||
|
||||
#[test]
|
||||
def from_ndnuon_invalid_object [] {
|
||||
assert error { '{"a":1' | formats from ndnuon }
|
||||
}
|
||||
|
@ -84,3 +84,22 @@ def to_jsonl_single_object [] {
|
||||
let expect = "{\"a\":1}"
|
||||
assert equal $result $expect "could not convert to JSONL"
|
||||
}
|
||||
|
||||
#[test]
|
||||
def from_ndnuon_multiple_objects [] {
|
||||
let result = test_data_multiline | formats from ndnuon
|
||||
let expect = [{a:1},{a:2},{a:3},{a:4},{a:5},{a:6}]
|
||||
assert equal $result $expect "could not convert from NDNUON"
|
||||
}
|
||||
|
||||
#[test]
|
||||
def from_ndnuon_single_object [] {
|
||||
let result = '{a: 1}' | formats from ndnuon
|
||||
let expect = [{a:1}]
|
||||
assert equal $result $expect "could not convert from NDNUON"
|
||||
}
|
||||
|
||||
#[test]
|
||||
def from_ndnuon_invalid_object [] {
|
||||
assert error { '{"a":1' | formats from ndnuon }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user