Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion crates/terraphim_automata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl Display for AutomataPath {
impl AutomataPath {
/// Create a new AutomataPath from a URL
pub fn from_remote(url: &str) -> Result<Self> {
if !url.starts_with("http") || !url.starts_with("https") {
if !url.starts_with("http://") && !url.starts_with("https://") {
return Err(TerraphimAutomataError::Dict(format!(
"Invalid URL scheme. Only `http` and `https` are supported right now. Got {}",
url
Expand Down Expand Up @@ -625,4 +625,46 @@ mod tests {
let result = load_thesaurus_from_json(invalid_json);
assert!(result.is_err());
}

#[test]
fn test_from_remote_accepts_https() {
let result = AutomataPath::from_remote("https://example.com/thesaurus.json");
assert!(result.is_ok());
match result.unwrap() {
AutomataPath::Remote(url) => {
assert_eq!(url, "https://example.com/thesaurus.json");
}
AutomataPath::Local(_) => panic!("Expected Remote variant"),
}
}

#[test]
fn test_from_remote_accepts_http() {
let result = AutomataPath::from_remote("http://example.com/thesaurus.json");
assert!(result.is_ok());
match result.unwrap() {
AutomataPath::Remote(url) => {
assert_eq!(url, "http://example.com/thesaurus.json");
}
AutomataPath::Local(_) => panic!("Expected Remote variant"),
}
}

#[test]
fn test_from_remote_rejects_ftp() {
let result = AutomataPath::from_remote("ftp://example.com/thesaurus.json");
assert!(result.is_err());
}

#[test]
fn test_from_remote_rejects_file_path() {
let result = AutomataPath::from_remote("/tmp/thesaurus.json");
assert!(result.is_err());
}

#[test]
fn test_from_remote_rejects_empty() {
let result = AutomataPath::from_remote("");
assert!(result.is_err());
}
}
Loading