]>
git.proxmox.com Git - cargo.git/blob - vendor/serde_json/tests/map.rs
1 use serde_json
::{from_str, Map, Value}
;
4 fn test_preserve_order() {
6 #[cfg(not(feature = "preserve_order"))]
7 const EXPECTED
: &[&str] = &["a", "b", "c"];
10 #[cfg(feature = "preserve_order")]
11 const EXPECTED
: &[&str] = &["b", "a", "c"];
13 let v
: Value
= from_str(r
#"{"b":null,"a":null,"c":null}"#).unwrap();
14 let keys
: Vec
<_
> = v
.as_object().unwrap().keys().collect();
15 assert_eq
!(keys
, EXPECTED
);
21 #[cfg(not(feature = "preserve_order"))]
22 const EXPECTED
: &[&str] = &["a", "b", "c"];
25 #[cfg(feature = "preserve_order")]
26 const EXPECTED
: &[&str] = &["b", "a", "c"];
28 let mut v
: Value
= from_str(r
#"{"b":null,"a":null,"c":null}"#).unwrap();
29 let val
= v
.as_object_mut().unwrap();
30 let mut m
= Map
::new();
32 let keys
: Vec
<_
> = m
.keys().collect();
34 assert_eq
!(keys
, EXPECTED
);
35 assert
!(val
.is_empty());
38 #[cfg(not(no_btreemap_retain))]
41 let mut v
: Value
= from_str(r
#"{"b":null,"a":null,"c":null}"#).unwrap();
42 let val
= v
.as_object_mut().unwrap();
43 val
.retain(|k
, _
| k
.as_str() != "b");
45 let keys
: Vec
<_
> = val
.keys().collect();
46 assert_eq
!(keys
, &["a", "c"]);