diff --git a/src/lib.rs b/src/lib.rs index 0e99c5d..b5118c0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/tests/loading/data/data02.kivi b/tests/loading/data/data02.kivi new file mode 100644 index 0000000..9e95735 --- /dev/null +++ b/tests/loading/data/data02.kivi @@ -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." diff --git a/tests/loading/test_load_from_file.rs b/tests/loading/test_load_from_file.rs index 7c40248..596ca04 100644 --- a/tests/loading/test_load_from_file.rs +++ b/tests/loading/test_load_from_file.rs @@ -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() + ); +}