diff options
author | Ryan Leckey <ryan@launchbadge.com> | 2017-06-16 11:15:40 -0700 |
---|---|---|
committer | Ryan Leckey <ryan@launchbadge.com> | 2017-06-16 11:15:40 -0700 |
commit | 05e9cd421e75173462072e57ab7e27881730d250 (patch) | |
tree | 8db6e8d6951c57a3d50093a8fd789c2941df849f /tests | |
parent | 1716c2fe7571b03215a5ae09c91f508d03335c2a (diff) |
Support subscript access on path get/set
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Settings.toml | 6 | ||||
-rw-r--r-- | tests/get.rs | 11 | ||||
-rw-r--r-- | tests/set.rs | 16 |
3 files changed, 33 insertions, 0 deletions
diff --git a/tests/Settings.toml b/tests/Settings.toml index b7fc7e9..2f2da74 100644 --- a/tests/Settings.toml +++ b/tests/Settings.toml @@ -8,6 +8,12 @@ boolean_s_parse = "fals" arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] +[[items]] +name = "1" + +[[items]] +name = "2" + [place] name = "Torre di Pisa" longitude = 43.7224985 diff --git a/tests/get.rs b/tests/get.rs index 2df50a5..1922fca 100644 --- a/tests/get.rs +++ b/tests/get.rs @@ -88,6 +88,17 @@ fn test_get_scalar_path() { } #[test] +fn test_get_scalar_path_subscript() { + let c = make(); + + assert_eq!(c.get("arr[2]").ok(), Some(3)); + assert_eq!(c.get("items[0].name").ok(), Some("1".to_string())); + assert_eq!(c.get("items[1].name").ok(), Some("2".to_string())); + assert_eq!(c.get("items[-1].name").ok(), Some("2".to_string())); + assert_eq!(c.get("items[-2].name").ok(), Some("1".to_string())); +} + +#[test] fn test_map() { let c = make(); let m: HashMap<String, Value> = c.get("place").unwrap(); diff --git a/tests/set.rs b/tests/set.rs index e02814b..14ddfae 100644 --- a/tests/set.rs +++ b/tests/set.rs @@ -40,6 +40,22 @@ fn test_set_scalar_path() { } #[test] +fn test_set_arr_path() { + let mut c = Config::default(); + + c.merge(File::new("tests/Settings", FileFormat::Toml)) + .unwrap(); + + c.set("items[0].name", "John").unwrap(); + + assert_eq!(c.get("items[0].name").ok(), Some("John".to_string())); + + c.set("items[2]", "George").unwrap(); + + assert_eq!(c.get("items[2]").ok(), Some("George".to_string())); +} + +#[test] fn test_set_capital() { let mut c = Config::default(); |