Fix label in .fields() accessor (#2884)

This commit is contained in:
Sébastien d'Herbais de Thun 2023-12-07 12:22:07 +01:00 committed by GitHub
parent 0bdd2191c0
commit 3e96f5f75f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 0 deletions

View File

@ -922,6 +922,17 @@ fn create_native_elem_impl(element: &Elem) -> TokenStream {
.unless_capability("Unlabellable", || quote! { self.label().is_some() })
.unwrap_or_else(|| quote! { false });
let label_field_dict = element.unless_capability("Unlabellable", || {
quote! {
if let Some(label) = self.label() {
fields.insert(
::ecow::EcoString::inline("label").into(),
#foundations::IntoValue::into_value(label)
);
}
}
});
let mark_prepared = element
.unless_capability("Unlabellable", || quote! { self.prepared = true; })
.unwrap_or_else(|| quote! {});
@ -1077,6 +1088,7 @@ fn create_native_elem_impl(element: &Elem) -> TokenStream {
fn fields(&self) -> #foundations::Dict {
let mut fields = #foundations::Dict::new();
#label_field_dict
#(#field_dict)*
#(#field_opt_dict)*
fields

View File

@ -0,0 +1,31 @@
// Tests whether the label is accessible through the has, field,
// and fields accessors
// Ref: false
---
// Test whether the label is accessible through the has method
#show heading: it => {
assert(it.has("label"))
it
}
= Hello, world! <my_label>
---
// Test whether the label is accessible through the field method
#show heading: it => {
assert(str(it.label) == "my_label")
it
}
= Hello, world! <my_label>
---
// Test whether the label is accessible through the fields method
#show heading: it => {
assert("label" in it.fields())
assert(str(it.fields().label) == "my_label")
it
}
= Hello, world! <my_label>