winged-rust 1.0.1

Fast, type-safe HTML DSL and static site generation engine in Rust and WebAssembly
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
//! The [`html!`](crate::html) declarative macro.
//!
//! Rust's answer to Winged-Swift's `@HTMLBuilder` / `@HTMLFragmentBuilder` result builders
//! (`Sources/WingedSwift/functions/HTMLFunctions.swift`). It is **sugar over the builder
//! API, never a second code path** — every form here expands to the same `Element` and
//! `Node` calls you would write by hand, so there is exactly one renderer to keep correct.

use crate::core::{Element, Node};

/// Builds a node tree from nested markup-like syntax.
///
/// # Syntax
///
/// | form | meaning |
/// | --- | --- |
/// | `div { … }` | an element with children |
/// | `div(class = "card", id = "x") { … }` | attributes, then children |
/// | `input(type = "email", required)` | a bare name is a boolean attribute |
/// | `"text"` | escaped text |
/// | `(expr)` | an escaped `Display` expression |
/// | `raw(expr)` | unescaped markup |
/// | `@if cond { … } @else { … }` | conditional, empty branch renders to nothing |
/// | `@for pat in iter { … }` | repetition |
///
/// # Examples
///
/// ```
/// use winged_rust::{html, prelude::*};
///
/// let page = html! {
///     div(class = "card", id = "hero") {
///         h1 { "Welcome" }
///         p { "Fuel, tyres & chain." }
///     }
/// };
///
/// assert_eq!(
///     page.render(),
///     r#"<div class="card" id="hero"><h1>Welcome</h1><p>Fuel, tyres &amp; chain.</p></div>"#
/// );
/// ```
///
/// Conditionals and loops, matching `buildOptional` / `buildEither` / `buildArray`:
///
/// ```
/// use winged_rust::{html, prelude::*};
///
/// let names = ["Ana", "Bruno"];
/// let logged_in = false;
///
/// let list = html! {
///     ul {
///         @for name in names { li { (name) } }
///         @if logged_in { li { "Sign out" } }
///     }
/// };
///
/// assert_eq!(list.render(), "<ul><li>Ana</li><li>Bruno</li></ul>");
/// ```
///
/// The expansion is the builder API, so the two are interchangeable:
///
/// ```
/// use winged_rust::{html, prelude::*};
/// assert_eq!(
///     html! { p(class = "lead") { "hi" } }.render(),
///     Node::from(p().add_class("lead").child(Node::text("hi"))).render()
/// );
/// ```
#[macro_export]
macro_rules! html {
    // A single root node.
    ($($body:tt)*) => {{
        let mut __nodes = $crate::macros::node_buffer();
        $crate::html_nodes!(__nodes, $($body)*);
        if __nodes.len() == 1 {
            __nodes.pop().unwrap_or_else(|| $crate::Node::Fragment(::std::vec::Vec::new()))
        } else {
            $crate::Node::Fragment(__nodes)
        }
    }};
}

