add tests, deal with pipes, newlines, tabs for to nuon (#6391)

* remove unnecessary FlatShape

* add proptest

* remove files that belonged in another PR

* more tests, more chars

* add exception for parser error unrelated ot PR
This commit is contained in:
pwygab
2022-09-01 20:08:19 +08:00
committed by GitHub
parent fbe9d6f529
commit 34e58bc5d6
5 changed files with 123 additions and 6 deletions

View File

@ -1,4 +1,5 @@
use nu_test_support::{nu, pipeline};
use proptest::prelude::*;
#[test]
fn to_nuon_correct_compaction() {
@ -267,3 +268,39 @@ fn to_nuon_does_not_quote_unnecessarily() {
));
assert_eq!(actual.out, "{\"ro name\": sam, rank: 10}");
}
proptest! {
#[test]
fn to_nuon_from_nuon(c: char) {
if c != '\0' && c!='\r' {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
format!(r#"
{{"prop{0}test": "sam"}} | to nuon | from nuon;
[ [ "prop{0}test" ]; [ 'test' ] ] | to nuon | from nuon;
[ [ "{0}" ]; [ 'test' ] ] | to nuon | from nuon;
{{"{0}": "sam"}} | to nuon | from nuon;
"#, c).as_ref()
));
assert!(actual.err.is_empty() || actual.err.contains("Unexpected end of code") || actual.err.contains("only strings can be keys"));
// The second is for weird escapes due to backslashes
// The third is for chars like '0'
}
}
#[test]
fn to_nuon_from_nuon_string(s: String) {
if s != "\\0" && s!= "" && !s.contains('\\') && !s.contains('"'){
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
format!(r#"
{{"prop{0}test": "sam"}} | to nuon | from nuon;
[ [ "prop{0}test" ]; [ 'test' ] ] | to nuon | from nuon;
[ [ "{0}" ]; [ 'test' ] ] | to nuon | from nuon;
{{"{0}": "sam"}} | to nuon | from nuon;
"#, s).as_ref()
));
assert!(actual.err.is_empty() || actual.err.contains("only strings can be keys") || actual.err.contains("unknown command"));
// TODO: fix parser error for "unknown command" when '=$' is the name
}
}
}