fix test failures

This commit is contained in:
Evan Almloff committed 2023-08-08 11:27:29 -07:00
1 parent aaded7981f
commit e43bdd815f
5 files changed
+20 -7

No files matched your search

+4 -1
View File
@@ -88,15 +88,18 @@ pub trait HistoryProvider<R: Routable> {
/// # use dioxus::prelude::*; /// # use dioxus::prelude::*;
/// # #[inline_props] /// # #[inline_props]
/// # fn Index(cx: Scope) -> Element { todo!() } /// # fn Index(cx: Scope) -> Element { todo!() }
/// # fn Other(cx: Scope) -> Element { todo!() }
/// #[derive(Clone, Routable, Debug, PartialEq)] /// #[derive(Clone, Routable, Debug, PartialEq)]
/// enum Route { /// enum Route {
/// #[route("/")] /// #[route("/")]
/// Index {}, /// Index {},
/// #[route("/other")]
/// Other {},
/// } /// }
/// let mut history = MemoryHistory::<Route>::default(); /// let mut history = MemoryHistory::<Route>::default();
/// assert_eq!(history.can_go_back(), false); /// assert_eq!(history.can_go_back(), false);
/// ///
/// history.push(Route::Index {}); /// history.push(Route::Other {});
/// assert_eq!(history.can_go_back(), true); /// assert_eq!(history.can_go_back(), true);
/// ``` /// ```
#[must_use] #[must_use]
+1 -1
View File
@@ -34,7 +34,7 @@ use crate::utils::use_router_internal::use_router_internal;
/// ///
/// #[inline_props] /// #[inline_props]
/// fn Index(cx: Scope) -> Element { /// fn Index(cx: Scope) -> Element {
/// let path = use_route(&cx).unwrap(); /// let path: Route = use_route(&cx).unwrap();
/// render! { /// render! {
/// h2 { "Current Path" } /// h2 { "Current Path" }
/// p { "{path}" } /// p { "{path}" }
+2 -2
View File
@@ -162,9 +162,9 @@ pub trait Routable: std::fmt::Display + std::str::FromStr + Clone + 'static {
/// ///
/// #[derive(Routable, Clone, PartialEq, Debug)] /// #[derive(Routable, Clone, PartialEq, Debug)]
/// enum Route { /// enum Route {
/// #[route("/")] /// #[route("/home")]
/// Home {}, /// Home {},
/// #[route("/about")] /// #[route("/home/about")]
/// About {}, /// About {},
/// } /// }
/// ///
+13 -2
View File
@@ -1,6 +1,7 @@
use super::cache::Segment; use super::cache::Segment;
use crate::cache::StringCache; use crate::cache::StringCache;
use dioxus_core::Attribute;
use dioxus_core::{prelude::*, AttributeValue, DynamicNode, RenderReturn}; use dioxus_core::{prelude::*, AttributeValue, DynamicNode, RenderReturn};
use std::collections::HashMap; use std::collections::HashMap;
use std::fmt::Write; use std::fmt::Write;
@@ -90,8 +91,7 @@ impl Renderer {
write_value(buf, &attr.value)?; write_value(buf, &attr.value)?;
} }
} else { } else {
write!(buf, " {}=", attr.name)?; write_attribute(buf, &attr)?;
write_value(buf, &attr.value)?;
} }
} }
Segment::Node(idx) => match &template.dynamic_nodes[*idx] { Segment::Node(idx) => match &template.dynamic_nodes[*idx] {
@@ -282,6 +282,17 @@ pub(crate) fn truthy(value: &AttributeValue) -> bool {
} }
} }
pub(crate) fn write_attribute(buf: &mut impl Write, attr: &Attribute) -> std::fmt::Result {
let name = &attr.name;
match attr.value {
AttributeValue::Text(value) => write!(buf, " {name}=\"{value}\""),
AttributeValue::Bool(value) => write!(buf, " {name}={value}"),
AttributeValue::Int(value) => write!(buf, " {name}={value}"),
AttributeValue::Float(value) => write!(buf, " {name}={value}"),
_ => Ok(()),
}
}
pub(crate) fn write_value(buf: &mut impl Write, value: &AttributeValue) -> std::fmt::Result { pub(crate) fn write_value(buf: &mut impl Write, value: &AttributeValue) -> std::fmt::Result {
match value { match value {
AttributeValue::Text(value) => write!(buf, "\"{}\"", value), AttributeValue::Text(value) => write!(buf, "\"{}\"", value),
-1
View File
@@ -21,7 +21,6 @@ fn static_boolean_attributs() {
#[test] #[test]
fn dynamic_boolean_attributs() { fn dynamic_boolean_attributs() {
fn app(cx: Scope) -> Element { fn app(cx: Scope) -> Element {
let inner_html = "<div>1234</div>";
render! { render! {
div { hidden: false } div { hidden: false }
div { hidden: true } div { hidden: true }