/// Accumulates sibling nodes into a `Vec`. Not part of the public API.
#[doc(hidden)]
#[macro_export]
macro_rules! html_nodes {
    // Terminal.
    ($out:ident,) => {};

    // @if and @for hand off to a token muncher. A `$cond:expr` fragment cannot be
    // used before a brace: the expression parser would read `show { … }` as a struct
    // literal and macro_rules cannot backtrack once a fragment has been consumed.
    ($out:ident, @if $($tail:tt)*) => { $crate::html_if!($out, [] $($tail)*); };
    ($out:ident, @for $($tail:tt)*) => { $crate::html_for!($out, [] $($tail)*); };

    // raw(expr) — unescaped markup.
    ($out:ident, raw($value:expr) $($rest:tt)*) => {
        $out.push($crate::Node::raw(::std::string::ToString::to_string(&$value)));
        $crate::html_nodes!($out, $($rest)*);
    };

    // Element with attributes and children.
    ($out:ident, $tag:ident ( $($attrs:tt)* ) { $($children:tt)* } $($rest:tt)*) => {
        {
            let __el = $crate::elements::$tag();
            let __el = $crate::html_attrs!(__el, $($attrs)*);
            let mut __kids = $crate::macros::node_buffer();
            $crate::html_nodes!(__kids, $($children)*);
            $out.push($crate::Node::Element(
                $crate::macros::element_with_children(__el, __kids)));
        }
        $crate::html_nodes!($out, $($rest)*);
    };

    // Element with attributes only.
    ($out:ident, $tag:ident ( $($attrs:tt)* ) $($rest:tt)*) => {
        {
            let __el = $crate::elements::$tag();
            $out.push($crate::Node::Element($crate::html_attrs!(__el, $($attrs)*)));
        }
        $crate::html_nodes!($out, $($rest)*);
    };

    // Element with children only.
    ($out:ident, $tag:ident { $($children:tt)* } $($rest:tt)*) => {
        {
            let mut __kids = $crate::macros::node_buffer();
            $crate::html_nodes!(__kids, $($children)*);
            $out.push($crate::Node::Element(
                $crate::macros::element_with_children($crate::elements::$tag(), __kids)));
        }
        $crate::html_nodes!($out, $($rest)*);
    };

    // Interpolated expression, escaped.
    ($out:ident, ($value:expr) $($rest:tt)*) => {
        $out.push($crate::Node::text(::std::string::ToString::to_string(&$value)));
        $crate::html_nodes!($out, $($rest)*);
    };

    // Literal text, escaped.
    ($out:ident, $text:literal $($rest:tt)*) => {
        $out.push($crate::Node::text($text));
        $crate::html_nodes!($out, $($rest)*);
    };

    // A bare element with no attributes and no children.
    ($out:ident, $tag:ident $($rest:tt)*) => {
        $out.push($crate::Node::Element($crate::elements::$tag()));
        $crate::html_nodes!($out, $($rest)*);
    };
}

/// Applies an attribute list to an element. Not part of the public API.
#[doc(hidden)]
#[macro_export]
macro_rules! html_attrs {
    ($el:expr,) => { $el };
    ($el:expr) => { $el };

    // "key" = value — a string key, for names that are Rust keywords such as `type`.
    ($el:expr, $key:literal = $value:expr, $($rest:tt)*) => {
        $crate::html_attrs!(
            $el.attr($key, ::std::string::ToString::to_string(&$value)), $($rest)*)
    };
    ($el:expr, $key:literal = $value:expr) => {
        $el.attr($key, ::std::string::ToString::to_string(&$value))
    };

    // key = value
    ($el:expr, $key:ident = $value:expr, $($rest:tt)*) => {
        $crate::html_attrs!(
            $el.attr(stringify!($key), ::std::string::ToString::to_string(&$value)), $($rest)*)
    };
    ($el:expr, $key:ident = $value:expr) => {
        $el.attr(stringify!($key), ::std::string::ToString::to_string(&$value))
    };

    // A bare name is a boolean attribute.
    ($el:expr, $key:literal, $($rest:tt)*) => {
        $crate::html_attrs!($el.bool_attr($key), $($rest)*)
    };
    ($el:expr, $key:literal) => {
        $el.bool_attr($key)
    };
    ($el:expr, $key:ident, $($rest:tt)*) => {
        $crate::html_attrs!($el.bool_attr(stringify!($key)), $($rest)*)
    };
    ($el:expr, $key:ident) => {
        $el.bool_attr(stringify!($key))
    };
}

/// An empty sibling buffer for the macro to push into.
///
/// A function rather than an inline `Vec::new()` so that `clippy::vec_init_then_push` does
/// not fire inside every `html!` expansion in every downstream crate. The lint is about
/// hand-written style; this code is generated.
#[doc(hidden)]
#[must_use]
pub fn node_buffer() -> Vec<Node> {
    Vec::new()
}

