Skip to content

Commit

Permalink
location working
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoczim committed Dec 31, 2023
1 parent 50d2df8 commit 6bd6bbd
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/location/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,47 @@ impl<'a> fmt::Display for ViewRef<'a> {
}
}
}

#[cfg(test)]
mod test {
use crate::location::external::ViewRef;

#[test]
fn valid_with_host() {
let (external_loc, view) =
super::parse("https://duckduckgo.com/").unwrap();
assert_eq!(external_loc.raw_contents(), "https://duckduckgo.com/");
assert_eq!(
view,
ViewRef::WithHost { scheme: "https", rest: "duckduckgo.com/" }
);
}

#[test]
fn valid_as_other() {
let (external_loc, view) =
super::parse("other://urn:isbn:123").unwrap();
assert_eq!(external_loc.raw_contents(), "other://urn:isbn:123");
assert_eq!(view, ViewRef::Other("urn:isbn:123"));
}

#[test]
fn invalid_no_scheme() {
super::parse("abcd").unwrap_err();
}

#[test]
fn invalid_empty_scheme() {
super::parse("://abcd").unwrap_err();
}

#[test]
fn invalid_bad_scheme_start() {
super::parse(".b://abcd").unwrap_err();
}

#[test]
fn invalid_bad_scheme_char() {
super::parse("a!b://abcd").unwrap_err();
}
}
41 changes: 41 additions & 0 deletions src/location/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,44 @@ impl<'a> fmt::Display for ViewRef<'a> {
}
}
}

#[cfg(test)]
mod test {
use crate::location::{
external::External,
general::ViewRef,
internal::Internal,
};

#[test]
fn valid_internal() {
let (location, view) = super::parse("blog/page#id").unwrap();
assert_eq!(location.raw_contents(), "blog/page#id");
assert_eq!(
view,
ViewRef::Internal(Internal::new("blog/page#id").unwrap()),
);
}

#[test]
fn valid_external() {
let (location, view) = super::parse("https://duckduckgo.com/").unwrap();
assert_eq!(location.raw_contents(), "https://duckduckgo.com/");
assert_eq!(
view,
ViewRef::External(
External::new("https://duckduckgo.com/").unwrap()
),
);
}

#[test]
fn invalid_internal() {
super::parse("../page#id").unwrap_err();
}

#[test]
fn invalid_external() {
super::parse("://page").unwrap_err();
}
}

0 comments on commit 6bd6bbd

Please sign in to comment.