rdom-tui 0.5.0

Terminal rendering layer for rdom-core — flexbox layout, TUI styles, key/mouse events. Use rdom-core directly for headless DOM manipulation.
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
//! B.1 tests — caret detection + paint.
//!
//! Covers:
//! - `is_editable()` recognizes `contenteditable="true"` / `""`.
//! - `nearest_editable_ancestor` walks up through the tree.
//! - `cell_of_position` maps positions to cells for ASCII, CJK,
//!   mid-line, end-of-line, wrapped paragraphs.
//! - The paint pass paints explicit fg/bg on the caret cell when a
//!   focused editable has a collapsed selection, and leaves the
//!   buffer untouched otherwise.

use rdom_core::{Position, Selection};

use crate::TuiDom;
use crate::layout::{Display, Size};
use crate::node::{TuiNodeExt, nearest_editable_ancestor};
use crate::render::{Buffer, LayoutExt, PaintExt, Rect};
use crate::runtime::editing::caret::cell_of_position;
use crate::style::{CascadeExt, Color, Stylesheet, TuiStyle};

// ── is_editable ─────────────────────────────────────────────────────

#[test]
fn is_editable_true_attr_matches() {
    let mut dom: TuiDom = TuiDom::new();
    let root = dom.root();
    let el = dom.create_element("div");
    dom.set_attribute(el, "contenteditable", "true").unwrap();
    dom.append_child(root, el).unwrap();
    assert!(dom.node(el).is_editable());
}

#[test]
fn is_editable_empty_string_matches_html_boolean_attr() {
    // HTML lets `contenteditable` (no value) mean true. Parser emits
    // it as an empty-string attr value.
    let mut dom: TuiDom = TuiDom::new();
    let root = dom.root();
    let el = dom.create_element("div");
    dom.set_attribute(el, "contenteditable", "").unwrap();
    dom.append_child(root, el).unwrap();
    assert!(dom.node(el).is_editable());
}

#[test]
fn is_editable_false_does_not_match() {
    let mut dom: TuiDom = TuiDom::new();
    let root = dom.root();
    let el = dom.create_element("div");
    dom.set_attribute(el, "contenteditable", "false").unwrap();
    dom.append_child(root, el).unwrap();
    assert!(!dom.node(el).is_editable());
}

#[test]
fn is_editable_absent_returns_false() {
    let mut dom: TuiDom = TuiDom::new();
    let root = dom.root();
    let el = dom.create_element("div");
    dom.append_child(root, el).unwrap();
    assert!(!dom.node(el).is_editable());
}

/// HTML §6.8.1: `contenteditable` is an enumerated attribute whose
/// keywords match ASCII case-insensitively; `plaintext-only` is an
/// editing host too; an invalid value is the inherit state (not a host).
#[test]
fn is_editable_matches_contenteditable_keywords_case_insensitively() {
    let mut dom: TuiDom = TuiDom::new();
    let root = dom.root();
    let mut make = |v: &str| {
        let el = dom.create_element("div");
        dom.set_attribute(el, "contenteditable", v).unwrap();
        dom.append_child(root, el).unwrap();
        el
    };
    let upper = make("TRUE");
    let mixed = make("True");
    let plain = make("PlainText-Only");
    let false_upper = make("FALSE");
    let bogus = make("yes");
    assert!(dom.node(upper).is_editable());
    assert!(dom.node(mixed).is_editable());
    assert!(dom.node(plain).is_editable());
    assert!(!dom.node(false_upper).is_editable());
    assert!(!dom.node(bogus).is_editable());
}

// ── C.4a: tag-based editability ────────────────────────────────────

#[test]
fn input_default_type_is_editable() {
    let mut dom: TuiDom = TuiDom::new();
    let root = dom.root();
    let el = dom.create_element("input");
    dom.append_child(root, el).unwrap();
    assert!(dom.node(el).is_editable());
}

