#[cfg(feature = "full")]
pub mod cli;
#[cfg(feature = "full")]
pub mod config;
#[cfg(feature = "base")]
pub mod dbuffer;
#[cfg(feature = "base")]
pub mod error;
#[cfg(feature = "base")]
pub mod http;
#[cfg(feature = "base")]
pub mod log;
#[cfg(feature = "resource")]
pub mod resource;
#[cfg(feature = "resource")]
pub mod route;
#[cfg(feature = "server")]
pub mod server;
#[cfg(feature = "ssl")]
pub mod ssl;
#[cfg(feature = "base")]
pub mod tp;
pub use tp::ThreadPool;
pub const RSWEB_VERSION: &str = "0.8.11";
pub const RSWEB_SERVER_STR: &str = "rsweb/0.8.11";
#[cfg(test)]
mod tests {
mod thread_pool {
use crate::tp::ThreadPool;
#[test]
fn thread_pool_create() {
let _ = ThreadPool::new(1);
}
#[test]
#[should_panic]
fn empty_thread_pool() {
let _ = ThreadPool::new(0);
}
}
mod dbuffer {
use crate::dbuffer::DBuffer;
#[test]
fn dbuffer_create() {
let _ = DBuffer::new();
}
#[test]
fn dbuffer_create_with_cap() {
let _ = DBuffer::with_capacity(6);
}
#[test]
fn dbuffer_read() {
let mut dbuffer = DBuffer::new();
let s = String::from("hello");
assert!(dbuffer.read_until_zero(&mut s.as_bytes()).is_ok());
}
#[test]
fn dbuffer_to_string() {
let mut dbuffer = DBuffer::new();
let s = String::from("hello");
assert!(dbuffer.read_until_zero(&mut s.as_bytes()).is_ok());
assert!(dbuffer.to_string().is_ok());
}
}
mod router {
use crate::route::Route;
use crate::route::Router;
#[test]
fn router_alias() {
let mut router = Router::new();
router.alias(String::from("/"), String::from("/index.html"));
assert_eq!(
router.lookup("/"),
Some(Route::Alias("/index.html".to_string()))
);
}
#[test]
fn router_route() {
let mut router = Router::new();
router.route(String::from("/"), String::from("/index.html"));
assert!(router.lookup("/").is_some());
}
}
mod http {
#[test]
fn request_from_string() {
let request_string = "GET / HTTP/1.1\r\nHost: examplehost.com\r\n\r\nbody";
assert!(crate::http::HTTPRequest::from_string(request_string.to_string()).is_ok());
let request =
crate::http::request::HTTPRequest::from_string(request_string.to_string()).unwrap();
assert_eq!(request.get_path(), "/".to_string());
assert_eq!(request.get_body(), &Some("body".to_string()));
}
}
}