use super::super::{context::*, url::*, util::*};
use {kutil::io::reader::*, std::fmt};
#[derive(Clone, Debug)]
pub struct MockUrl {
pub url_representation: String,
pub slashable: bool,
pub base_url_representation: Option<String>,
pub query: Option<UrlQuery>,
pub fragment: Option<String>,
pub format: Option<String>,
pub content: Option<ReadableBuffer>,
pub(crate) context: UrlContextRef,
}
impl MockUrl {
pub fn new(
context: &UrlContextRef,
url_representation: String,
slashable: bool,
base_url_representation: Option<String>,
query: Option<UrlQuery>,
fragment: Option<String>,
format: Option<String>,
content: Option<&[u8]>,
) -> Self {
Self {
url_representation,
slashable,
base_url_representation,
query,
fragment,
format,
content: content.map(ReadableBuffer::new),
context: context.clone(),
}
}
pub fn new_with(&self, url_representation: String) -> MockUrl {
Self {
context: self.context.clone(),
url_representation,
slashable: self.slashable,
query: None,
fragment: None,
format: self.format.clone(),
content: self.content.clone(),
base_url_representation: None,
}
}
}
impl fmt::Display for MockUrl {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
let query = url_query_string(&self.query);
let fragment = url_fragment_string(&self.fragment);
write!(formatter, "{}{}{}", self.url_representation, query, fragment)
}
}
impl Into<UrlRef> for MockUrl {
fn into(self) -> UrlRef {
Box::new(self)
}
}