-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
172: Use indexmap to preserve order (optional) r=torkleyy a=torkleyy Introduces an optional `indexmap` feature which uses `IndexMap` in `Value::Map` to preserve the order of deserialized elements. Fixes #129 Co-authored-by: Thomas Schaller <torkleyy@gmail.com>
- Loading branch information
Showing
6 changed files
with
223 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,7 @@ branches: | |
- staging | ||
- trying | ||
- master | ||
|
||
script: | ||
- cargo test | ||
- cargo test --all-features |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#[cfg(feature = "indexmap")] | ||
use ron::{de::from_str, Value}; | ||
|
||
#[test] | ||
#[cfg(feature = "indexmap")] | ||
fn test_order_preserved() { | ||
let file = r#"( | ||
tasks: { | ||
"debug message": Dbg( | ||
msg: "test message. some text after it." | ||
), | ||
"shell command": Shell( | ||
command: "ls", | ||
args: Some([ | ||
"-l", | ||
"-h", | ||
]), | ||
ch_dir: Some("/") | ||
), | ||
} | ||
) | ||
"#; | ||
|
||
let value: Value = from_str(file).unwrap(); | ||
match value { | ||
Value::Map(map) => match &map[&Value::String("tasks".to_owned())] { | ||
Value::Map(map) => { | ||
assert_eq!( | ||
*map.keys().next().unwrap(), | ||
Value::String("debug message".to_string()) | ||
); | ||
assert_eq!( | ||
*map.keys().skip(1).next().unwrap(), | ||
Value::String("shell command".to_string()) | ||
); | ||
} | ||
_ => panic!(), | ||
}, | ||
_ => panic!(), | ||
} | ||
|
||
let file = r#"( | ||
tasks: { | ||
"shell command": Shell( | ||
command: "ls", | ||
args: Some([ | ||
"-l", | ||
"-h", | ||
]), | ||
ch_dir: Some("/") | ||
), | ||
"debug message": Dbg( | ||
msg: "test message. some text after it." | ||
), | ||
} | ||
) | ||
"#; | ||
|
||
let value: Value = from_str(file).unwrap(); | ||
match value { | ||
Value::Map(map) => match &map[&Value::String("tasks".to_owned())] { | ||
Value::Map(map) => { | ||
assert_eq!( | ||
*map.keys().next().unwrap(), | ||
Value::String("shell command".to_string()) | ||
); | ||
assert_eq!( | ||
*map.keys().skip(1).next().unwrap(), | ||
Value::String("debug message".to_string()) | ||
); | ||
} | ||
_ => panic!(), | ||
}, | ||
_ => panic!(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters