Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate lifetime Parser and WootheeResult #6

Merged
merged 3 commits into from
Feb 3, 2018
Merged
Changes from 1 commit
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
Prev Previous commit
add unit test (for #5)
  • Loading branch information
Hideo Hattori committed Feb 2, 2018
commit aee5e173e86a65c825bc73dd555a45d29efb0db8
26 changes: 21 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -46,9 +46,25 @@ pub fn is_crawler(agent: &str) -> bool {
parser.try_crawler(agent, &mut result)
}

#[test]
fn test_is_crawler_smoke() {
assert!(!is_crawler("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)"));
assert!(is_crawler("Mozilla/5.0 (compatible; Yahoo! Slurp; \
http://help.yahoo.com/help/us/ysearch/slurp)"));
#[cfg(test)]
mod tests {
use super::{is_crawler, WootheeResult, Parser};

fn get_woothee_result(agent: &str) -> WootheeResult {
Parser::new().parse(agent).expect("fail parse()")
}

#[test]
fn test_parser_lifetime() {
let agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:21.0) Gecko/20100101 Firefox/21.0";
let result = get_woothee_result(agent);
assert_eq!(result.name.as_str(), "Firefox");
}

#[test]
fn test_is_crawler_smoke() {
assert!(!is_crawler("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)"));
assert!(is_crawler("Mozilla/5.0 (compatible; Yahoo! Slurp; \
http://help.yahoo.com/help/us/ysearch/slurp)"));
}
}