@@ -574,7 +574,8 @@ make_parser!(
574
574
575
575
make_parser ! (
576
576
ObjectValue ( input: char , constant: & bool ) -> Value {
577
- between( char ( '{' ) , char ( '}' ) , many:: <Vec <_>, _>( ObjectField :: new( constant) ) )
577
+ between( char ( '{' )
578
+ . skip( many:: <Vec <_>, _>( or( WhiteSpace :: new( ) , LineTerminator :: new( & true ) ) ) ) , char ( '}' ) , many:: <Vec <_>, _>( ObjectField :: new( constant) ) )
578
579
. skip( many:: <Vec <_>, _>( or( WhiteSpace :: new( ) , LineTerminator :: new( & true ) ) ) )
579
580
. map( |fields| {
580
581
let mut result = HashMap :: new( ) ;
@@ -607,6 +608,8 @@ mod tests {
607
608
use super :: * ;
608
609
use combine:: { State , Parser } ;
609
610
611
+ use std:: collections:: HashMap ;
612
+
610
613
macro_rules! assert_successful_parse {
611
614
// base case
612
615
( ) => { } ;
@@ -789,5 +792,17 @@ mod tests {
789
792
assert_successful_parse ! ( EnumValue , "test" , Value :: Enum ( String :: from( "test" ) ) ) ;
790
793
}
791
794
792
- // TODO add tests for object value
795
+ #[ test]
796
+ fn test_parse_objectvalue_empty ( ) {
797
+ assert_successful_parse ! ( ObjectValue :: new( & true ) , "{}" , Value :: Object ( HashMap :: new( ) ) ) ;
798
+ }
799
+
800
+ #[ test]
801
+ fn test_parse_objectvalue_onefield ( ) {
802
+ let mut map = HashMap :: new ( ) ;
803
+ map. insert ( String :: from ( "x" ) , Value :: Int ( 1 ) ) ;
804
+ let value = Value :: Object ( map) ;
805
+
806
+ assert_successful_parse ! ( ObjectValue :: new( & true ) , "{ x : 1 }" , value) ;
807
+ }
793
808
}
0 commit comments