add from ndnuon and to ndnuon to stdlib

This commit is contained in:
amtoine 2024-11-13 18:35:42 +01:00
parent 30f98f7e64
commit e33d621311
No known key found for this signature in database
GPG Key ID: 37AAE9B486CFF1AB
3 changed files with 48 additions and 0 deletions

View File

@ -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
}

View File

@ -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 }
}

View File

@ -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 }
}