Skip to content

Commit 2f9396b

Browse files
committed
Add toml parse test
1 parent dfec74c commit 2f9396b

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/cmd/shelf.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,36 @@ pub fn execute(_args: &ArgMatches) -> Result<()> {
186186

187187
Ok(())
188188
}
189+
190+
#[test]
191+
fn test_parse_toml() {
192+
let toml = r#"
193+
root_url_prefix = "myprefix"
194+
195+
[[book]]
196+
git_url = "firsturl"
197+
git_ref = "shelf"
198+
path = "guide"
199+
200+
[[book]]
201+
git_url = "secondurl"
202+
203+
[[book]]
204+
path = "../test_book"
205+
"#;
206+
let cfg: Shelf = toml::from_str(&toml).unwrap();
207+
assert_eq!(cfg.root_url_prefix.unwrap(), "myprefix");
208+
209+
let book = &cfg.book[0];
210+
assert_eq!(book.git_url.clone().unwrap(), "firsturl");
211+
assert_eq!(book.git_ref.clone().unwrap(), "shelf");
212+
assert_eq!(book.path.clone().unwrap(), "guide");
213+
214+
let book = &cfg.book[1];
215+
assert_eq!(book.git_url.clone().unwrap(), "secondurl");
216+
assert!(book.git_ref.is_none());
217+
assert!(book.path.is_none());
218+
219+
let book = &cfg.book[2];
220+
assert_eq!(book.path.clone().unwrap(), "../test_book");
221+
}

0 commit comments

Comments
 (0)