✨ Detecta errores de programación en desarrollo
Añade comprobaciones sin coste en producción:
- Falla con `debug_assert!` si `param_or*`/`extra_or*` piden otro tipo,
si `form:📅:Field` recibe un valor de otro tipo, si `grid::Tracks`
supera MAX_TRACKS o si `TestRequest::header()` recibe una cabecera
no válida.
- Avisa en desarrollo de las traducciones ausentes y, al arrancar, de
las claves de permiso repetidas.
- Corrige en Bootsier el título por defecto de los desplegables y los
botones de confirmación, que salían siempre en inglés. Evita también
el aviso de import sin usar en release de `core/extension/all.rs`.
This commit is contained in:
parent
c7888c85ac
commit
f9ab1f55a3
18 changed files with 203 additions and 49 deletions
|
|
@ -232,8 +232,12 @@ impl Theme for Bootsier {
|
|||
// Etiquetas de los botones del modal de confirmación que sustituye al `confirm()` nativo
|
||||
// de htmx (ver `bootsier.confirm.js`); se leen aquí porque este es el único punto con
|
||||
// acceso al `Context` para resolverlas antes de escribirlas en el `<body>`.
|
||||
let confirm_ok = Lc::l("confirm_ok").lookup(page).unwrap_or_default();
|
||||
let confirm_cancel = Lc::l("confirm_cancel").lookup(page).unwrap_or_default();
|
||||
let confirm_ok = Lc::t("confirm_ok", &LOCALES_BOOTSIER)
|
||||
.lookup(page)
|
||||
.unwrap_or_default();
|
||||
let confirm_cancel = Lc::t("confirm_cancel", &LOCALES_BOOTSIER)
|
||||
.lookup(page)
|
||||
.unwrap_or_default();
|
||||
|
||||
// Las URLs de las fuentes deben coincidir exactamente con las declaradas en @font-face de
|
||||
// _bootsier-custom.scss; cualquier discrepancia hace que el navegador descargue dos veces.
|
||||
|
|
|
|||
|
|
@ -9,8 +9,6 @@
|
|||
|
||||
use pagetop::prelude::*;
|
||||
|
||||
use crate::LOCALES_BOOTSIER;
|
||||
|
||||
mod props;
|
||||
pub use props::Kind;
|
||||
|
||||
|
|
@ -165,9 +163,9 @@ pub(crate) async fn item_render(item: &Item, cx: &mut Context) -> Result<Markup,
|
|||
return Ok(html! {});
|
||||
}
|
||||
let title = dd.title().lookup(cx).unwrap_or_else(|| {
|
||||
Lc::t("dropdown", &LOCALES_BOOTSIER)
|
||||
Lc::l("dropdown_default_title")
|
||||
.lookup(cx)
|
||||
.unwrap_or_else(|| "Dropdown".to_string())
|
||||
.unwrap_or_default()
|
||||
});
|
||||
let menu_classes = if *dd.menu_end() {
|
||||
"dropdown-menu dropdown-menu-end"
|
||||
|
|
|
|||
34
extensions/pagetop-bootsier/tests/translations.rs
Normal file
34
extensions/pagetop-bootsier/tests/translations.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
// Verifies that the texts added by the theme on its own come translated from their own catalog.
|
||||
|
||||
use pagetop::prelude::*;
|
||||
use pagetop_bootsier::Bootsier;
|
||||
use pagetop_bootsier::theme::*;
|
||||
|
||||
fn request() -> HttpRequest {
|
||||
web::test::TestRequest::get().to_http_request()
|
||||
}
|
||||
|
||||
#[pagetop::test]
|
||||
async fn a_dropdown_without_title_gets_the_translated_default() {
|
||||
let mut nav = Nav::new().with_item(bs::nav::Item::dropdown(
|
||||
Dropdown::new().with_item(dropdown::Item::link(Lc::n("x"), "/x")),
|
||||
));
|
||||
let mut cx = Context::new(request())
|
||||
.with_theme(&Bootsier)
|
||||
.with_langid(&Locale::resolve("es-ES"));
|
||||
let html = nav.render(&mut cx).await.into_string();
|
||||
assert!(html.contains("Menú desplegable"), "{html}");
|
||||
}
|
||||
|
||||
#[pagetop::test]
|
||||
async fn the_confirmation_buttons_are_translated() {
|
||||
let html = Page::new(request())
|
||||
.with_theme(&Bootsier)
|
||||
.with_langid(&Locale::resolve("es-ES"))
|
||||
.render()
|
||||
.await
|
||||
.unwrap()
|
||||
.into_string();
|
||||
assert!(html.contains(r#"data-confirm-ok="Aceptar""#), "{html}");
|
||||
assert!(html.contains(r#"data-confirm-cancel="Cancelar""#), "{html}");
|
||||
}
|
||||
|
|
@ -429,9 +429,13 @@ impl PermissionRegistry {
|
|||
PERMISSIONS.get().unwrap_or(&EMPTY_PERMISSIONS)
|
||||
}
|
||||
|
||||
/// Registra un permiso. Se ignora si ya hay uno con la misma clave.
|
||||
/// Registra un permiso. Si ya hay uno con la misma clave se ignora, con un aviso en las trazas.
|
||||
pub fn register(&mut self, perm: PermissionRef) {
|
||||
if self.has(perm) {
|
||||
trace::warn!(
|
||||
"Permission \"{}\" declared more than once, keeping the first one",
|
||||
perm.key()
|
||||
);
|
||||
return;
|
||||
}
|
||||
let group = perm.group();
|
||||
|
|
|
|||
|
|
@ -245,24 +245,39 @@ impl Field {
|
|||
}
|
||||
|
||||
/// Establece la fecha inicial de un campo de [`Field::date()`] (`None` para dejarlo vacío). En
|
||||
/// un campo de otro tipo se ignora.
|
||||
/// un campo de otro tipo falla en desarrollo y en pruebas, y en producción se ignora.
|
||||
pub fn with_date(mut self, date: impl Into<Option<NaiveDate>>) -> Self {
|
||||
self.value = date.into().map_or(Value::None, Value::Date);
|
||||
let date = date.into();
|
||||
debug_assert!(
|
||||
date.is_none() || matches!(self.kind, Kind::Date),
|
||||
"with_date() needs a field created with Field::date()"
|
||||
);
|
||||
self.value = date.map_or(Value::None, Value::Date);
|
||||
self
|
||||
}
|
||||
|
||||
/// Establece la hora inicial de un campo de [`Field::time()`] (`None` para dejarlo vacío). En
|
||||
/// un campo de otro tipo se ignora.
|
||||
/// un campo de otro tipo falla en desarrollo y en pruebas, y en producción se ignora.
|
||||
pub fn with_time(mut self, time: impl Into<Option<NaiveTime>>) -> Self {
|
||||
self.value = time.into().map_or(Value::None, Value::Time);
|
||||
let time = time.into();
|
||||
debug_assert!(
|
||||
time.is_none() || matches!(self.kind, Kind::Time),
|
||||
"with_time() needs a field created with Field::time()"
|
||||
);
|
||||
self.value = time.map_or(Value::None, Value::Time);
|
||||
self
|
||||
}
|
||||
|
||||
/// Establece el instante inicial de un campo de [`Field::datetime()`] (`None` para dejarlo
|
||||
/// vacío). Se muestra en la zona horaria efectiva del documento. En un campo de otro tipo se
|
||||
/// ignora.
|
||||
/// vacío). Se muestra en la zona horaria efectiva del documento. En un campo de otro tipo falla
|
||||
/// en desarrollo y en pruebas, y en producción se ignora.
|
||||
pub fn with_datetime(mut self, dt: impl Into<Option<DateTime<Utc>>>) -> Self {
|
||||
self.value = dt.into().map_or(Value::None, Value::DateTime);
|
||||
let dt = dt.into();
|
||||
debug_assert!(
|
||||
dt.is_none() || matches!(self.kind, Kind::DateTime),
|
||||
"with_datetime() needs a field created with Field::datetime()"
|
||||
);
|
||||
self.value = dt.map_or(Value::None, Value::DateTime);
|
||||
self
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -352,19 +352,28 @@ pub trait Contextual {
|
|||
})
|
||||
}
|
||||
|
||||
/// Devuelve el parámetro clonado o el **valor por defecto del tipo** (`T::default()`).
|
||||
/// Devuelve el parámetro clonado o el **valor por defecto del tipo** (`T::default()`) si no
|
||||
/// existe.
|
||||
///
|
||||
/// En desarrollo y en pruebas falla si existe con otro tipo; en producción devuelve también el
|
||||
/// valor por defecto.
|
||||
fn param_or_default<T: Clone + Default + 'static>(&self, key: &'static str) -> T {
|
||||
self.param::<T>(key).ok().cloned().unwrap_or_default()
|
||||
checked_param(self.param::<T>(key)).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Devuelve el parámetro clonado o un **valor por defecto** si no existe.
|
||||
///
|
||||
/// En desarrollo y en pruebas falla si existe con otro tipo; en producción devuelve también el
|
||||
/// valor por defecto.
|
||||
fn param_or<T: Clone + 'static>(&self, key: &'static str, default: T) -> T {
|
||||
self.param::<T>(key).ok().cloned().unwrap_or(default)
|
||||
checked_param(self.param::<T>(key)).unwrap_or(default)
|
||||
}
|
||||
|
||||
/// Devuelve el parámetro clonado o el **valor evaluado** por la función `f` si no existe.
|
||||
///
|
||||
/// En desarrollo y en pruebas falla si existe con otro tipo; en producción evalúa también `f`.
|
||||
fn param_or_else<T: Clone + 'static, F: FnOnce() -> T>(&self, key: &'static str, f: F) -> T {
|
||||
self.param::<T>(key).ok().cloned().unwrap_or_else(f)
|
||||
checked_param(self.param::<T>(key)).unwrap_or_else(f)
|
||||
}
|
||||
|
||||
/// Devuelve el Favicon de los recursos del contexto.
|
||||
|
|
@ -795,3 +804,16 @@ impl<T: Contextual> LangId for T {
|
|||
self.context().locale.langid()
|
||||
}
|
||||
}
|
||||
|
||||
// Un parámetro ausente es normal; pedirlo con un tipo distinto al guardado es error de desarrollo.
|
||||
fn checked_param<T: Clone>(param: Result<&T, ContextError>) -> Option<T> {
|
||||
param
|
||||
.inspect_err(|err| {
|
||||
debug_assert!(
|
||||
!matches!(err, ContextError::ParamTypeMismatch { .. }),
|
||||
"{err}"
|
||||
);
|
||||
})
|
||||
.ok()
|
||||
.cloned()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -225,7 +225,7 @@ impl From<RoutePath> for Route {
|
|||
|
||||
/// Enlaza con una ruta declarada con [`Endpoint`], conservando su acceso.
|
||||
///
|
||||
/// Una ruta con parámetro se enlaza con [`Endpoint::to()`]; en desarrollo y en las pruebas, esta
|
||||
/// Una ruta con parámetro se enlaza con [`Endpoint::to()`]; en desarrollo y en pruebas, esta
|
||||
/// conversión falla si se olvida.
|
||||
impl<E: Endpoint> From<E> for Route {
|
||||
fn from(endpoint: E) -> Self {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use crate::core::extension::ExtensionRef;
|
|||
use crate::core::theme::ThemeRef;
|
||||
use crate::core::theme::all::register_theme;
|
||||
use crate::web::{Layers, Router, Routes, StaticFiles};
|
||||
use crate::{BoxError, config, global, serve_static_files, trace, web};
|
||||
use crate::{BoxError, config, global, serve_static_files, trace};
|
||||
|
||||
use std::sync::OnceLock;
|
||||
|
||||
|
|
@ -249,7 +249,7 @@ pub fn configure_routes(router: Router) -> Result<Router, StartupError> {
|
|||
#[cfg(debug_assertions)]
|
||||
let router = router.route(
|
||||
"/.well-known/appspecific/com.chrome.devtools.json",
|
||||
web::get(|| async { web::http::StatusCode::NOT_FOUND }),
|
||||
crate::web::get(|| async { crate::web::http::StatusCode::NOT_FOUND }),
|
||||
);
|
||||
|
||||
EXTENSIONS
|
||||
|
|
|
|||
|
|
@ -215,16 +215,20 @@ impl Tracks {
|
|||
Self::default()
|
||||
}
|
||||
|
||||
/// Añade una pista al final de la lista. Si ya hay [`MAX_TRACKS`] pistas, la llamada se ignora.
|
||||
/// Añade una pista al final de la lista. Si ya hay [`MAX_TRACKS`] pistas, falla en desarrollo y
|
||||
/// en pruebas, y en producción la llamada se ignora.
|
||||
pub fn with_track(mut self, track: AxisTrack) -> Self {
|
||||
if let Some(slot) = self.tracks.iter_mut().find(|t| t.is_none()) {
|
||||
let slot = self.tracks.iter_mut().find(|t| t.is_none());
|
||||
debug_assert!(slot.is_some(), "a grid admits up to {MAX_TRACKS} tracks");
|
||||
if let Some(slot) = slot {
|
||||
*slot = Some(track);
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
/// Repite la misma pista `count` veces (equivalente a `repeat(count, track)` en CSS, para el
|
||||
/// caso de uso más común con pistas idénticas). Trunca a [`MAX_TRACKS`] si `count` lo supera.
|
||||
/// caso de uso más común con pistas idénticas). Si `count` supera [`MAX_TRACKS`], falla en
|
||||
/// desarrollo y en pruebas, y en producción se trunca.
|
||||
///
|
||||
/// ```rust
|
||||
/// # use pagetop::prelude::*;
|
||||
|
|
@ -232,6 +236,10 @@ impl Tracks {
|
|||
/// assert_eq!(tracks.to_string(), "1fr 1fr 1fr");
|
||||
/// ```
|
||||
pub fn repeat(count: usize, track: AxisTrack) -> Self {
|
||||
debug_assert!(
|
||||
count <= MAX_TRACKS,
|
||||
"a grid admits up to {MAX_TRACKS} tracks, got {count}"
|
||||
);
|
||||
let mut tracks = Self::new();
|
||||
for _ in 0..count.min(MAX_TRACKS) {
|
||||
tracks = tracks.with_track(track);
|
||||
|
|
|
|||
|
|
@ -162,9 +162,6 @@ use std::sync::Arc;
|
|||
///
|
||||
/// assert!(props.extra_or(EXT_ENABLED, false));
|
||||
/// assert_eq!(props.extra_or(EXT_LABEL, String::new()), "flotante");
|
||||
///
|
||||
/// // Tipo incorrecto devuelve el valor por defecto indicado:
|
||||
/// assert_eq!(props.extra_or(EXT_ENABLED, 0_u8), 0);
|
||||
/// ```
|
||||
///
|
||||
/// Los valores extra no se emiten en el HTML al renderizar; son exclusivamente para uso interno de
|
||||
|
|
@ -556,7 +553,10 @@ impl Props {
|
|||
})
|
||||
}
|
||||
|
||||
/// Devuelve el valor extra clonado o el **valor `default`** si no existe o el tipo no coincide.
|
||||
/// Devuelve el valor extra clonado o el **valor `default`** si no existe.
|
||||
///
|
||||
/// En desarrollo y en pruebas falla si existe con otro tipo; en producción devuelve también
|
||||
/// `default`.
|
||||
///
|
||||
/// ```rust
|
||||
/// # use pagetop::prelude::*;
|
||||
|
|
@ -569,11 +569,13 @@ impl Props {
|
|||
/// assert!(!props.extra_or(EXT_OTHER, false));
|
||||
/// ```
|
||||
pub fn extra_or<T: Clone + 'static>(&self, key: &'static str, default: T) -> T {
|
||||
self.extra::<T>(key).ok().cloned().unwrap_or(default)
|
||||
self.extra_cloned(key).unwrap_or(default)
|
||||
}
|
||||
|
||||
/// Devuelve el valor extra clonado o el **valor por defecto del tipo** si no existe o el tipo
|
||||
/// no coincide.
|
||||
/// Devuelve el valor extra clonado o el **valor por defecto del tipo** si no existe.
|
||||
///
|
||||
/// En desarrollo y en pruebas falla si existe con otro tipo; en producción devuelve también el
|
||||
/// valor por defecto.
|
||||
///
|
||||
/// ```rust
|
||||
/// # use pagetop::prelude::*;
|
||||
|
|
@ -586,11 +588,12 @@ impl Props {
|
|||
/// assert_eq!(props.extra_or_default::<i32>(EXT_COUNT), 0);
|
||||
/// ```
|
||||
pub fn extra_or_default<T: Clone + Default + 'static>(&self, key: &'static str) -> T {
|
||||
self.extra::<T>(key).ok().cloned().unwrap_or_default()
|
||||
self.extra_cloned(key).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Devuelve el valor extra clonado o el **valor evaluado por la función `f`** si no existe o el
|
||||
/// tipo no coincide.
|
||||
/// Devuelve el valor extra clonado o el **valor evaluado por la función `f`** si no existe.
|
||||
///
|
||||
/// En desarrollo y en pruebas falla si existe con otro tipo; en producción evalúa también `f`.
|
||||
///
|
||||
/// ```rust
|
||||
/// # use pagetop::prelude::*;
|
||||
|
|
@ -606,7 +609,21 @@ impl Props {
|
|||
key: &'static str,
|
||||
f: F,
|
||||
) -> T {
|
||||
self.extra::<T>(key).ok().cloned().unwrap_or_else(f)
|
||||
self.extra_cloned(key).unwrap_or_else(f)
|
||||
}
|
||||
|
||||
// Un valor ausente es normal; pedirlo con un tipo distinto del guardado es un error de
|
||||
// programación.
|
||||
fn extra_cloned<T: Clone + 'static>(&self, key: &'static str) -> Option<T> {
|
||||
self.extra::<T>(key)
|
||||
.inspect_err(|err| {
|
||||
debug_assert!(
|
||||
!matches!(err, PropsError::ExtraTypeMismatch { .. }),
|
||||
"{err}"
|
||||
);
|
||||
})
|
||||
.ok()
|
||||
.cloned()
|
||||
}
|
||||
|
||||
// **< Props RENDER >***************************************************************************
|
||||
|
|
|
|||
|
|
@ -355,13 +355,21 @@ impl Lc {
|
|||
// memoria, aunque `langid` sea casi siempre un idioma disponible. Se prueba antes
|
||||
// el idioma exacto, que es lo primero que elige la negociación, por lo que el
|
||||
// resultado no cambia; sólo si falla se recorre la cadena de idiomas de respaldo.
|
||||
self.locales
|
||||
let text = self
|
||||
.locales
|
||||
.lookup_single_language(langid, key.as_ref(), args.as_ref())
|
||||
.ok()
|
||||
.or_else(|| {
|
||||
self.locales
|
||||
.try_lookup_complete(langid, key.as_ref(), args.as_ref())
|
||||
})
|
||||
});
|
||||
// Sin `panic!`: `lookup()` devuelve `None` por contrato. Sólo en desarrollo, porque
|
||||
// una clave ausente se repetiría en cada renderizado.
|
||||
#[cfg(debug_assertions)]
|
||||
if text.is_none() {
|
||||
crate::trace::warn!("No translation for key \"{key}\" in \"{langid}\"");
|
||||
}
|
||||
text
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
16
src/web.rs
16
src/web.rs
|
|
@ -586,14 +586,16 @@ pub mod test {
|
|||
|
||||
/// Añade una cabecera a la petición.
|
||||
///
|
||||
/// Si `name` o `value` no son válidos como cabecera HTTP, se descarta en silencio en lugar
|
||||
/// de entrar en pánico.
|
||||
/// Falla si `name` o `value` no son válidos como cabecera HTTP, para que una prueba no pase
|
||||
/// sin la cabecera que cree enviar (compilando con *debug assertions*; sin ellas, se
|
||||
/// descarta).
|
||||
pub fn header(mut self, name: impl AsRef<str>, value: impl AsRef<str>) -> Self {
|
||||
if let (Ok(n), Ok(v)) = (
|
||||
http::HeaderName::from_bytes(name.as_ref().as_bytes()),
|
||||
http::HeaderValue::from_str(value.as_ref()),
|
||||
) {
|
||||
self.headers.insert(n, v);
|
||||
let (name, value) = (name.as_ref(), value.as_ref());
|
||||
let parsed = http::HeaderName::from_bytes(name.as_bytes()).ok();
|
||||
let parsed = parsed.zip(http::HeaderValue::from_str(value).ok());
|
||||
debug_assert!(parsed.is_some(), "invalid header `{name}: {value}`");
|
||||
if let Some((name, value)) = parsed {
|
||||
self.headers.insert(name, value);
|
||||
}
|
||||
self
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ pub trait Endpoint {
|
|||
/// resuelve `.` y `..` como otra ruta: los identificadores numéricos o validados no tienen ese
|
||||
/// problema.
|
||||
///
|
||||
/// En desarrollo y en las pruebas falla si la ruta no tiene exactamente un parámetro.
|
||||
/// En desarrollo y en pruebas falla si la ruta no tiene exactamente un parámetro.
|
||||
fn to(&self, param: impl fmt::Display) -> Route {
|
||||
let pattern = self.path();
|
||||
let parts = pattern
|
||||
|
|
|
|||
|
|
@ -70,9 +70,17 @@ async fn text_is_shown_as_written_and_empty_fields_have_no_value() {
|
|||
}
|
||||
|
||||
#[pagetop::test]
|
||||
async fn a_value_of_another_kind_is_ignored() {
|
||||
#[should_panic(expected = "needs a field created with")]
|
||||
async fn a_value_of_another_kind_is_an_error() {
|
||||
let date = NaiveDate::from_ymd_opt(2026, 10, 6).unwrap();
|
||||
let mut field = form::date::Field::time().with_name("at").with_date(date);
|
||||
let _ = form::date::Field::time().with_date(date);
|
||||
}
|
||||
|
||||
#[pagetop::test]
|
||||
async fn no_value_is_valid_for_any_kind() {
|
||||
let mut field = form::date::Field::time()
|
||||
.with_name("at")
|
||||
.with_date(None::<NaiveDate>);
|
||||
let html = field.render(&mut cx("es-ES", "UTC")).await.into_string();
|
||||
assert!(!html.contains("value="));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -221,3 +221,16 @@ async fn grid_breakpoints_add_their_suffix_and_wrap_rules_in_media_queries() {
|
|||
assert!(assets.contains("@media(min-width:768px){._grid_md_{display:grid}}"));
|
||||
assert!(assets.contains("@media(min-width:992px){._grid-columns_1fr-1fr-1fr_lg_"));
|
||||
}
|
||||
|
||||
#[pagetop::test]
|
||||
#[should_panic(expected = "up to 12 tracks")]
|
||||
async fn repeating_more_tracks_than_allowed_is_an_error() {
|
||||
let _ = grid::Tracks::repeat(grid::MAX_TRACKS + 1, grid::AxisTrack::Fraction(1.0));
|
||||
}
|
||||
|
||||
#[pagetop::test]
|
||||
#[should_panic(expected = "up to 12 tracks")]
|
||||
async fn adding_more_tracks_than_allowed_is_an_error() {
|
||||
let track = grid::AxisTrack::Fraction(1.0);
|
||||
let _ = grid::Tracks::repeat(grid::MAX_TRACKS, track).with_track(track);
|
||||
}
|
||||
|
|
|
|||
14
tests/context_params.rs
Normal file
14
tests/context_params.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
use pagetop::prelude::*;
|
||||
|
||||
#[pagetop::test]
|
||||
#[should_panic(expected = "type mismatch")]
|
||||
async fn a_param_of_another_type_is_an_error() {
|
||||
let cx = Context::default().with_param("count", 7_i32);
|
||||
let _ = cx.param_or("count", 0_u32);
|
||||
}
|
||||
|
||||
#[pagetop::test]
|
||||
async fn a_missing_param_gets_the_default() {
|
||||
let cx = Context::default();
|
||||
assert_eq!(cx.param_or("count", 3_u32), 3);
|
||||
}
|
||||
|
|
@ -62,9 +62,10 @@ async fn extra_or_returns_default_on_missing() {
|
|||
}
|
||||
|
||||
#[pagetop::test]
|
||||
async fn extra_or_returns_default_on_type_mismatch() {
|
||||
#[should_panic(expected = "type mismatch")]
|
||||
async fn extra_or_fails_on_type_mismatch() {
|
||||
let props = Props::default().with_prop(PropsOp::set_extra("ext.flag", true));
|
||||
assert_eq!(props.extra_or("ext.flag", 0_u32), 0_u32);
|
||||
let _ = props.extra_or("ext.flag", 0_u32);
|
||||
}
|
||||
|
||||
// **< Props::extra_or_default >********************************************************************
|
||||
|
|
|
|||
|
|
@ -77,3 +77,9 @@ async fn http_request_exposes_the_method() {
|
|||
assert_eq!(request.method(), web::http::Method::POST);
|
||||
assert!(!request.method().is_safe());
|
||||
}
|
||||
|
||||
#[pagetop::test]
|
||||
#[should_panic(expected = "invalid header")]
|
||||
async fn an_invalid_header_is_an_error() {
|
||||
let _ = web::test::TestRequest::get().header("bad name", "value");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue