Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/serde_json/tests/map.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / vendor / serde_json / tests / map.rs` 57 lines ยท 1603 bytes Raw Blame History 1 use serde_json::{from_str, Map, Value}; 2 3 #[test] 4 fn test_preserve_order() { 5 // Sorted order 6 #[cfg(not(feature = "preserve_order"))] 7 const EXPECTED: &[&str] = &["a", "b", "c"]; 8 9 // Insertion order 10 #[cfg(feature = "preserve_order")] 11 const EXPECTED: &[&str] = &["b", "a", "c"]; 12 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); 16 } 17 18 #[test] 19 #[cfg(feature = "preserve_order")] 20 fn test_shift_insert() { 21 let mut v: Value = from_str(r#"{"b":null,"a":null,"c":null}"#).unwrap(); 22 let val = v.as_object_mut().unwrap(); 23 val.shift_insert(0, "d".to_owned(), Value::Null); 24 25 let keys: Vec<_> = val.keys().collect(); 26 assert_eq!(keys, &["d", "b", "a", "c"]); 27 } 28 29 #[test] 30 fn test_append() { 31 // Sorted order 32 #[cfg(not(feature = "preserve_order"))] 33 const EXPECTED: &[&str] = &["a", "b", "c"]; 34 35 // Insertion order 36 #[cfg(feature = "preserve_order")] 37 const EXPECTED: &[&str] = &["b", "a", "c"]; 38 39 let mut v: Value = from_str(r#"{"b":null,"a":null,"c":null}"#).unwrap(); 40 let val = v.as_object_mut().unwrap(); 41 let mut m = Map::new(); 42 m.append(val); 43 let keys: Vec<_> = m.keys().collect(); 44 45 assert_eq!(keys, EXPECTED); 46 assert!(val.is_empty()); 47 } 48 49 #[test] 50 fn test_retain() { 51 let mut v: Value = from_str(r#"{"b":null,"a":null,"c":null}"#).unwrap(); 52 let val = v.as_object_mut().unwrap(); 53 val.retain(|k, _| k.as_str() != "b"); 54 55 let keys: Vec<_> = val.keys().collect(); 56 assert_eq!(keys, &["a", "c"]); 57 }