[RELEASE] Version 0.0.7 #9

Merged
jank merged 9 commits from feature/version-0.0.7 into main 2024-08-21 14:04:27 +00:00
Showing only changes of commit 55fb3a196e - Show all commits

@ -22,5 +22,34 @@ impl Router {
None => respond_not_found(request),
}
}
pub fn add_route(&mut self, route: &str, route_function: fn(Request)) {
self.routes.insert(route.to_string(), route_function);
}
}
#[cfg(test)]
mod tests {
use std::collections::HashMap;
use tiny_http::Request;
use super::Router;
#[test]
fn test_add_route() {
let mut router = Router::new();
fn test_route(_request: Request) {
}
router.add_route("/test", test_route as fn(Request));
let mut expected = HashMap::new();
expected.insert("/test".to_string(), test_route as fn(Request));
assert_eq!(router.routes, expected);
}
}