/// Attaches macro-collected children to an element.
///
/// When every child is text, it becomes the element's **content** rather than a list of
/// child nodes. That is what the builder API produces for `p().text("x")`, and the two
/// render differently once pretty printing is on: content stays on the element's line,
/// while a child text node gets its own indented line. Collapsing here is what keeps the
/// macro true sugar over the builder rather than a second, subtly different code path.
#[doc(hidden)]
#[must_use]
pub fn element_with_children(element: Element, children: Vec<Node>) -> Element {
    let all_text = !children.is_empty() && children.iter().all(|c| matches!(c, Node::Text(_)));

    if all_text {
        let mut content = String::new();
        for child in children {
            if let Node::Text(text) = child {
                content.push_str(&text);
            }
        }
        // The text was escaped when each node was built, so it goes in verbatim.
        return element.raw_text(content);
    }

    element.children_from(children)
}

/// Token muncher for `@if`. Collects condition tokens until the body block. Not public.
#[doc(hidden)]
#[macro_export]
macro_rules! html_if {
    ($out:ident, [$($cond:tt)+] { $($body:tt)* } @else { $($alt:tt)* } $($rest:tt)*) => {
        if $($cond)+ { $crate::html_nodes!($out, $($body)*); }
        else { $crate::html_nodes!($out, $($alt)*); }
        $crate::html_nodes!($out, $($rest)*);
    };
    ($out:ident, [$($cond:tt)+] { $($body:tt)* } $($rest:tt)*) => {
        if $($cond)+ { $crate::html_nodes!($out, $($body)*); }
        $crate::html_nodes!($out, $($rest)*);
    };
    ($out:ident, [$($cond:tt)*] $next:tt $($rest:tt)*) => {
        $crate::html_if!($out, [$($cond)* $next] $($rest)*);
    };
}

/// Token muncher for `@for`. Collects `pat in iter` until the body block. Not public.
#[doc(hidden)]
#[macro_export]
macro_rules! html_for {
    ($out:ident, [$($head:tt)+] { $($body:tt)* } $($rest:tt)*) => {
        for $($head)+ { $crate::html_nodes!($out, $($body)*); }
        $crate::html_nodes!($out, $($rest)*);
    };
    ($out:ident, [$($head:tt)*] $next:tt $($rest:tt)*) => {
        $crate::html_for!($out, [$($head)* $next] $($rest)*);
    };
}

#[cfg(test)]
mod tests {
    use crate::prelude::*;

    #[test]
    fn a_bare_element_renders_empty() {
        assert_eq!(html! { div }.render(), "<div></div>");
    }

    #[test]
    fn text_children_are_escaped() {
        assert_eq!(html! { p { "a & b" } }.render(), "<p>a &amp; b</p>");
    }

    #[test]
    fn raw_children_are_not_escaped() {
        assert_eq!(html! { p { raw("<b>x</b>") } }.render(), "<p><b>x</b></p>");
    }

    #[test]
    fn attributes_and_children_combine() {
        assert_eq!(
            html! { div(class = "card", id = "hero") { p { "hi" } } }.render(),
            r#"<div class="card" id="hero"><p>hi</p></div>"#
        );
    }

    #[test]
    fn a_bare_attribute_name_is_a_boolean_attribute() {
        assert_eq!(
            html! { input("type" = "email", name = "email", required) }.render(),
            r#"<input type="email" name="email" required>"#
        );
    }

    #[test]
    fn expressions_interpolate_escaped() {
        let name = "Tom & Jerry";
        assert_eq!(
            html! { span { (name) } }.render(),
            "<span>Tom &amp; Jerry</span>"
        );
    }

    /// Matches `buildArray` in Winged-Swift's `HTMLBuilder`.
    #[test]
    fn for_loops_expand_to_siblings() {
        let names = ["Ana", "Bruno"];
        assert_eq!(
            html! { ul { @for n in names { li { (n) } } } }.render(),
            "<ul><li>Ana</li><li>Bruno</li></ul>"
        );
    }

