Autocomplete tests
This commit is contained in:
parent
22d16ff5ba
commit
b41bf6dcf4
|
@ -200,6 +200,10 @@ Is there a permissions issue? Here's the underlaying error:
|
|||
letters, numbers, dots, dashes and underscores are allowed.")]
|
||||
InvalidCustomFormatter(String),
|
||||
|
||||
#[error("The specified name for a autocompleted formatter \"{0}\" is not valid. Only ascii
|
||||
letters, numbers, dots, dashes and underscores are allowed.")]
|
||||
InvalidAutocompleteFormatter(String),
|
||||
|
||||
#[error("You have specified a custom formatter \"{0}\" but your config file doesn't say
|
||||
where to look for it.
|
||||
|
||||
|
|
|
@ -74,3 +74,47 @@ impl FromStr for Formatter {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use super::*;
|
||||
|
||||
fn autocomplete(s: &str) -> error::Result<Formatter> {
|
||||
let formatters = vec!["text", "csv", "json", "ids", "ical", "chart"];
|
||||
if s.len() > 1 {
|
||||
for formatter in formatters {
|
||||
if formatter.contains(s) {
|
||||
return Formatter::from_str(formatter)
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(error::Error::InvalidAutocompleteFormatter(s.to_string()))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid_autocomplete_starts_with() {
|
||||
let format = autocomplete("tex");
|
||||
assert!(format.is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid_autocomplete_contains() {
|
||||
let format = autocomplete("sv");
|
||||
assert!(format.is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_autocomplete_to_short() {
|
||||
let format = autocomplete("s");
|
||||
assert!(format.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_autocomplete_does_not_contains() {
|
||||
let format = autocomplete("fail");
|
||||
assert!(format.is_err());
|
||||
}
|
||||
|
||||
// TODO: autocomplete for custom formatter
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue