[#13] added some more unit tests, hated life for a bit

This commit is contained in:
Jef Roosens 2021-04-08 22:53:29 +02:00
parent 2e73d88ae9
commit e4b8be3ba3
Signed by: Jef Roosens
GPG key ID: B580B976584B5F30
4 changed files with 32 additions and 2 deletions

View file

@ -60,6 +60,7 @@ impl Serialize for BasicDate {
mod tests {
use super::*;
/// Tests catching a string with an invalid date
#[test]
fn test_invalid_date() {
let val = "2012-13-12";

View file

@ -28,3 +28,5 @@ impl Serialize for PickupTime {
s.end()
}
}
// I'd put tests here, but there's barely anything to do

View file

@ -6,8 +6,19 @@ use std::convert::TryFrom;
/// Represents a street
pub struct Street {
pub name: String,
pub city: String,
name: String,
city: String,
}
impl Street {
// This constructor just makes my life a bit easier during testing
#[cfg(test)]
fn new(name: String, city: String) -> Street {
Street {
name: name,
city: city,
}
}
}
impl From<&Street> for String {
@ -50,6 +61,7 @@ impl<'v> FromFormValue<'v> for Street {
// This regex is pretty loose tbh, but not sure how I can make it more
// strict right now
let re = Regex::new(r"^(.+) \((.+)\)$").unwrap();
match re.captures(&form_value.url_decode_lossy()) {
None => Err(form_value),
Some(caps) => Ok(Street {
@ -59,3 +71,15 @@ impl<'v> FromFormValue<'v> for Street {
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_to_string() {
let street = Street::new(String::from("testname"), String::from("city"));
assert_eq!(String::from("testname (city)"), String::from(&street));
}
}