#[test]
fn input_text_family_types_are_editable() {
    for ty in ["text", "password", "email", "url", "tel", "search"] {
        let mut dom: TuiDom = TuiDom::new();
        let root = dom.root();
        let el = dom.create_element("input");
        dom.set_attribute(el, "type", ty).unwrap();
        dom.append_child(root, el).unwrap();
        assert!(dom.node(el).is_editable(), "type={} should be editable", ty);
    }
}

#[test]
fn input_non_text_types_are_not_editable() {
    // C.4b will give checkbox / radio their own behavior — they
    // route through `<button>`-style activation, not text editing.
    for ty in ["checkbox", "radio", "submit", "reset", "button", "hidden"] {
        let mut dom: TuiDom = TuiDom::new();
        let root = dom.root();
        let el = dom.create_element("input");
        dom.set_attribute(el, "type", ty).unwrap();
        dom.append_child(root, el).unwrap();
        assert!(
            !dom.node(el).is_editable(),
            "type={} should not be text-editable",
            ty
        );
    }
}

#[test]
fn textarea_is_editable() {
    let mut dom: TuiDom = TuiDom::new();
    let root = dom.root();
    let el = dom.create_element("textarea");
    dom.append_child(root, el).unwrap();
    assert!(dom.node(el).is_editable());
}

#[test]
fn disabled_input_is_not_editable() {
    let mut dom: TuiDom = TuiDom::new();
    let root = dom.root();
    let el = dom.create_element("input");
    dom.set_attribute(el, "disabled", "").unwrap();
    dom.append_child(root, el).unwrap();
    assert!(!dom.node(el).is_editable());
}

#[test]
fn disabled_textarea_is_not_editable() {
    let mut dom: TuiDom = TuiDom::new();
    let root = dom.root();
    let el = dom.create_element("textarea");
    dom.set_attribute(el, "disabled", "").unwrap();
    dom.append_child(root, el).unwrap();
    assert!(!dom.node(el).is_editable());
}

/// P7-FIELDSET-DISABLED-1: a text control inside a `<fieldset disabled>`
/// is disabled, so not editable; one in its first `<legend>` is.
#[test]
fn text_controls_in_a_disabled_fieldset_are_not_editable() {
    let mut dom: TuiDom = TuiDom::new();
    let root = dom.root();
    let fs = dom.create_element("fieldset");
    dom.set_attribute(fs, "disabled", "").unwrap();
    dom.append_child(root, fs).unwrap();
    let legend = dom.create_element("legend");
    dom.append_child(fs, legend).unwrap();
    let in_legend = dom.create_element("input");
    dom.append_child(legend, in_legend).unwrap();
    let input = dom.create_element("input");
    dom.append_child(fs, input).unwrap();
    let textarea = dom.create_element("textarea");
    dom.append_child(fs, textarea).unwrap();
    assert!(!dom.node(input).is_editable());
    assert!(!dom.node(textarea).is_editable());
    assert!(dom.node(in_legend).is_editable());
}

#[test]
fn readonly_input_is_still_editable_for_focus_routing() {
    // `readonly` does NOT make the element non-editable in the
    // `is_editable` sense — it stays focusable, selectable, and
    // routes through `nearest_editable_ancestor` like any input.
    // `perform_edit` is what blocks the actual mutation.
    let mut dom: TuiDom = TuiDom::new();
    let root = dom.root();
    let el = dom.create_element("input");
    dom.set_attribute(el, "readonly", "").unwrap();
    dom.append_child(root, el).unwrap();
    assert!(dom.node(el).is_editable());
}

// ── nearest_editable_ancestor ──────────────────────────────────────

#[test]
fn nearest_editable_ancestor_returns_self_when_editable() {
    let mut dom: TuiDom = TuiDom::new();
    let root = dom.root();
    let editable = dom.create_element("div");
    dom.set_attribute(editable, "contenteditable", "true")
        .unwrap();
    dom.append_child(root, editable).unwrap();
    assert_eq!(nearest_editable_ancestor(&dom, editable), Some(editable));
}

