Skip to content

Commit

Permalink
Updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
DariuszDepta committed Nov 22, 2024
1 parent 931fb72 commit 5746d05
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ tasks:
cmds:
- cmd: cargo clean

cov:
desc: Generates code coverage
cmds:
- cmd: ./coverage.sh

clippy:
desc: Runs clippy for all targets
cmds:
Expand Down
8 changes: 8 additions & 0 deletions tests/loading/data/data01.kivi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
host
127.0.0.1

port
54321

timeout
12ms
1 change: 1 addition & 0 deletions tests/loading/mod.rs
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;
Expand Down
11 changes: 11 additions & 0 deletions tests/loading/test_load_from_file.rs
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());
}
41 changes: 41 additions & 0 deletions tests/test_api.rs
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(","));
}

0 comments on commit 5746d05

Please sign in to comment.