added tests for parsing root config
This commit is contained in:
21
tests/data/root_config_complex.toml
Normal file
21
tests/data/root_config_complex.toml
Normal file
@@ -0,0 +1,21 @@
|
||||
mod_location = "mods"
|
||||
download_location = "downloads"
|
||||
nexus_api_key = "1234"
|
||||
|
||||
[games.sse]
|
||||
path = "/home/user/games/sse"
|
||||
|
||||
[instances.example1]
|
||||
path = "example1.toml"
|
||||
|
||||
[instances.example2]
|
||||
path = "/home/user/example2.toml"
|
||||
|
||||
[mods.mod1]
|
||||
path = "/home/user/mods/mod1"
|
||||
|
||||
[mods."mod2"]
|
||||
path = "mod2"
|
||||
|
||||
[mods.mod3]
|
||||
path = "mods3"
|
||||
1
tests/data/root_config_minimal.toml
Normal file
1
tests/data/root_config_minimal.toml
Normal file
@@ -0,0 +1 @@
|
||||
mod_location = "mods"
|
||||
51
tests/root_config_test.rs
Normal file
51
tests/root_config_test.rs
Normal file
@@ -0,0 +1,51 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use fomod_manager::types::RootConfig;
|
||||
|
||||
fn get_parent() -> PathBuf {
|
||||
PathBuf::from(file!()).parent().unwrap().to_owned()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_minimal() {
|
||||
let config =
|
||||
RootConfig::load_from_file(get_parent().join("data/root_config_minimal.toml")).unwrap();
|
||||
|
||||
assert!(config.mod_location().ends_with("mods"));
|
||||
assert!(
|
||||
config.download_location().is_none(),
|
||||
"Download location should be None"
|
||||
);
|
||||
assert!(config.nexus_api_key().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_complex() {
|
||||
let config =
|
||||
RootConfig::load_from_file(get_parent().join("data/root_config_complex.toml")).unwrap();
|
||||
|
||||
assert!(config.mod_location().ends_with("mods"));
|
||||
assert!(
|
||||
config
|
||||
.download_location()
|
||||
.is_some_and(|e| e.ends_with("downloads"))
|
||||
);
|
||||
assert_eq!(config.nexus_api_key(), Some("1234"));
|
||||
|
||||
assert!(
|
||||
config
|
||||
.game_by_id("sse")
|
||||
.is_some_and(|e| e.install_location() == "/home/user/games/sse"),
|
||||
"Installed game wrong path"
|
||||
);
|
||||
|
||||
assert!(config.game_by_id("starfield").is_none());
|
||||
|
||||
assert!(config.mod_by_id("mod1").is_some());
|
||||
assert!(config.mod_by_id("mod100").is_none());
|
||||
assert!(
|
||||
config
|
||||
.mod_by_id("mod1")
|
||||
.is_some_and(|e| e.path().ends_with("mods/mod1"))
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user