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

Commit

Permalink
Add test of Number parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jul 17, 2023
1 parent 610d7b2 commit 3c68165
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion tests/test_de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use indoc::indoc;
use serde_derive::Deserialize;
use serde_yaml::{Deserializer, Value};
use serde_yaml::{Deserializer, Number, Value};
use std::collections::BTreeMap;
use std::fmt::Debug;

Expand Down Expand Up @@ -676,3 +676,30 @@ fn test_tag_resolution() {

test_de(yaml, &expected);
}

#[test]
fn test_parse_number() {
let n = "111".parse::<Number>().unwrap();
assert_eq!(n, Number::from(111));

let n = "-111".parse::<Number>().unwrap();
assert_eq!(n, Number::from(-111));

let n = "-1.1".parse::<Number>().unwrap();
assert_eq!(n, Number::from(-1.1));

let n = ".nan".parse::<Number>().unwrap();
assert_eq!(n, Number::from(f64::NAN));

let n = ".inf".parse::<Number>().unwrap();
assert_eq!(n, Number::from(f64::INFINITY));

let n = "-.inf".parse::<Number>().unwrap();
assert_eq!(n, Number::from(f64::NEG_INFINITY));

let err = "null".parse::<Number>().unwrap_err();
assert_eq!(err.to_string(), "failed to parse YAML number");

let err = " 1 ".parse::<Number>().unwrap_err();
assert_eq!(err.to_string(), "failed to parse YAML number");
}

0 comments on commit 3c68165

Please sign in to comment.