use crate::context::{Cx, try_request_context};
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub enum UrlForm {
#[default]
Relative,
Absolute,
}
#[inline]
#[must_use]
pub fn url_form(cx: &Cx) -> UrlForm {
try_request_context::<UrlForm>(cx)
.copied()
.unwrap_or_default()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn defaults_to_relative() {
assert_eq!(url_form(&Cx::default()), UrlForm::Relative);
}
#[test]
fn a_scope_registers_another_form() {
let cx = Cx::default().with(UrlForm::Absolute);
assert_eq!(url_form(&cx), UrlForm::Absolute);
}
#[test]
fn an_inner_scope_shadows_the_outer_form() {
let cx = Cx::default().with(UrlForm::Absolute);
let inner = cx.with(UrlForm::Relative);
assert_eq!(url_form(&inner), UrlForm::Relative);
assert_eq!(url_form(&cx), UrlForm::Absolute);
}
}