-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Colton J. McCurdy <[email protected]>
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,3 +70,50 @@ impl Repo { | |
self.clone() | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
extern crate log; | ||
use env_logger; | ||
|
||
fn setup() -> Repo { | ||
// https://github.com/rust-cli/env_logger/blob/19e92ece73472ca3a0269c61c4f44399c6ea2366/examples/in_tests.rs#L21 | ||
let _ = env_logger::builder() | ||
// Include all events in tests | ||
.filter_level(log::LevelFilter::max()) | ||
// Ensure events are captured by `cargo test` | ||
.is_test(true) | ||
// Ignore errors initializing the logger if tests race to configure it | ||
.try_init(); | ||
|
||
Repo::new() | ||
} | ||
|
||
#[test] | ||
fn test_url_invalid_name() { | ||
let mut r = setup(); | ||
|
||
// contains ":" | ||
let got = r.url("a:a/a/a".to_string()); | ||
assert_eq!(got.is_err(), true); | ||
|
||
// contains "@" | ||
let got = r.url("a@a/a/a".to_string()); | ||
assert_eq!(got.is_err(), true); | ||
|
||
// <3 | ||
let got = r.url("a/a".to_string()); | ||
assert_eq!(got.is_err(), true); | ||
} | ||
|
||
#[test] | ||
fn test_url_valid_name() { | ||
let mut r = setup(); | ||
|
||
let got = r | ||
.url("github.com/a/a".to_string()) | ||
.expect("failed to set url"); | ||
assert_eq!(got.get_url(), "[email protected]:a/a.git"); | ||
} | ||
} |