mirror of
https://codeberg.org/icewind/php-literal-parser.git
synced 2026-06-03 18:44:07 +02:00
fix tests
This commit is contained in:
parent
d185883573
commit
bd3f415eae
3 changed files with 34 additions and 6 deletions
|
|
@ -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 {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
|
|
|
|||
|
|
@ -769,9 +769,8 @@ mod tests {
|
|||
match super::from_str(source) {
|
||||
Ok(res) => Ok(res),
|
||||
Err(err) => {
|
||||
let sourced = err.with_source(source);
|
||||
eprintln!("{}", sourced);
|
||||
Err(sourced.into_inner())
|
||||
eprintln!("{}", err);
|
||||
Err(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,8 @@ fn parse(source: &str) -> Result<Value, ParseError> {
|
|||
match from_str(source) {
|
||||
Ok(res) => Ok(res),
|
||||
Err(err) => {
|
||||
let sourced = err.with_source(source);
|
||||
eprintln!("{}", sourced);
|
||||
Err(sourced.into_inner())
|
||||
eprintln!("{}", err);
|
||||
Err(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -130,6 +129,30 @@ fn test_parse_value() {
|
|||
}),
|
||||
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]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue