Added additional test for the #[property(..)] generator for a currently failing example.
This commit is contained in:
parent
300be72385
commit
ddcec75613
|
@ -681,16 +681,33 @@ mod property_tests {
|
|||
let _ = c;
|
||||
child
|
||||
}
|
||||
|
||||
#[property(context)]
|
||||
fn not_var_input(child: impl UiNode, input: &'static str) -> impl UiNode {
|
||||
let _ = input;
|
||||
child
|
||||
}
|
||||
}
|
||||
|
||||
/// Tests on the #[widget(..)] and #[widget_mixin], widget_new! code generators.
|
||||
#[cfg(test)]
|
||||
mod widget_tests {
|
||||
use crate::{widget2, widget_mixin2, Widget, WidgetId};
|
||||
use std::collections::HashSet;
|
||||
|
||||
use crate::{property, state_key, var::Var, widget2, widget_mixin2, UiNode, Widget, WidgetId};
|
||||
|
||||
#[widget2($crate::widget_tests::empty_wgt)]
|
||||
pub mod empty_wgt {}
|
||||
|
||||
state_key! {
|
||||
struct TraceKey: HashSet<&'static str>;
|
||||
}
|
||||
|
||||
#[property(context)]
|
||||
fn trace(child: impl UiNode, trace: impl Var<&'static str>) -> impl UiNode {
|
||||
child
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn implicit_inherited() {
|
||||
let expected = WidgetId::new_unique();
|
||||
|
|
|
@ -711,7 +711,7 @@ mod output {
|
|||
let arg_debug_vars = {
|
||||
let ( #(#arg_locals),* ) = self_.unwrap_ref();
|
||||
Box::new([
|
||||
#(
|
||||
#(// TODO: If the value is not a var the compiler requires a type hint here. See `not_var_input` test.
|
||||
#crate_core::debug::debug_var(
|
||||
#crate_core::var::IntoVar::into_var(
|
||||
std::clone::Clone::clone(#arg_locals)
|
||||
|
|
|
@ -107,7 +107,7 @@ pub fn expand(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
|||
let mut user_prop_set_calls = vec![];
|
||||
let mut unset_properties = HashSet::new();
|
||||
let mut user_properties = HashSet::new();
|
||||
|
||||
|
||||
// for each property assigned in the widget instantiation call (excluding when blocks).
|
||||
for up in &user_input.properties {
|
||||
let p_name = util::display_path(&up.path);
|
||||
|
@ -143,7 +143,7 @@ pub fn expand(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
|||
errors.push(format_args!("unknown value `{}!`", sp), sp.span());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if !user_properties.insert(&up.path) {
|
||||
errors.push(format_args!("property `{}` already set", p_name), up.path.span());
|
||||
continue;
|
||||
|
@ -250,7 +250,7 @@ pub fn expand(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
|||
wgt_properties
|
||||
.get(&parse_quote! {#p})
|
||||
.unwrap_or_else(|| non_user_error!("captured property is unknown"))
|
||||
});
|
||||
});
|
||||
let new_caps = widget_data.new.iter().map(|p| {
|
||||
wgt_properties
|
||||
.get(&parse_quote! {#p})
|
||||
|
@ -258,7 +258,7 @@ pub fn expand(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
|||
});
|
||||
let new_child_call = quote! {
|
||||
let node__ = #module::__new_child(#(#new_child_caps),*);
|
||||
};
|
||||
};
|
||||
let new_call = quote! {
|
||||
#module::__new(node__, #(#new_caps),*)
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue