@@ -45,6 +45,37 @@ mod without_metadata {
4545 assert_eq ! ( address[ "street" ] . clone( ) . into_immutable_string( ) . expect( "address.street should exist" ) , "10 Downing Street" ) ;
4646 }
4747
48+ #[ test]
49+ #[ cfg( not( feature = "no_function" ) ) ]
50+ #[ cfg( not( feature = "no_object" ) ) ]
51+ #[ cfg( not( feature = "no_float" ) ) ]
52+ fn test_parse_json_scientific_notation ( ) {
53+ let engine = Engine :: new ( ) ;
54+ let mut scope = Scope :: new ( ) ;
55+
56+ let map = engine
57+ . eval_with_scope :: < Map > (
58+ & mut scope,
59+ r#"
60+ parse_json("{\
61+ \"positive_exp\": 1.23e4,\
62+ \"negative_exp\": 1.5e-5,\
63+ \"capital_e\": 2.5E+10,\
64+ \"integer_exp\": 3e2,\
65+ \"zero_exp\": 4.2e0\
66+ }")
67+ "# ,
68+ )
69+ . unwrap ( ) ;
70+
71+ assert_eq ! ( map. len( ) , 5 ) ;
72+ assert_eq ! ( map[ "positive_exp" ] . as_float( ) . expect( "positive_exp should exist" ) , 1.23e4 ) ;
73+ assert_eq ! ( map[ "negative_exp" ] . as_float( ) . expect( "negative_exp should exist" ) , 1.5e-5 ) ;
74+ assert_eq ! ( map[ "capital_e" ] . as_float( ) . expect( "capital_e should exist" ) , 2.5E+10 ) ;
75+ assert_eq ! ( map[ "integer_exp" ] . as_float( ) . expect( "integer_exp should exist" ) , 3e2 ) ;
76+ assert_eq ! ( map[ "zero_exp" ] . as_float( ) . expect( "zero_exp should exist" ) , 4.2e0 ) ;
77+ }
78+
4879 #[ test]
4980 #[ cfg( feature = "no_index" ) ]
5081 #[ cfg( not( feature = "no_object" ) ) ]
@@ -140,6 +171,37 @@ mod with_metadata {
140171 assert_eq ! ( address[ "street" ] . clone( ) . into_immutable_string( ) . expect( "address.street should exist" ) , "10 Downing Street" ) ;
141172 }
142173
174+ #[ test]
175+ #[ cfg( not( feature = "no_function" ) ) ]
176+ #[ cfg( not( feature = "no_object" ) ) ]
177+ #[ cfg( not( feature = "no_float" ) ) ]
178+ fn test_parse_json_scientific_notation ( ) {
179+ let engine = Engine :: new ( ) ;
180+ let mut scope = Scope :: new ( ) ;
181+
182+ let map = engine
183+ . eval_with_scope :: < Map > (
184+ & mut scope,
185+ r#"
186+ parse_json("{\
187+ \"positive_exp\": 1.23e4,\
188+ \"negative_exp\": 1.5e-5,\
189+ \"capital_e\": 2.5E+10,\
190+ \"integer_exp\": 3e2,\
191+ \"zero_exp\": 4.2e0\
192+ }")
193+ "# ,
194+ )
195+ . unwrap ( ) ;
196+
197+ assert_eq ! ( map. len( ) , 5 ) ;
198+ assert_eq ! ( map[ "positive_exp" ] . as_float( ) . expect( "positive_exp should exist" ) , 1.23e4 ) ;
199+ assert_eq ! ( map[ "negative_exp" ] . as_float( ) . expect( "negative_exp should exist" ) , 1.5e-5 ) ;
200+ assert_eq ! ( map[ "capital_e" ] . as_float( ) . expect( "capital_e should exist" ) , 2.5E+10 ) ;
201+ assert_eq ! ( map[ "integer_exp" ] . as_float( ) . expect( "integer_exp should exist" ) , 3e2 ) ;
202+ assert_eq ! ( map[ "zero_exp" ] . as_float( ) . expect( "zero_exp should exist" ) , 4.2e0 ) ;
203+ }
204+
143205 #[ test]
144206 #[ cfg( feature = "no_index" ) ]
145207 #[ cfg( not( feature = "no_object" ) ) ]
0 commit comments