    /// Matches `buildOptional`: a false branch renders to nothing at all.
    #[test]
    fn a_false_condition_contributes_no_node() {
        let show = false;
        assert_eq!(
            html! { div { @if show { p { "x" } } } }.render(),
            "<div></div>"
        );
    }

    /// Matches `buildEither`.
    #[test]
    fn if_else_picks_one_branch() {
        let logged_in = true;
        let markup = html! {
            nav { @if logged_in { a { "Sign out" } } @else { a { "Sign in" } } }
        };
        assert_eq!(markup.render(), "<nav><a>Sign out</a></nav>");
    }

    #[test]
    fn several_roots_become_a_fragment() {
        assert_eq!(html! { p { "a" } p { "b" } }.render(), "<p>a</p><p>b</p>");
    }

    /// The macro is sugar: it must produce exactly what the builder produces.
    #[test]
    fn macro_output_equals_the_builder_output() {
        let from_macro = html! { div(class = "card") { h1 { "T" } p { "B" } } };
        let from_builder = Node::from(
            div()
                .add_class("card")
                .child(h1().text("T"))
                .child(p().text("B")),
        );
        assert_eq!(from_macro.render(), from_builder.render());
        assert_eq!(from_macro.render_pretty(), from_builder.render_pretty());
    }

    #[test]
    fn nesting_survives_pretty_printing() {
        let markup = html! { div { section { p { "deep" } } } };
        assert_eq!(
            markup.render_pretty(),
            "<div>\n  <section>\n    <p>deep</p>\n  </section>\n</div>"
        );
    }

    // Ports `BuilderInitTests`, whose thesis is that Swift's result-builder initialiser is
    // *exactly* equivalent to the array one. `html!` makes the same promise here — rule 9
    // of AGENTS.md: sugar over the builder, never a second code path — so each of these
    // asserts the macro and the builder agree, and then pins the markup.

    /// Ports `BuilderInitTests.plainContainer`.
    #[test]
    fn the_macro_and_the_builder_agree_on_a_plain_container() {
        let macro_built = html! { div { p { "Hi" } } };
        let builder_built = div().child(p().text("Hi"));

        assert_eq!(macro_built.render(), builder_built.render());
        assert_eq!(macro_built.render(), "<div><p>Hi</p></div>");
    }

    /// Ports `BuilderInitTests.containerWithRequiredAttribute`.
    #[test]
    fn the_macro_and_the_builder_agree_on_a_required_attribute() {
        let macro_built = html! { a(href = "/docs") { span { "Docs" } } };
        let builder_built = link_to("/docs").child(span().text("Docs"));

        assert_eq!(macro_built.render(), builder_built.render());
        assert_eq!(
            macro_built.render(),
            r#"<a href="/docs"><span>Docs</span></a>"#
        );
    }

    /// Ports `BuilderInitTests.containerWithAttributesAndContent`.
    #[test]
    fn attributes_and_children_render_together() {
        assert_eq!(
            html! { div(id = "main") { p { "Hi" } } }.render(),
            r#"<div id="main"><p>Hi</p></div>"#
        );
    }

    /// Ports `BuilderInitTests.booleanFlagIsPreserved`.
    #[test]
    fn a_boolean_flag_survives_the_macro() {
        assert_eq!(
            html! { details(open) { summary { "More" } } }.render(),
            "<details open><summary>More</summary></details>"
        );
    }

    /// Ports `BuilderInitTests.tableFamily`.
    #[test]
    fn the_table_family_nests() {
        let markup = html! {
            table {
                thead { tr { th { "A" } } }
                tbody { tr { td { "1" } } }
            }
        };

        assert_eq!(
            markup.render(),
            "<table><thead><tr><th>A</th></tr></thead><tbody><tr><td>1</td></tr></tbody></table>"
        );
    }

