fix tests

This commit is contained in:
Robin Appelman 2021-09-09 15:19:31 +02:00
commit bd3f415eae
3 changed files with 34 additions and 6 deletions

View file

@ -292,6 +292,12 @@ impl From<&str> for Value {
} }
} }
impl From<HashMap<Key, Value>> for Value {
fn from(value: HashMap<Key, Value>) -> Self {
Value::Array(value)
}
}
impl Display for Value { impl Display for Value {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self { match self {

View file

@ -769,9 +769,8 @@ mod tests {
match super::from_str(source) { match super::from_str(source) {
Ok(res) => Ok(res), Ok(res) => Ok(res),
Err(err) => { Err(err) => {
let sourced = err.with_source(source); eprintln!("{}", err);
eprintln!("{}", sourced); Err(err)
Err(sourced.into_inner())
} }
} }
} }

View file

@ -5,9 +5,8 @@ fn parse(source: &str) -> Result<Value, ParseError> {
match from_str(source) { match from_str(source) {
Ok(res) => Ok(res), Ok(res) => Ok(res),
Err(err) => { Err(err) => {
let sourced = err.with_source(source); eprintln!("{}", err);
eprintln!("{}", sourced); Err(err)
Err(sourced.into_inner())
} }
} }
} }
@ -130,6 +129,30 @@ fn test_parse_value() {
}), }),
parse(r#"array("2"=>3,"foo" => 4, null => 5, true => 6, false => 7)"#).unwrap() parse(r#"array("2"=>3,"foo" => 4, null => 5, true => 6, false => 7)"#).unwrap()
); );
assert_eq!(
Value::Array(hashmap! {
Key::Int(0) => hashmap! {
Key::String("a".into()) => Value::Int(2),
}.into(),
Key::Int(1) => hashmap! {
Key::String("b".into()) => Value::Int(3),
}.into()
}),
parse(r#"[["a" => 2], ["b" => 3]]"#).unwrap()
);
assert_eq!(
Value::Array(hashmap! {
Key::Int(0) => hashmap! {
Key::String("a".into()) => Value::Int(2),
}.into(),
Key::Int(1) => hashmap! {
Key::String("b".into()) => Value::Int(3),
}.into()
}),
parse(r#"array(array("a" => 2), array("b" => 3))"#).unwrap()
);
} }
#[test] #[test]