Skip to content

Commit

Permalink
Remove duplicate test
Browse files Browse the repository at this point in the history
  • Loading branch information
QEDK committed Jul 19, 2020
1 parent c28679a commit 3dfccc6
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 38 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ fn main() -> Result<(), Box<dyn Error>> {
// Remember that all indexes are stored in lowercase!
// You can easily write the currently stored configuration to a file like:
config.write("output.ini");
config.write("output.ini")?;
// If you want to simply mutate the stored hashmap, you can use get_mut_map()
let map = config.get_mut_map();
Expand Down
37 changes: 0 additions & 37 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,41 +62,4 @@ fn main() -> Result<(), Box<dyn Error>> {
config2.clear();
assert_eq!(config.get_map_ref(), config2.get_map_ref());
Ok(())
}

#[test]#[allow(unused_variables)]
fn doc() -> Result<(), Box<dyn Error>> {
let mut config = Ini::new();

// You can easily load a file to get a clone of the map:
let map = config.load("tests/test.ini")?;
println!("{:?}", map);
// You can also safely not store the reference and access it later with get_map_ref() or get a clone with get_map()

// You can then access it like a normal hashmap:
let innermap = map["topsecret"].clone(); // Remember this is a hashmap!

// If you want to access the value, then you can simply do:
let val = map["topsecret"]["kfc"].clone().unwrap();
// Lowercasing when accessing map directly is important because all keys are stored in lower-case!
// Note: The .clone().unwrap() is required because it's an Option<String> type.

assert_eq!(val, "the secret herb is orega-"); // value accessible!

// What if you want to mutate the parser and remove KFC's secret recipe? Just use get_mut_map():
let mut_map = config.get_mut_map();
mut_map.get_mut("topsecret").unwrap().insert(String::from("kfc"), None);
// And the secret is back in safety, remember that these are normal HashMap functions chained for convenience.

// However very quickly see how that becomes cumbersome, so you can use the handy get() function from Ini
// The get() function accesses the map case-insensitively, so you can use uppercase as well:
let val = config.get("topsecret", "KFC"); // unwrapping will be an error because we just emptied it!
assert_eq!(val, None); // as expected!

// What if you want to get a number?
let my_number = config.getint("values", "Int")?.unwrap();
assert_eq!(my_number, -31415); // and we got it!
// The Ini struct provides more getters for primitive datatypes.

Ok(())
}

0 comments on commit 3dfccc6

Please sign in to comment.