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 776ba67 commit e342d7b
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,46 @@
//! # KIVI format deserializer
//!
//! KIVI is a simple text format for storing keys with associated values on separate lines.
//! While it is not as widely known as formats like JSON or INI, it is straightforward
//! and particularly useful in specific contexts where keys or values consist
//! of multiple lines of text.
//!
//! An example of a configuration file in KIVI format:
//!
//! ```text
//! host
//! 127.0.0.1
//!
//! port
//! 54321
//!
//! timeout
//! 12ms
//! ```
//!
//! `host`, `port` and `timeout` are keys; `127.0.0.1`, `54321`, `12ms` are values.
//! It is quite similar to properties or INI file that store key-value pair in a single line.
//!
//! In KIVI format, the key and/or value may span over multiple lines:
//!
//! ```text
//! host
//! 127.0.0.1
//!
//! port
//! 54321
//!
//! timeout
//! 12ms
//!
//! "General
//! description"
//! "This configuration file
//! should be placed in the same
//! directory where the servers
//! binary is placed"
//! ```
//!
mod loader;
mod model;
Expand Down
15 changes: 15 additions & 0 deletions tests/loading/data/data02.kivi
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
host
127.0.0.1

port
54321

timeout
12ms

"General
description"
"This configuration file
should be placed in the same
directory where the servers
binary is placed."
14 changes: 14 additions & 0 deletions tests/loading/test_load_from_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,17 @@ fn loading_from_file_should_work() {
assert_eq!("54321", kvp.get("port").unwrap());
assert_eq!("12ms", kvp.get("timeout").unwrap());
}

#[test]
fn loading_multi_line_from_file_should_work() {
let kvp = load_from_file("./tests/loading/data/data02.kivi").unwrap();
assert!(!kvp.is_empty());
assert_eq!(4, 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());
assert_eq!(
"This configuration file\n should be placed in the same\n directory where the servers\n binary is placed.",
kvp.get("General\n description").unwrap()
);
}

0 comments on commit e342d7b

Please sign in to comment.