#[test]
fn nearest_editable_ancestor_walks_up_to_editable() {
    let mut dom: TuiDom = TuiDom::new();
    let root = dom.root();
    let editable = dom.create_element("div");
    dom.set_attribute(editable, "contenteditable", "true")
        .unwrap();
    let inner = dom.create_element("span");
    dom.append_child(editable, inner).unwrap();
    dom.append_child(root, editable).unwrap();
    assert_eq!(nearest_editable_ancestor(&dom, inner), Some(editable));
}

#[test]
fn nearest_editable_ancestor_none_when_nothing_editable() {
    let mut dom: TuiDom = TuiDom::new();
    let root = dom.root();
    let plain = dom.create_element("div");
    dom.append_child(root, plain).unwrap();
    assert_eq!(nearest_editable_ancestor(&dom, plain), None);
}

/// A `contenteditable="false"` island inside an editing host is not
/// editable (HTML §6.8.1: the false state stops inheritance), in any
/// letter case; an invalid value inherits.
#[test]
fn nearest_editable_ancestor_stops_at_a_false_island() {
    let mut dom: TuiDom = TuiDom::new();
    let root = dom.root();
    let host = dom.create_element("div");
    dom.set_attribute(host, "contenteditable", "true").unwrap();
    dom.append_child(root, host).unwrap();
    let island = dom.create_element("span");
    dom.set_attribute(island, "contenteditable", "False")
        .unwrap();
    dom.append_child(host, island).unwrap();
    let text = dom.create_text_node("fixed");
    dom.append_child(island, text).unwrap();
    let inherits = dom.create_element("span");
    dom.set_attribute(inherits, "contenteditable", "bogus")
        .unwrap();
    dom.append_child(host, inherits).unwrap();
    // A host nested in the island is editable again.
    let nested = dom.create_element("em");
    dom.set_attribute(nested, "contenteditable", "").unwrap();
    dom.append_child(island, nested).unwrap();

    assert_eq!(nearest_editable_ancestor(&dom, text), None);
    assert_eq!(nearest_editable_ancestor(&dom, island), None);
    assert_eq!(nearest_editable_ancestor(&dom, inherits), Some(host));
    assert_eq!(nearest_editable_ancestor(&dom, nested), Some(nested));
}

// ── cell_of_position ───────────────────────────────────────────────

/// Build a `<p contenteditable>hello<span/></p>` fixture. The span
/// makes the <p> qualify as an IFC. Returns (dom, p, text_node).
fn editable_paragraph(text: &str) -> (TuiDom, rdom_core::NodeId, rdom_core::NodeId) {
    let mut dom: TuiDom = TuiDom::new();
    let root = dom.root();
    let p = dom.create_element("p");
    dom.set_attribute(p, "contenteditable", "true").unwrap();
    let t = dom.create_text_node(text);
    dom.append_child(p, t).unwrap();
    let span = dom.create_element("span");
    dom.append_child(p, span).unwrap();
    dom.append_child(root, p).unwrap();

    let sheet = Stylesheet::bare()
        .rule_unchecked(
            "p",
            TuiStyle::new()
                .display(Display::Block)
                .width(Size::Fixed(40)),
        )
        .rule_unchecked("span", TuiStyle::new().display(Display::Inline));
    dom.cascade(&sheet);
    dom.layout_dom(Rect::new(0, 0, 60, 10));
    (dom, p, t)
}

#[test]
fn cell_of_position_at_start_is_origin() {
    let (dom, _p, t) = editable_paragraph("hello");
    let (x, y) = cell_of_position(&dom, Position::new(t, 0)).unwrap();
    assert_eq!((x, y), (0, 0));
}