    /// Ports `BuilderInitTests.formFamily`.
    ///
    /// `for` is a Rust keyword, so the attribute name is quoted — the one place the macro
    /// asks for punctuation the Swift builder does not.
    #[test]
    fn the_form_family_nests() {
        let markup = html! {
            form {
                fieldset {
                    legend { "Account" }
                    label("for" = "email") { "Email" }
                }
            }
        };

        assert_eq!(
            markup.render(),
            concat!(
                "<form><fieldset><legend>Account</legend>",
                r#"<label for="email">Email</label></fieldset></form>"#,
            )
        );
    }

    /// Ports `BuilderInitTests.mediaFamily`.
    #[test]
    fn the_media_family_nests() {
        let markup = html! {
            picture {
                source(srcset = "a.webp", "type" = "image/webp")
                img(src = "a.jpg", alt = "A")
            }
        };

        assert_eq!(
            markup.render(),
            concat!(
                r#"<picture><source srcset="a.webp" type="image/webp">"#,
                r#"<img src="a.jpg" alt="A"></picture>"#,
            )
        );
    }

    /// Ports `BuilderInitTests.loopsInsideTheBuilder`.
    #[test]
    fn a_loop_inside_the_macro_repeats_its_body() {
        let markup = html! { ul { @for name in ["a", "b", "c"] { li { (name) } } } };

        assert_eq!(markup.render(), "<ul><li>a</li><li>b</li><li>c</li></ul>");
    }

