You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let contents = String::from("{\"ab\":\"c\\\"d\\\"e\"}");
795
+
796
+
let actual = parse(&contents).unwrap();
797
+
let serialized = stringify(actual.clone());
798
+
799
+
assert_eq!(serialized, contents);
800
+
}
801
+
802
+
#[test]
803
+
fnit_should_parse_basic_json_values(){
804
+
let s = "{\"a\":1,\"b\":true,\"c\":false,\"d\":null,\"e\":2}";
805
+
let actual = parse(s).unwrap();
806
+
letmut expected = object!{
807
+
"a" => 1,
808
+
"b" => true,
809
+
"c" => false,
810
+
"e" => 2
811
+
};
812
+
expected["d"] = JsonValue::Null;
813
+
814
+
assert_eq!(actual, expected);
815
+
}
816
+
817
+
#[test]
818
+
fnit_should_parse_json_arrays(){
819
+
let s = "{\"a\":1,\"b\":true,\"c\":false,\"d\":null,\"e\":2,\"f\":[1,2,3,false,true,[],{}]}";
820
+
let actual = parse(s).unwrap();
821
+
letmut expected = object!{
822
+
"a" => 1,
823
+
"b" => true,
824
+
"c" => false,
825
+
"e" => 2
826
+
};
827
+
expected["d"] = JsonValue::Null;
828
+
expected["f"] = array![
829
+
1,2,3,
830
+
false,
831
+
true,
832
+
array![],
833
+
object!{}
834
+
];
835
+
836
+
assert_eq!(actual, expected);
837
+
}
838
+
839
+
#[test]
840
+
fnit_should_parse_json_nested_object(){
841
+
let s = "{\"a\":1,\"b\":{\"c\":2,\"d\":{\"e\":{\"f\":{\"g\":3,\"h\":[]}}},\"i\":4,\"j\":[],\"k\":{\"l\":5,\"m\":{}}}}";
842
+
let actual = parse(s).unwrap();
843
+
letmut expected = object!{
844
+
"a" => 1,
845
+
"b" => object!{
846
+
"c" => 2,
847
+
"d" => object!{
848
+
"e" => object! {
849
+
"f" => object!{
850
+
"g" => 3,
851
+
"h" => array![]
852
+
}
853
+
}
854
+
},
855
+
"i" => 4,
856
+
"j" => array![],
857
+
"k" => object!{
858
+
"l" => 5,
859
+
"m" => object!{}
860
+
}
861
+
}
862
+
};
863
+
864
+
assert_eq!(actual, expected);
865
+
}
866
+
867
+
#[test]
868
+
fnit_should_parse_json_complex_object(){
869
+
let s = "{\"a\":1,\"b\":{\"c\":2,\"d\":{\"e\":{\"f\":{\"g\":3,\"h\":[{\"z\":1},{\"y\":2,\"x\":[{},{}]}]}}},\"i\":4,\"j\":[],\"k\":{\"l\":5,\"m\":{}}}}";
0 commit comments