#[test]
fn cell_of_position_advances_with_offset() {
    let (dom, _p, t) = editable_paragraph("hello");
    for byte_off in 0..=5 {
        let (x, _) = cell_of_position(&dom, Position::new(t, byte_off)).unwrap();
        assert_eq!(x, byte_off as u16);
    }
}

#[test]
fn cell_of_position_cjk_wide_glyph_advances_two_cells() {
    let (dom, _p, t) = editable_paragraph("中文");
    let (x0, _) = cell_of_position(&dom, Position::new(t, 0)).unwrap();
    let (x_mid, _) = cell_of_position(&dom, Position::new(t, 3)).unwrap(); // after '中'
    let (x_end, _) = cell_of_position(&dom, Position::new(t, 6)).unwrap(); // after '文'
    assert_eq!(x0, 0);
    assert_eq!(x_mid, 2);
    assert_eq!(x_end, 4);
}

#[test]
fn cell_of_position_wrapped_line_returns_correct_row() {
    // Narrow width forces wrapping. Position after "hello " (byte 6)
    // should be on row 1, cell 0 — the wrap drop.
    let mut dom: TuiDom = TuiDom::new();
    let root = dom.root();
    let p = dom.create_element("p");
    dom.set_attribute(p, "contenteditable", "true").unwrap();
    let t = dom.create_text_node("hello world");
    dom.append_child(p, t).unwrap();
    let span = dom.create_element("span");
    dom.append_child(p, span).unwrap();
    dom.append_child(root, p).unwrap();

    let sheet = Stylesheet::bare()
        .rule_unchecked(
            "p",
            TuiStyle::new()
                .display(Display::Block)
                .width(Size::Fixed(6)),
        )
        .rule_unchecked("span", TuiStyle::new().display(Display::Inline));
    dom.cascade(&sheet);
    dom.layout_dom(Rect::new(0, 0, 10, 5));

    // Byte 0 = 'h' at row 0 col 0.
    let (x0, y0) = cell_of_position(&dom, Position::new(t, 0)).unwrap();
    assert_eq!((x0, y0), (0, 0));
    // Byte 6 = 'w' at row 1 col 0 (after wrap).
    let (x6, y6) = cell_of_position(&dom, Position::new(t, 6)).unwrap();
    assert_eq!((x6, y6), (0, 1));
}

// ── paint_caret_if_editable (integration through paint pass) ───────

fn pipeline(dom: &mut TuiDom, sheet: &Stylesheet, viewport: Rect) -> Buffer {
    dom.cascade(sheet);
    dom.layout_dom(viewport);
    let mut buf = Buffer::empty(viewport);
    dom.paint_dom(&mut buf, viewport);
    buf
}

fn editable_sheet() -> Stylesheet {
    Stylesheet::bare()
        .rule_unchecked(
            "p",
            TuiStyle::new()
                .display(Display::Block)
                .width(Size::Fixed(20)),
        )
        .rule_unchecked("span", TuiStyle::new().display(Display::Inline))
}

#[test]
fn caret_paints_when_editable_is_focused_with_collapsed_selection() {
    let (mut dom, p, t) = editable_paragraph("hello");
    dom.set_focused(Some(p));
    dom.set_selection(Some(Selection::caret(Position::new(t, 3))));

    let buf = pipeline(&mut dom, &editable_sheet(), Rect::new(0, 0, 30, 5));

    // Cells 0-2 ("hel") aren't selected → plain (bg == Reset). Cell 3
    // ("l" index 3, byte 3 is after the first 'l' and on the second 'l')
    // has the caret painted → bg is the high-contrast white fallback
    // (no cascaded color on <p>, so Auto caret-color → white).
    // Cell 4 plain again.
    assert_ne!(
        buf.cell(3, 0).unwrap().bg,
        Color::Reset,
        "caret cell should have an explicit bg painted"
    );
    for x in [0u16, 1, 2, 4] {
        assert_eq!(
            buf.cell(x, 0).unwrap().bg,
            Color::Reset,
            "cell {x} should not have the caret bg painted"
        );
    }
}

