| 1 | #[cfg(feature = "indexmap")] |
| 2 | use ron::{de::from_str, Value}; |
| 3 | |
| 4 | #[test] |
| 5 | #[cfg(feature = "indexmap")] |
| 6 | fn test_order_preserved() { |
| 7 | let file = r#"( |
| 8 | tasks: { |
| 9 | "debug message": Dbg( |
| 10 | msg: "test message. some text after it." |
| 11 | ), |
| 12 | "shell command": Shell( |
| 13 | command: "ls", |
| 14 | args: Some([ |
| 15 | "-l", |
| 16 | "-h", |
| 17 | ]), |
| 18 | ch_dir: Some("/"), |
| 19 | ), |
| 20 | }, |
| 21 | ) |
| 22 | "#; |
| 23 | |
| 24 | let value: Value = from_str(file).unwrap(); |
| 25 | match value { |
| 26 | Value::Map(map) => match &map[&Value::String("tasks".to_owned())] { |
| 27 | Value::Map(map) => { |
| 28 | assert_eq!( |
| 29 | *map.keys().next().unwrap(), |
| 30 | Value::String("debug message".to_string()) |
| 31 | ); |
| 32 | assert_eq!( |
| 33 | *map.keys().nth(1).unwrap(), |
| 34 | Value::String("shell command".to_string()) |
| 35 | ); |
| 36 | } |
| 37 | _ => panic!(), // GRCOV_EXCL_LINE |
| 38 | }, |
| 39 | _ => panic!(), // GRCOV_EXCL_LINE |
| 40 | } |
| 41 | |
| 42 | let file = r#"( |
| 43 | tasks: { |
| 44 | "shell command": Shell( |
| 45 | command: "ls", |
| 46 | args: Some([ |
| 47 | "-l", |
| 48 | "-h", |
| 49 | ]), |
| 50 | ch_dir: Some("/") |
| 51 | ), |
| 52 | "debug message": Dbg( |
| 53 | msg: "test message. some text after it." |
| 54 | ), |
| 55 | } |
| 56 | ) |
| 57 | "#; |
| 58 | |
| 59 | let value: Value = from_str(file).unwrap(); |
| 60 | match value { |
| 61 | Value::Map(map) => match &map[&Value::String("tasks".to_owned())] { |
| 62 | Value::Map(map) => { |
| 63 | assert_eq!( |
| 64 | *map.keys().next().unwrap(), |
| 65 | Value::String("shell command".to_string()) |
| 66 | ); |
| 67 | assert_eq!( |
| 68 | *map.keys().nth(1).unwrap(), |
| 69 | Value::String("debug message".to_string()) |
| 70 | ); |
| 71 | } |
| 72 | _ => panic!(), // GRCOV_EXCL_LINE |
| 73 | }, |
| 74 | _ => panic!(), // GRCOV_EXCL_LINE |
| 75 | } |
| 76 | } |