Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thedavidmeister committed Nov 28, 2023
1 parent e923a53 commit f0d9ff4
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 34 deletions.
8 changes: 8 additions & 0 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,14 @@ pub(crate) fn ambiguous_string(scalar: &str) -> bool {
|| lower_scalar == "yes"
|| lower_scalar == "n"
|| lower_scalar == "no"
|| lower_scalar == "on"
|| lower_scalar == "off"
|| lower_scalar == "true"
|| lower_scalar == "false"
|| lower_scalar == "null"
|| lower_scalar == "nil"
|| lower_scalar == "~"
|| lower_scalar == "nan"
}

pub(crate) fn visit_int<'de, V>(visitor: V, v: &str) -> Result<Result<V::Value>, V>
Expand Down
86 changes: 52 additions & 34 deletions tests/test_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,44 +314,62 @@ fn test_strings_needing_quote() {
leading_zeros: '007'
"};
test_serde(&thing, yaml);
}

#[test]
fn test_moar_strings_needing_quote() {
#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct Struct2 {
string: String,
struct Struct {
s: String,
}
// Long hex values that don't fit in a u64 need to be quoted.
let thing2 = Struct2 {
string: "0xffaed20B7B67e498A3bEEf97386ec1849EFeE6Ac".to_owned(),
};
let yaml2 = indoc! {"
string: '0xffaed20B7B67e498A3bEEf97386ec1849EFeE6Ac'
"};
test_serde(&thing2, yaml2);

let thing3 = Struct2 {
string: "".to_owned(),
};
let yaml3 = indoc! {"
string: ''
"};
test_serde(&thing3, yaml3);

let thing4 = Struct2 {
string: " ".to_owned(),
};
let yaml4 = indoc! {"
string: ' '
"};
test_serde(&thing4, yaml4);

// The literal norway problem https://hitchdev.com/strictyaml/why/implicit-typing-removed/
let thing5 = Struct2 {
string: "NO".to_owned(),
};
let yaml5 = indoc! {"
string: 'NO'
"};
test_serde(&thing5, yaml5);
for s in &[
// Short hex values.
"0x0",
"0x1",
// Long hex values that don't fit in a u64 need to be quoted.
"0xffaed20B7B67e498A3bEEf97386ec1849EFeE6Ac",
// "empty" strings.
"",
" ",
// The norway problem https://hitchdev.com/strictyaml/why/implicit-typing-removed/
"NO",
"no",
"No",
"Yes",
"YES",
"yes",
"True",
"TRUE",
"true",
"False",
"FALSE",
"false",
"y",
"Y",
"n",
"N",
"on",
"On",
"ON",
"off",
"Off",
"OFF",
"0",
"1",
"null",
"Null",
"NULL",
"nil",
"Nil",
"NIL",
] {
let thing = Struct {
s: s.to_string(),
};
let yaml = format!("s: '{}'\n", s);
test_serde(&thing, &yaml);
}
}

#[test]
Expand Down

0 comments on commit f0d9ff4

Please sign in to comment.