#[test]
fn caret_does_not_paint_when_no_focus() {
    let (mut dom, _p, t) = editable_paragraph("hello");
    dom.set_selection(Some(Selection::caret(Position::new(t, 2))));
    // focused is None
    let buf = pipeline(&mut dom, &editable_sheet(), Rect::new(0, 0, 30, 5));
    for x in 0..5 {
        assert_eq!(buf.cell(x, 0).unwrap().bg, Color::Reset);
    }
}

#[test]
fn caret_does_not_paint_on_non_editable_even_with_selection() {
    // Same paragraph but WITHOUT contenteditable. Clicking in it
    // places a selection (runtime); but we shouldn't paint a caret
    // for a non-editable.
    let mut dom: TuiDom = TuiDom::new();
    let root = dom.root();
    let p = dom.create_element("p");
    let t = dom.create_text_node("hello");
    dom.append_child(p, t).unwrap();
    let span = dom.create_element("span");
    dom.append_child(p, span).unwrap();
    dom.append_child(root, p).unwrap();
    dom.set_focused(Some(p));
    dom.set_selection(Some(Selection::caret(Position::new(t, 2))));

    let buf = pipeline(&mut dom, &editable_sheet(), Rect::new(0, 0, 30, 5));
    for x in 0..5 {
        assert_eq!(buf.cell(x, 0).unwrap().bg, Color::Reset);
    }
}

#[test]
fn caret_does_not_paint_when_selection_is_a_range_not_a_caret() {
    // Non-collapsed selection paints the selection overlay, not a
    // caret. Verified indirectly: no standalone caret-style cell
    // outside the range (cells 0 and 4 keep bg == Reset; cells 1-3
    // get the UA `*::selection` bg, not the caret white fallback).
    let (mut dom, p, t) = editable_paragraph("hello");
    dom.set_focused(Some(p));
    dom.set_selection(Some(Selection::new(
        Position::new(t, 1),
        Position::new(t, 4),
    )));

    let buf = pipeline(&mut dom, &editable_sheet(), Rect::new(0, 0, 30, 5));
    // Cells 0 and 4 are outside the selection — no caret, no overlay.
    assert_eq!(buf.cell(0, 0).unwrap().bg, Color::Reset);
    assert_eq!(buf.cell(4, 0).unwrap().bg, Color::Reset);
}

// ── P6G-PSEUDO-SHIFT-1: the caret shares the packer's geometry ──────

/// A 10-wide editable pure-text block with `::before { content: "> " }`.
fn editable_with_before(text: &str) -> (TuiDom, rdom_core::NodeId, rdom_core::NodeId) {
    use crate::style::Content;
    let mut dom: TuiDom = TuiDom::new();
    let root = dom.root();
    let p = dom.create_element("p");
    dom.set_attribute(p, "contenteditable", "true").unwrap();
    let t = dom.create_text_node(text);
    dom.append_child(p, t).unwrap();
    dom.append_child(root, p).unwrap();
    let sheet = Stylesheet::bare()
        .rule_unchecked("p", TuiStyle::new().width(Size::Fixed(10)))
        .rule_unchecked(
            "p::before",
            TuiStyle::new().content(Content::Str("> ".into())),
        );
    dom.cascade(&sheet);
    dom.layout_dom(Rect::new(0, 0, 20, 5));
    (dom, p, t)
}

#[test]
fn caret_at_offset_zero_sits_after_the_before_pseudo() {
    let (dom, _p, t) = editable_with_before("abcdefg hi");
    assert_eq!(cell_of_position(&dom, Position::new(t, 0)), Some((2, 0)));
    // Past "abcdefg " the caret is on the wrapped line, at its start.
    assert_eq!(cell_of_position(&dom, Position::new(t, 8)), Some((0, 1)));
    assert_eq!(cell_of_position(&dom, Position::new(t, 10)), Some((2, 1)));
}

