mirror of
https://github.com/nushell/nushell
synced 2024-12-26 04:53:09 +00:00
fix multiline strings in NDNUON (#14519)
- should close https://github.com/nushell/nushell/issues/14517 # Description this will change `to ndnuon` so that newlines are encoded as a literal `\n` which `from ndnuon` is already able to handle # User-Facing Changes users should be able to encode multiline strings in NDNUON # Tests + Formatting new tests have been added: - they don't pass on the first commit - they do pass with the fix # After Submitting
This commit is contained in:
parent
234484b6f8
commit
d97562f6e8
3 changed files with 29 additions and 1 deletions
|
@ -36,5 +36,5 @@ export def "from ndnuon" []: [string -> any] {
|
|||
|
||||
# Convert structured data to NDNUON, i.e. newline-delimited NUON
|
||||
export def "to ndnuon" []: [any -> string] {
|
||||
each { to nuon --raw } | to text
|
||||
each { to nuon --raw | str replace --all "\n" '\n' } | to text
|
||||
}
|
||||
|
|
|
@ -128,3 +128,17 @@ def to_ndnuon_single_object [] {
|
|||
let expect = "{a: 1}"
|
||||
assert equal $result $expect "could not convert to NDNUON"
|
||||
}
|
||||
|
||||
#[test]
|
||||
def to_ndnuon_multiline_strings [] {
|
||||
let result = "foo\n\\n\nbar" | to ndnuon
|
||||
let expect = '"foo\n\\n\nbar"'
|
||||
assert equal $result $expect "could not convert multiline string to NDNUON"
|
||||
}
|
||||
|
||||
#[test]
|
||||
def from_ndnuon_multiline_strings [] {
|
||||
let result = '"foo\n\\n\nbar"' | from ndnuon
|
||||
let expect = ["foo\n\\n\nbar"]
|
||||
assert equal $result $expect "could not convert multiline string from NDNUON"
|
||||
}
|
||||
|
|
|
@ -128,3 +128,17 @@ def to_ndnuon_single_object [] {
|
|||
let expect = "{a: 1}"
|
||||
assert equal $result $expect "could not convert to NDNUON"
|
||||
}
|
||||
|
||||
#[test]
|
||||
def to_ndnuon_multiline_strings [] {
|
||||
let result = "foo\n\\n\nbar" | formats to ndnuon
|
||||
let expect = '"foo\n\\n\nbar"'
|
||||
assert equal $result $expect "could not convert multiline string to NDNUON"
|
||||
}
|
||||
|
||||
#[test]
|
||||
def from_ndnuon_multiline_strings [] {
|
||||
let result = '"foo\n\\n\nbar"' | formats from ndnuon
|
||||
let expect = ["foo\n\\n\nbar"]
|
||||
assert equal $result $expect "could not convert multiline string from NDNUON"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue