-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
931fb72
commit 5746d05
Showing
5 changed files
with
66 additions
and
0 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
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,8 @@ | ||
host | ||
127.0.0.1 | ||
|
||
port | ||
54321 | ||
|
||
timeout | ||
12ms |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod test_load_from_file; | ||
mod test_load_from_string; | ||
|
||
use kivi::load_from_string; | ||
|
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,11 @@ | ||
use kivi::load_from_file; | ||
|
||
#[test] | ||
fn loading_from_file_should_work() { | ||
let kvp = load_from_file("./tests/loading/data/data01.kivi").unwrap(); | ||
assert!(!kvp.is_empty()); | ||
assert_eq!(3, kvp.len()); | ||
assert_eq!("127.0.0.1", kvp.get("host").unwrap()); | ||
assert_eq!("54321", kvp.get("port").unwrap()); | ||
assert_eq!("12ms", kvp.get("timeout").unwrap()); | ||
} |
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,41 @@ | ||
use kivi::load_from_string; | ||
|
||
#[test] | ||
fn getting_empty_value_should_work() { | ||
let kvp = load_from_string(""); | ||
assert!(kvp.is_empty()); | ||
assert_eq!(0, kvp.len()); | ||
assert_eq!(None, kvp.get("a")); | ||
} | ||
|
||
#[test] | ||
fn getting_non_empty_value_should_work() { | ||
let kvp = load_from_string("a\nb\n"); | ||
assert!(!kvp.is_empty()); | ||
assert_eq!(1, kvp.len()); | ||
assert_eq!("b", kvp.get("a").unwrap()); | ||
} | ||
|
||
#[test] | ||
fn getting_keys_should_work() { | ||
let kvp = load_from_string("a\nb\nc\nd\n"); | ||
assert!(!kvp.is_empty()); | ||
assert_eq!(2, kvp.len()); | ||
assert_eq!("b", kvp.get("a").unwrap()); | ||
assert_eq!("d", kvp.get("c").unwrap()); | ||
let mut keys = kvp.keys().map(|s| s.to_owned()).collect::<Vec<String>>(); | ||
keys.sort(); | ||
assert_eq!("a,c", keys.join(",")); | ||
} | ||
|
||
#[test] | ||
fn getting_values_should_work() { | ||
let kvp = load_from_string("a\nb\nc\nd\n"); | ||
assert!(!kvp.is_empty()); | ||
assert_eq!(2, kvp.len()); | ||
assert_eq!("b", kvp.get("a").unwrap()); | ||
assert_eq!("d", kvp.get("c").unwrap()); | ||
let mut values = kvp.values().map(|s| s.to_owned()).collect::<Vec<String>>(); | ||
values.sort(); | ||
assert_eq!("b,d", values.join(",")); | ||
} |