/// An empty editable has no text fragment: the caret sits at the start
/// of the block, before the `::before` — what browsers do for the
/// `[contenteditable]:empty::before` placeholder idiom.
#[test]
fn caret_in_empty_editable_sits_at_the_block_start() {
    let (dom, _p, t) = editable_with_before("");
    assert_eq!(cell_of_position(&dom, Position::new(t, 0)), Some((0, 0)));
}

/// A text control showing its placeholder (`:placeholder-shown::before`,
/// rdom's stand-in for `::placeholder`): the caret stays at the start of
/// the field, as browsers draw it.
#[test]
fn caret_in_empty_input_sits_at_the_start_of_its_placeholder() {
    let mut dom: TuiDom = TuiDom::new();
    let root = dom.root();
    let input = dom.create_element("input");
    dom.set_attribute(input, "placeholder", "Name").unwrap();
    let t = dom.create_text_node("");
    dom.append_child(input, t).unwrap();
    dom.append_child(root, input).unwrap();
    dom.cascade(&Stylesheet::new());
    dom.layout_dom(Rect::new(0, 0, 20, 5));
    let content = dom.node(input).content_layout_rect().unwrap();
    assert_eq!(
        cell_of_position(&dom, Position::new(t, 0)),
        Some((content.x as u16, content.y as u16))
    );
}

// ── P6G-INLINE-PSEUDO-1: the caret around an inline element's pseudos ─

/// `<p contenteditable>a <b>bold</b> c</p>` with `b::before { "[" }` /
/// `b::after { "]" }` paints "a [bold] c": the caret at the end of "a "
/// sits before the `[`, inside `<b>` after it.
#[test]
fn caret_around_an_inline_elements_pseudos_follows_the_packed_text() {
    use crate::style::Content;
    let mut dom: TuiDom = TuiDom::new();
    let root = dom.root();
    let p = dom.create_element("p");
    dom.set_attribute(p, "contenteditable", "true").unwrap();
    let a = dom.create_text_node("a ");
    let b = dom.create_element("b");
    let bold = dom.create_text_node("bold");
    let c = dom.create_text_node(" c");
    dom.append_child(b, bold).unwrap();
    dom.append_child(p, a).unwrap();
    dom.append_child(p, b).unwrap();
    dom.append_child(p, c).unwrap();
    dom.append_child(root, p).unwrap();
    let sheet = Stylesheet::new()
        .rule_unchecked(
            "b::before",
            TuiStyle::new().content(Content::Str("[".into())),
        )
        .rule_unchecked(
            "b::after",
            TuiStyle::new().content(Content::Str("]".into())),
        );
    dom.cascade(&sheet);
    dom.layout_dom(Rect::new(0, 0, 20, 2));
    assert_eq!(cell_of_position(&dom, Position::new(bold, 0)), Some((3, 0)));
    assert_eq!(cell_of_position(&dom, Position::new(bold, 4)), Some((7, 0)));
    assert_eq!(cell_of_position(&dom, Position::new(c, 1)), Some((9, 0)));
}

/// HTML §2.3.3: the `type` keyword is ASCII case-insensitive, and an
/// invalid value falls back to the Text state (`P7-FORM-ENUM-CASE-1`).
#[test]
fn input_type_keywords_are_ascii_case_insensitive() {
    for (ty, editable) in [
        ("Text", true),
        ("PASSWORD", true),
        ("eMail", true),
        ("bogus", true),
        ("CheckBox", false),
        ("SUBMIT", false),
        ("Hidden", false),
    ] {
        let mut dom: TuiDom = TuiDom::new();
        let root = dom.root();
        let el = dom.create_element("input");
        dom.set_attribute(el, "type", ty).unwrap();
        dom.append_child(root, el).unwrap();
        assert_eq!(dom.node(el).is_editable(), editable, "type={ty}");
    }
}