Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonbrad committed Sep 15, 2023
1 parent 083efd4 commit 9c5ef48
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions clafrica/data/invalid_data.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# invalid
[data]
a = ["b", "c"]

File renamed without changes.
4 changes: 4 additions & 0 deletions clafrica/data/invalid_translator.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# invalid
[translators]
a = ["b", "c"]

14 changes: 11 additions & 3 deletions clafrica/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl Config {
insert_with_auto_capitalize!(data, auto_capitalize, key, value);
});
}
_ => Err(format!("Error in script file `{filepath:?}`.\nCaused by:\n\t{value:?} not allowed for the data table."))?,
_ => Err(format!("Invalid script file `{filepath:?}`.\nCaused by:\n\t{value:?} not allowed in the data table."))?,
};
Ok(())
},
Expand All @@ -114,7 +114,7 @@ impl Config {
let filepath = config_path.join(v.clone()).to_str().unwrap().to_string();
translators.insert(key.to_owned(), Data::Simple(filepath));
}
_ => Err(format!("Error in script file `{filepath:?}`.\nCaused by:\n\t{value:?} not allowed for translator."))?,
_ => Err(format!("Invalid script file `{filepath:?}`.\nCaused by:\n\t{value:?} not allowed in the translator table."))?,
};
Ok(())
},
Expand Down Expand Up @@ -248,7 +248,7 @@ mod tests {
assert_eq!(data.keys().len(), 23);

// parsing error
let conf = Config::from_file(Path::new("./data/invalid.toml"));
let conf = Config::from_file(Path::new("./data/invalid_file.toml"));
assert!(conf.is_err());

// config file not found
Expand All @@ -259,6 +259,14 @@ mod tests {
let conf = Config::from_file(Path::new("./data/blank_sample.toml")).unwrap();
let data = conf.extract_data();
assert_eq!(data.keys().len(), 0);

// invalid data
let conf = Config::from_file(Path::new("./data/invalid_data.toml"));
assert!(conf.is_err());

// invalid translator
let conf = Config::from_file(Path::new("./data/invalid_translator.toml"));
assert!(conf.is_err());
}

#[test]
Expand Down

0 comments on commit 9c5ef48

Please sign in to comment.