    /// Ports `BuilderInitTests.conditionsInsideTheBuilder`.
    #[test]
    fn a_false_condition_inside_the_macro_renders_nothing() {
        let is_admin = false;
        let markup = html! {
            nav {
                a(href = "/") { "Home" }
                @if is_admin { a(href = "/admin") { "Admin" } }
            }
        };

        assert_eq!(markup.render(), r#"<nav><a href="/">Home</a></nav>"#);
    }

    /// Ports `BuilderInitTests.mapInsideTheBuilder`.
    ///
    /// Swift drops a `map` straight into the builder. The macro takes an iterator through
    /// `@for` instead, and `children_from` is the builder's spelling of the same thing —
    /// the test is that both land on identical markup.
    #[test]
    fn a_mapped_sequence_matches_the_macro_loop() {
        let macro_built = html! { ol { @for item in ["x", "y"] { li { (item) } } } };
        let builder_built = ol().children_from(["x", "y"].map(|item| li().text(item)));

        assert_eq!(macro_built.render(), builder_built.render());
        assert_eq!(macro_built.render(), "<ol><li>x</li><li>y</li></ol>");
    }

    /// Ports `BuilderInitTests.emptyBuilderProducesAnEmptyElement`.
    #[test]
    fn an_empty_body_produces_an_empty_element() {
        assert_eq!(html! { div {} }.render(), "<div></div>");
    }

    /// Ports `BuilderInitTests.untypedElementSupportsTheBuilder`.
    ///
    /// The macro resolves a tag name to its generated constructor, and there is no
    /// `hgroup()` among the 93 — Winged-Swift has no `Hgroup` type either, which is why its
    /// own test reaches for the untyped `HTMLTag`. `Element::new` is that escape hatch here,
    /// and it composes with macro-built children.
    #[test]
    fn an_untyped_element_takes_macro_built_children() {
        let group = Element::new("hgroup")
            .child(html! { h1 { "Title" } })
            .child(html! { p { "Subtitle" } });

        assert_eq!(
            group.render(),
            "<hgroup><h1>Title</h1><p>Subtitle</p></hgroup>"
        );
    }

    /// Ports `BuilderInitTests.chainingStillPreservesTheType`.
    ///
    /// Swift's builder initialiser returns the concrete tag type, so `.addClass` chains off
    /// it. `html!` returns a [`Node`], which is the union of every shape a child can take
    /// and has no builder methods — so chaining happens on the builder, and the macro
    /// supplies the children. Both spellings render the same.
    #[test]
    fn chaining_happens_on_the_builder_side() {
        let chained = div().child(html! { p { "Hi" } }).add_class("card");

        assert_eq!(chained.render(), r#"<div class="card"><p>Hi</p></div>"#);
    }

    /// Ports `BuilderInitTests.nestingIsArbitrarilyDeep`.
    #[test]
    fn nesting_goes_as_deep_as_it_is_written() {
        let page = html! {
            body { main_tag { section { article { h2 { "Title" } } } } }
        };

        assert_eq!(
            page.render(),
            "<body><main><section><article><h2>Title</h2></article></section></main></body>"
        );
    }

    // Ports `HTMLBuilderTests`, which exercises Swift's result-builder plumbing:
    // `buildOptional`, `buildEither` and `buildExpression`. Those are compiler hooks with
    // no counterpart here — `html!` lowers `@if`/`@else`/`@for` straight onto the builder —
    // so each port keeps the *behaviour* the Swift test describes. Several of those tests
    // reach into `document.children[0].name`; these assert markup instead, which is rule 11
    // of AGENTS.md and the reason Winged-Swift's own suite survived its 2.0 rewrite.

    /// Ports `HTMLBuilderTests.testHTMLBuilderCreatesRootHTMLTag`.
    #[test]
    fn a_root_html_element_keeps_its_children_in_order() {
        let document = html_tag().child(body()).child(head());

        assert_eq!(document.render(), "<html><body></body><head></head></html>");
    }

    /// Ports `HTMLBuilderTests.testHTMLBuilderHandlesOptional`.
    ///
    /// `Option` is an iterator of zero or one item, so `children_from` is all the plumbing
    /// an optional child needs.
    #[test]
    fn an_optional_child_is_included_when_present() {
        let present: Option<Element> = Some(Element::new("optional"));
        let absent: Option<Element> = None;

        assert_eq!(
            html_tag().children_from(present).render(),
            "<html><optional></optional></html>"
        );
        assert_eq!(html_tag().children_from(absent).render(), "<html></html>");
    }

    /// Ports `HTMLBuilderTests.testHTMLBuilderWrapsASingleNonGroupedComponent`.
    #[test]
    fn a_single_child_gains_no_wrapper() {
        let document = html_tag().child(body().child(h1().text("Hi")));

        assert_eq!(document.render(), "<html><body><h1>Hi</h1></body></html>");
    }

    /// Ports `HTMLBuilderTests.testHTMLBuilderTakesBothBranchesOfAnIfElse`.
    #[test]
    fn an_if_else_renders_whichever_branch_holds() {
        fn page(logged_in: bool) -> Element {
            html_tag().child(html! {
                @if logged_in { nav { "Sign out" } } @else { nav { "Sign in" } }
            })
        }

        assert_eq!(page(true).render(), "<html><nav>Sign out</nav></html>");
        assert_eq!(page(false).render(), "<html><nav>Sign in</nav></html>");
    }

    /// Ports `HTMLBuilderTests.testHTMLBuilderAcceptsAnArrayExpression`.
    #[test]
    fn a_sequence_of_children_flattens_into_siblings() {
        let document = html_tag().children_from(["a", "b"].map(|text| p().text(text)));

        assert_eq!(document.render(), "<html><p>a</p><p>b</p></html>");
    }

    /// Ports `HTMLBuilderTests.testHTMLBuilderHandlesEitherFirst`.
    ///
    /// Swift names the branches with the untyped `HTMLTag("first")`; the macro resolves a
    /// tag name to its generated constructor, so real tags stand in.
    #[test]
    fn the_first_branch_of_a_condition_renders_alone() {
        let document = html_tag().child(html! {
            @if true { header } @else { footer }
        });

        assert_eq!(document.render(), "<html><header></header></html>");
    }

    /// Ports `HTMLBuilderTests.testHTMLBuilderHandlesEitherSecond`.
    #[test]
    fn the_second_branch_of_a_condition_renders_alone() {
        let document = html_tag().child(html! {
            @if false { header } @else { footer }
        });

        assert_eq!(document.render(), "<html><footer></footer></html>");
    }
}