mirror of
https://codeberg.org/icewind/php-literal-parser.git
synced 2026-06-03 10:34:08 +02:00
allow trailing semicolon
This commit is contained in:
parent
20dad94035
commit
688f4fb6f4
4 changed files with 26 additions and 17 deletions
|
|
@ -1,20 +1,19 @@
|
|||
use maplit::hashmap;
|
||||
use php_literal_parser::{from_str, Key, ParseError, Value};
|
||||
|
||||
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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_value() {
|
||||
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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
use maplit::hashmap;
|
||||
|
||||
assert_eq!(Value::Bool(true), parse("true").unwrap());
|
||||
assert_eq!(Value::Bool(false), parse("false").unwrap());
|
||||
assert_eq!(Value::Int(12), parse("12").unwrap());
|
||||
|
|
@ -132,3 +131,8 @@ fn test_parse_value() {
|
|||
parse(r#"array("2"=>3,"foo" => 4, null => 5, true => 6, false => 7)"#).unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_trailing_semi() {
|
||||
assert_eq!(Value::Int(12), parse(r#"12;"#).unwrap());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue