mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 14:40:06 +02:00
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:
@ -152,6 +152,7 @@ shadow-rs = { version = "0.16.1", default-features = false }
|
||||
[dev-dependencies]
|
||||
hamcrest2 = "0.3.0"
|
||||
dirs-next = "2.0.0"
|
||||
proptest = "1.0.0"
|
||||
quickcheck = "1.0.3"
|
||||
quickcheck_macros = "1.0.0"
|
||||
rstest = {version = "0.15.0", default-features = false}
|
||||
|
@ -0,0 +1,23 @@
|
||||
# Seeds for failure cases proptest has generated in the past. It is
|
||||
# automatically read and these particular cases re-run before any
|
||||
# novel cases are generated.
|
||||
#
|
||||
# It is recommended to check this file in to source control so that
|
||||
# everyone who runs the test benefits from these saved cases.
|
||||
cc 96a80ecd19729fb43a7b7bb2766b37d6083ba73b16abb97075875e3cfcdc763f # shrinks to c = '"'
|
||||
cc 4146602559ea717a02bcef3c6d73cdf613c30d0c3f92c48e26c79b9a1544e027 # shrinks to c = '\\'
|
||||
cc 80532a0ee73df456a719b9e3cce1ae5f3d26009dde819cbaf16f8e0cb6709705 # shrinks to c = ':'
|
||||
cc cdb88505686eea3c74c36f282fd29b2b68bc118ded4ebfc36f9838d174bd7653 # shrinks to c = '`'
|
||||
cc 0f534d55f9771e8810b9c4252a4168abfaec1a35e1b0cac12dbaf726d295a08c # shrinks to c = '\0'
|
||||
cc 5d31bcbab722acd1f4e23ca3a4f95ff309a636b45a73ca8ae9f820d93ff57acc # shrinks to c = '{'
|
||||
cc 5afec063bc96160d681d77f90041b67ef5cfdea4dcbd12d984fd828fbeb4b421 # shrinks to c = '#'
|
||||
cc f919beb3ee5c70e756a15635d65ded7d44f3ae58b5e86b6c09e814d5d8cdd506 # shrinks to c = ';'
|
||||
cc ec00f39b8d45dfd8808947a56af5e50ba5a0ef7c951723b45377815a02e515b1 # shrinks to c = '('
|
||||
cc 25b773cdf4c24179151fa86244c7de4136e05df9e94e6ee77a336ebfd8764444 # shrinks to c = '|'
|
||||
cc 94dc0d54b97d59e1c0f4cb11bdccb3823a1bb908cbc3fd643ee8f067169fad72 # shrinks to c = '0'
|
||||
cc c9d0051fb1e5a8bdc1d4f5a3dceac1b4b465827d1dff4fc3a3755baae6a7bb48 # shrinks to c = '$'
|
||||
cc 14ec40d2eb5bd2663e9b11bb49fb2120852f9ea71678c69d732161412b55a3ec # shrinks to s = ""
|
||||
cc d4afccc51ed9d421bdb7e1723e273dfb6e77c3a449489671a496db234e87c5ed # shrinks to c = '\r'
|
||||
cc 515a56d73eb1b69290ef4c714b629421989879aebd57991bd2c2bf11294353b1 # shrinks to s = "\\\\𐊀{"
|
||||
cc 111566990fffa432acd2dbc845141b0e7870f97125c7621e3ddf142204568246 # shrinks to s = "'\":`"
|
||||
cc 0424c33000d9188be96b3049046eb052770b2158bf5ebb0c98656d7145e8aca9 # shrinks to s = "0"
|
@ -192,15 +192,23 @@ fn to_nuon(call: &Call, input: PipelineData) -> Result<String, ShellError> {
|
||||
|
||||
fn needs_quotes(string: &str) -> bool {
|
||||
string.contains(' ')
|
||||
|| string.contains(',')
|
||||
|| string.contains('[')
|
||||
|| string.contains(']')
|
||||
|| string.contains(':')
|
||||
|| string.contains('`')
|
||||
|| string.contains('{')
|
||||
|| string.contains('}')
|
||||
|| string.contains('#')
|
||||
|| string.contains('\'')
|
||||
|| string.contains(';')
|
||||
|| string.contains('(')
|
||||
|| string.contains(')')
|
||||
|| string.contains('[')
|
||||
|| string.contains(']')
|
||||
|| string.contains('{')
|
||||
|| string.contains('}')
|
||||
|| string.contains('|')
|
||||
|| string.contains('$')
|
||||
|| string.contains(',')
|
||||
|| string.contains('\t')
|
||||
|| string.contains('\n')
|
||||
|| string.contains('\r')
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user