1
use proptest::{prelude::*, proptest};
2

            
3
#[allow(unused_imports)]
4
pub use super::*;
5
#[cfg(test)]
6
mod assign_tests {
7
    use alloc::vec::Vec;
8

            
9
    use azul_css::{props::basic::length::FloatValue, AzString, OptionF32, OptionString};
10
    use proptest::{prelude::*, proptest};
11

            
12
    use super::*;
13
    use crate::{dom::OptionDomNodeId, geom::LogicalPosition, window::OptionVirtualKeyCodeCombo};
14

            
15
    /// Partial updates must leave unset fields intact.
16
    #[test]
17
1
    fn assign_takes_only_what_the_patch_sets() {
18
1
        let mut widget = AccessibilityInfo {
19
1
            role: AccessibilityRole::Slider,
20
1
            accessibility_value: OptionString::Some("42".into()),
21
1
            states: AccessibilityStateVec::from_vec(vec![AccessibilityState::Focusable]),
22
1
            ..Default::default()
23
1
        };
24

            
25
1
        widget.assign(AccessibilityInfo {
26
1
            accessibility_name: OptionString::Some("Volume".into()),
27
1
            ..Default::default()
28
1
        });
29

            
30
1
        assert_eq!(
31
1
            widget.accessibility_name.as_ref().map(|s| s.as_str()),
32
            Some("Volume")
33
        );
34
1
        assert!(
35
1
            matches!(widget.role, AccessibilityRole::Slider),
36
            "an unset role in the patch (Unknown) must not clobber a real one"
37
        );
38
1
        assert_eq!(
39
1
            widget.accessibility_value.as_ref().map(|s| s.as_str()),
40
            Some("42"),
41
            "the live value must survive an app setting the name"
42
        );
43
1
        assert_eq!(widget.states.as_ref().len(), 1, "states must survive too");
44
1
    }
45

            
46
    /// Partial updates overwrite existing fields.
47
    #[test]
48
1
    fn assign_overrides_a_field_the_patch_does_set() {
49
1
        let mut base = AccessibilityInfo::named("Old", AccessibilityRole::PushButton);
50
1
        base.assign(AccessibilityInfo {
51
1
            accessibility_name: OptionString::Some("New".into()),
52
1
            role: AccessibilityRole::CheckButton,
53
1
            ..Default::default()
54
1
        });
55
1
        assert_eq!(
56
1
            base.accessibility_name.as_ref().map(|s| s.as_str()),
57
            Some("New")
58
        );
59
1
        assert!(matches!(base.role, AccessibilityRole::CheckButton));
60
1
    }
61

            
62
    /// `is_live_region: false` in a partial struct does not clear an existing `true` flag.
63
    #[test]
64
1
    fn assign_never_clears_a_live_region_flag() {
65
1
        let mut base = AccessibilityInfo {
66
1
            is_live_region: true,
67
1
            ..Default::default()
68
1
        };
69
1
        base.assign(AccessibilityInfo::default());
70
1
        assert!(
71
1
            base.is_live_region,
72
            "a default-constructed patch must not turn a live region off"
73
        );
74
1
    }
75
}
76

            
77
#[cfg(test)]
78
mod autotest_generated {
79
    use alloc::{string::String, vec::Vec};
80

            
81
    use azul_css::{props::basic::length::FloatValue, AzString, OptionF32, OptionString};
82
    use proptest::{prelude::*, proptest};
83

            
84
    use super::*;
85
    use crate::{dom::OptionDomNodeId, geom::LogicalPosition, window::OptionVirtualKeyCodeCombo};
86

            
87
    fn name_str(o: &OptionString) -> Option<&str> {
88
        o.as_ref().map(|s| s.as_str())
89
    }
90

            
91
    fn f32_of(o: &OptionF32) -> Option<f32> {
92
        o.as_ref().copied()
93
    }
94

            
95
    /// Adversarial strings for FFI boundary testing.
96

            
97
    /// f32 edge cases.
98

            
99
    // SmallAriaInfo::label — no_panic_smoke
100

            
101
    proptest! {
102
        #[test]
103
        fn small_label_no_panic_smoke(s in any::<String>()) {
104
        let expected = s.clone();
105
        let info = SmallAriaInfo::label(s);
106

            
107
        assert_eq!(name_str(&info.label), Some(expected.as_str()));
108
        assert!(info.role.is_none());
109
        assert!(info.description.is_none());
110

            
111
        let full = info.to_full_info();
112
        assert_eq!(name_str(&full.accessibility_name), Some(expected.as_str()));
113

            
114
        let info = SmallAriaInfo::label("hello");
115
        assert_eq!(name_str(&info.label), Some("hello"));
116
        }
117
    }
118

            
119
    // SmallAriaInfo::with_role — no_panic + invariants
120

            
121
    fn representative_roles() -> Vec<AccessibilityRole> {
122
        vec![
123
            AccessibilityRole::TitleBar, // first variant
124
            AccessibilityRole::PushButton,
125
            AccessibilityRole::CheckButton,
126
            AccessibilityRole::Slider,
127
            AccessibilityRole::Link,
128
            AccessibilityRole::Nothing,
129
            AccessibilityRole::Unknown, // last variant
130
        ]
131
    }
132

            
133
    #[test]
134
    fn small_with_role_invariants() {
135
        for role in representative_roles() {
136
            let info = SmallAriaInfo::label("base").with_role(role);
137

            
138
            assert_eq!(info.role, OptionAccessibilityRole::Some(role));
139
            assert_eq!(name_str(&info.label), Some("base"));
140
            assert!(info.description.is_none());
141
        }
142

            
143
        let info = SmallAriaInfo::label("x")
144
            .with_role(AccessibilityRole::Link)
145
            .with_role(AccessibilityRole::Slider);
146
        assert_eq!(
147
            info.role,
148
            OptionAccessibilityRole::Some(AccessibilityRole::Slider)
149
        );
150
    }
151

            
152
    // SmallAriaInfo::with_description — no_panic + invariants
153

            
154
    proptest! {
155
        #[test]
156
        fn small_with_description_invariants(s in any::<String>()) {
157
        let expected = s.clone();
158
        let info = SmallAriaInfo::label("base").with_description(s);
159
        assert_eq!(name_str(&info.description), Some(expected.as_str()));
160

            
161
        assert_eq!(name_str(&info.label), Some("base"));
162
        assert!(info.role.is_none());
163
        }
164
    }
165

            
166
    //  SmallAriaInfo::to_full_info — basic + edge
167

            
168
    #[test]
169
    fn small_to_full_info_basic() {
170
        let info = SmallAriaInfo::label("Submit")
171
            .with_role(AccessibilityRole::PushButton)
172
            .with_description("primary action")
173
            .to_full_info();
174
        assert_eq!(name_str(&info.accessibility_name), Some("Submit"));
175
        assert_eq!(info.role, AccessibilityRole::PushButton);
176
        assert_eq!(name_str(&info.description), Some("primary action"));
177
        assert!(info.accessibility_value.is_none());
178
        assert_eq!(info.states.len(), 0);
179
        assert_eq!(info.supported_actions.len(), 0);
180
        assert!(!info.is_live_region);
181
        assert!(info.labelled_by.is_none());
182
        assert!(info.described_by.is_none());
183
    }
184

            
185
    #[test]
186
    fn small_to_full_info_edge_missing_role_maps_to_unknown() {
187
        let info = SmallAriaInfo::label("").to_full_info();
188
        assert_eq!(info.role, AccessibilityRole::Unknown);
189
        assert_eq!(name_str(&info.accessibility_name), Some(""));
190
        assert!(info.description.is_none());
191
    }
192

            
193
    // ProgressAriaInfo::create — no_panic_smoke
194

            
195
    proptest! {
196
        #[test]
197
        fn progress_create_no_panic_smoke(s in any::<String>()) {
198
        let expected = s.clone();
199
        let p = ProgressAriaInfo::create(s.into());
200
        assert_eq!(name_str(&p.label), Some(expected.as_str()));
201

            
202
        assert!(p.current_value.is_none());
203
        assert!(p.max.is_none());
204
        assert!(!p.indeterminate);
205
        assert!(p.description.is_none());
206
        }
207
    }
208

            
209
    // ProgressAriaInfo::with_current_value — no_panic + invariants (numeric)
210

            
211
    proptest! {
212
        #[test]
213
        fn progress_with_current_value_numeric(v in proptest::num::f32::ANY) {
214
        let p = ProgressAriaInfo::create("p".into()).with_current_value(v);
215
        match f32_of(&p.current_value) {
216
            Some(got) if v.is_nan() => assert!(got.is_nan()),
217
            Some(got) => assert_eq!(got, v),
218
            None => panic!("current_value should be Some after with_current_value"),
219
        }
220

            
221
        let full = p.to_full_info();
222
        assert!(full.accessibility_value.is_some());
223
        }
224
    }
225

            
226
    // ProgressAriaInfo::with_max — no_panic + invariants (numeric)
227

            
228
    proptest! {
229
        #[test]
230
        fn progress_with_max_numeric(v in proptest::num::f32::ANY) {
231
        let p = ProgressAriaInfo::create("p".into()).with_max(v);
232
        match f32_of(&p.max) {
233
            Some(got) if v.is_nan() => assert!(got.is_nan()),
234
            Some(got) => assert_eq!(got, v),
235
            None => panic!("max should be Some after with_max"),
236
        }
237

            
238
        assert!(p.current_value.is_none());
239
        }
240
    }
241

            
242
    // ProgressAriaInfo::with_indeterminate — no_panic + invariants
243

            
244
    #[test]
245
    fn progress_with_indeterminate_invariants() {
246
        for flag in [true, false] {
247
            let p = ProgressAriaInfo::create("p".into()).with_indeterminate(flag);
248
            assert_eq!(p.indeterminate, flag);
249
        }
250

            
251
        let p = ProgressAriaInfo::create("p".into())
252
            .with_current_value(0.5)
253
            .with_indeterminate(true);
254
        assert!(p.to_full_info().accessibility_value.is_none());
255
    }
256

            
257
    // ProgressAriaInfo::with_description — no_panic + invariants
258

            
259
    proptest! {
260
        #[test]
261
        fn progress_with_description_invariants(s in any::<String>()) {
262
        let expected = s.clone();
263
        let p = ProgressAriaInfo::create("p".into()).with_description(s.into());
264
        assert_eq!(name_str(&p.description), Some(expected.as_str()));
265
        assert_eq!(name_str(&p.label), Some("p"));
266
        }
267
    }
268

            
269
    // ProgressAriaInfo::to_full_info — basic + edge
270

            
271
    #[test]
272
    fn progress_to_full_info_basic() {
273
        let info = ProgressAriaInfo::create("Loading".into())
274
            .with_current_value(0.5)
275
            .to_full_info();
276
        assert_eq!(name_str(&info.accessibility_name), Some("Loading"));
277
        assert_eq!(info.role, AccessibilityRole::ProgressBar);
278
        assert_eq!(name_str(&info.accessibility_value), Some("0.5"));
279
        assert_eq!(info.states.len(), 0);
280
        assert_eq!(info.supported_actions.len(), 0);
281
    }
282

            
283
    #[test]
284
    fn progress_to_full_info_edge() {
285
        let info = ProgressAriaInfo::create("x".into()).to_full_info();
286
        assert!(info.accessibility_value.is_none());
287
        assert_eq!(info.role, AccessibilityRole::ProgressBar);
288

            
289
        assert_eq!(
290
            name_str(
291
                &ProgressAriaInfo::create("x".into())
292
                    .with_current_value(f32::NAN)
293
                    .to_full_info()
294
                    .accessibility_value
295
            ),
296
            Some("NaN")
297
        );
298
        assert_eq!(
299
            name_str(
300
                &ProgressAriaInfo::create("x".into())
301
                    .with_current_value(f32::INFINITY)
302
                    .to_full_info()
303
                    .accessibility_value
304
            ),
305
            Some("inf")
306
        );
307
        assert_eq!(
308
            name_str(
309
                &ProgressAriaInfo::create("x".into())
310
                    .with_current_value(f32::NEG_INFINITY)
311
                    .to_full_info()
312
                    .accessibility_value
313
            ),
314
            Some("-inf")
315
        );
316
    }
317

            
318
    // MeterAriaInfo::create — numeric (zero / min_max / negative / nan_inf)
319

            
320
    #[test]
321
    fn meter_create_zero() {
322
        let m = MeterAriaInfo::create("z".into(), 0.0, 0.0, 0.0);
323
        assert_eq!(m.current_value, 0.0);
324
        assert_eq!(m.min, 0.0);
325
        assert_eq!(m.max, 0.0);
326
        assert_eq!(name_str(&m.to_full_info().accessibility_value), Some("0"));
327
    }
328

            
329
    #[test]
330
    fn meter_create_min_max() {
331
        let m = MeterAriaInfo::create("mm".into(), f32::MAX, f32::MIN, f32::MAX);
332
        assert_eq!(m.current_value, f32::MAX);
333
        assert_eq!(m.min, f32::MIN);
334
        assert_eq!(m.max, f32::MAX);
335

            
336
        assert!(m.to_full_info().accessibility_value.is_some());
337
    }
338

            
339
    #[test]
340
    fn meter_create_negative() {
341
        let m = MeterAriaInfo::create("neg".into(), -5.0, -10.0, -1.0);
342
        assert_eq!(m.current_value, -5.0);
343
        assert_eq!(m.min, -10.0);
344
        assert_eq!(m.max, -1.0);
345
        assert_eq!(name_str(&m.to_full_info().accessibility_value), Some("-5"));
346

            
347
        let inv = MeterAriaInfo::create("inv".into(), 5.0, 100.0, 0.0);
348
        assert_eq!(inv.min, 100.0);
349
        assert_eq!(inv.max, 0.0);
350
        assert!(inv.to_full_info().accessibility_value.is_some());
351
    }
352

            
353
    #[test]
354
    fn meter_create_overflow_saturates_to_inf() {
355
        let over = f32::MAX * 2.0; // == +inf
356
        assert!(over.is_infinite());
357
        let m = MeterAriaInfo::create("o".into(), over, -over, over);
358
        assert_eq!(name_str(&m.to_full_info().accessibility_value), Some("inf"));
359
    }
360

            
361
    #[test]
362
    fn meter_create_nan_inf() {
363
        let m = MeterAriaInfo::create("n".into(), f32::NAN, 0.0, 1.0);
364
        assert!(m.current_value.is_nan());
365
        assert_eq!(name_str(&m.to_full_info().accessibility_value), Some("NaN"));
366

            
367
        let pos = MeterAriaInfo::create("n".into(), f32::INFINITY, 0.0, 1.0);
368
        assert_eq!(
369
            name_str(&pos.to_full_info().accessibility_value),
370
            Some("inf")
371
        );
372

            
373
        let neg = MeterAriaInfo::create("n".into(), f32::NEG_INFINITY, 0.0, 1.0);
374
        assert_eq!(
375
            name_str(&neg.to_full_info().accessibility_value),
376
            Some("-inf")
377
        );
378

            
379
        let bounds = MeterAriaInfo::create("n".into(), 0.5, f32::NEG_INFINITY, f32::INFINITY);
380
        assert!(bounds.min.is_infinite());
381
        assert!(bounds.max.is_infinite());
382
        assert!(bounds.to_full_info().accessibility_value.is_some());
383
    }
384

            
385
    // MeterAriaInfo::with_low / with_high / with_optimum — numeric invariants
386

            
387
    proptest! {
388
        #[test]
389
        fn meter_with_low_high_optimum_numeric(v in proptest::num::f32::ANY) {
390
        let m = MeterAriaInfo::create("m".into(), 0.5, 0.0, 1.0)
391
            .with_low(v)
392
            .with_high(v)
393
            .with_optimum(v);
394
        for opt in [&m.low, &m.high, &m.optimum] {
395
            match f32_of(opt) {
396
                Some(got) if v.is_nan() => assert!(got.is_nan()),
397
                Some(got) => assert_eq!(got, v),
398
                None => panic!("threshold should be Some after builder"),
399
            }
400
        }
401

            
402
        assert_eq!(m.current_value, 0.5);
403
        assert_eq!(m.min, 0.0);
404
        assert_eq!(m.max, 1.0);
405
        }
406
    }
407

            
408
    // MeterAriaInfo::with_description — no_panic + invariants
409

            
410
    proptest! {
411
        #[test]
412
        fn meter_with_description_invariants(s in any::<String>()) {
413
        let expected = s.clone();
414
        let m = MeterAriaInfo::create("m".into(), 1.0, 0.0, 2.0).with_description(s.into());
415
        assert_eq!(name_str(&m.description), Some(expected.as_str()));
416
        assert_eq!(m.current_value, 1.0);
417
        }
418
    }
419

            
420
    // MeterAriaInfo::to_full_info — basic + edge
421

            
422
    #[test]
423
    fn meter_to_full_info_basic() {
424
        let info = MeterAriaInfo::create("Disk".into(), 42.0, 0.0, 100.0)
425
            .with_description("usage".into())
426
            .to_full_info();
427
        assert_eq!(name_str(&info.accessibility_name), Some("Disk"));
428
        assert_eq!(info.role, AccessibilityRole::Indicator);
429
        assert_eq!(name_str(&info.accessibility_value), Some("42"));
430
        assert_eq!(name_str(&info.description), Some("usage"));
431
        assert_eq!(info.states.len(), 0);
432
        assert_eq!(info.supported_actions.len(), 0);
433
    }
434

            
435
    #[test]
436
    fn meter_to_full_info_edge() {
437
        let info = MeterAriaInfo::create("".into(), f32::MIN, f32::MIN, f32::MAX).to_full_info();
438
        assert!(info.accessibility_value.is_some());
439
        assert_eq!(info.role, AccessibilityRole::Indicator);
440
        assert_eq!(name_str(&info.accessibility_name), Some(""));
441
    }
442

            
443
    // DialogAriaInfo::create — no_panic_smoke
444

            
445
    proptest! {
446
        #[test]
447
        fn dialog_create_no_panic_smoke(s in any::<String>()) {
448
        let expected = s.clone();
449
        let d = DialogAriaInfo::create(s.into());
450
        assert_eq!(name_str(&d.label), Some(expected.as_str()));
451

            
452
        assert!(!d.modal);
453
        assert_eq!(d.role, AccessibilityRole::Dialog);
454
        assert!(d.described_by.is_none());
455
        assert!(d.description.is_none());
456
        }
457
    }
458

            
459
    // DialogAriaInfo::with_modal — no_panic + invariants
460

            
461
    #[test]
462
    fn dialog_with_modal_invariants() {
463
        for flag in [true, false] {
464
            let d = DialogAriaInfo::create("t".into()).with_modal(flag);
465
            assert_eq!(d.modal, flag);
466

            
467
            assert_eq!(d.role, AccessibilityRole::Dialog);
468
            assert_eq!(name_str(&d.label), Some("t"));
469
        }
470
    }
471

            
472
    // DialogAriaInfo::with_described_by — no_panic + invariants
473

            
474
    proptest! {
475
        #[test]
476
        fn dialog_with_described_by_invariants(s in any::<String>()) {
477
        let expected = s.clone();
478
        let d = DialogAriaInfo::create("t".into()).with_described_by(s.into());
479
        assert_eq!(name_str(&d.described_by), Some(expected.as_str()));
480
        assert_eq!(name_str(&d.label), Some("t"));
481
        }
482
    }
483

            
484
    // DialogAriaInfo::with_role — no_panic + invariants
485

            
486
    #[test]
487
    fn dialog_with_role_invariants() {
488
        for role in representative_roles() {
489
            let d = DialogAriaInfo::create("t".into()).with_role(role);
490
            assert_eq!(d.role, role);
491
            assert!(!d.modal);
492
        }
493

            
494
        let info = DialogAriaInfo::create("t".into())
495
            .with_role(AccessibilityRole::Alert)
496
            .to_full_info();
497
        assert_eq!(info.role, AccessibilityRole::Alert);
498
    }
499

            
500
    // DialogAriaInfo::with_description — no_panic + invariants
501

            
502
    proptest! {
503
        #[test]
504
        fn dialog_with_description_invariants(s in any::<String>()) {
505
        let expected = s.clone();
506
        let d = DialogAriaInfo::create("t".into()).with_description(s.into());
507
        assert_eq!(name_str(&d.description), Some(expected.as_str()));
508
        assert_eq!(name_str(&d.label), Some("t"));
509
        }
510
    }
511

            
512
    // DialogAriaInfo::to_full_info — basic + edge
513

            
514
    #[test]
515
    fn dialog_to_full_info_basic() {
516
        let info = DialogAriaInfo::create("Confirm".into())
517
            .with_modal(true)
518
            .with_role(AccessibilityRole::Alert)
519
            .with_described_by("body-node".into())
520
            .with_description("Are you sure?".into())
521
            .to_full_info();
522
        assert_eq!(name_str(&info.accessibility_name), Some("Confirm"));
523
        assert_eq!(info.role, AccessibilityRole::Alert);
524
        assert_eq!(name_str(&info.description), Some("Are you sure?"));
525

            
526
        assert!(info.described_by.is_none());
527
        assert!(info.labelled_by.is_none());
528
        assert!(info.accessibility_value.is_none());
529
        assert_eq!(info.states.len(), 0);
530
        assert_eq!(info.supported_actions.len(), 0);
531
    }
532

            
533
    #[test]
534
    fn dialog_to_full_info_edge() {
535
        let info = DialogAriaInfo::create("".into()).to_full_info();
536
        assert_eq!(info.role, AccessibilityRole::Dialog);
537
        assert_eq!(name_str(&info.accessibility_name), Some(""));
538
        assert!(info.description.is_none());
539
    }
540

            
541
    use core::hash::{Hash, Hasher};
542

            
543
    use crate::{
544
        dom::{DomId, DomNodeId},
545
        styled_dom::NodeHierarchyItemId,
546
    };
547

            
548
    /// FNV-1a for no_std testing.
549
    struct Fnv(u64);
550

            
551
    impl Default for Fnv {
552
        fn default() -> Self {
553
            Self(0xcbf2_9ce4_8422_2325) // offset basis
554
        }
555
    }
556

            
557
    impl Hasher for Fnv {
558
        fn finish(&self) -> u64 {
559
            self.0
560
        }
561
        fn write(&mut self, bytes: &[u8]) {
562
            for b in bytes {
563
                self.0 ^= u64::from(*b);
564
                self.0 = self.0.wrapping_mul(0x0000_0100_0000_01b3); // FNV prime
565
            }
566
        }
567
    }
568

            
569
    fn hash_of<T: Hash>(t: &T) -> u64 {
570
        let mut h = Fnv::default();
571
        t.hash(&mut h);
572
        h.finish()
573
    }
574

            
575
    /// Every `AccessibilityRole`, in declaration order.
576
    fn all_roles() -> Vec<AccessibilityRole> {
577
        use AccessibilityRole::*;
578
        vec![
579
            TitleBar,
580
            MenuBar,
581
            ScrollBar,
582
            Grip,
583
            Sound,
584
            Cursor,
585
            Caret,
586
            Alert,
587
            Window,
588
            Client,
589
            MenuPopup,
590
            MenuItem,
591
            Tooltip,
592
            Application,
593
            Document,
594
            Pane,
595
            Chart,
596
            Dialog,
597
            Border,
598
            Grouping,
599
            Separator,
600
            Toolbar,
601
            StatusBar,
602
            Table,
603
            ColumnHeader,
604
            RowHeader,
605
            Column,
606
            Row,
607
            Cell,
608
            Link,
609
            HelpBalloon,
610
            Character,
611
            List,
612
            ListItem,
613
            Outline,
614
            OutlineItem,
615
            PageTab,
616
            PropertyPage,
617
            Indicator,
618
            Graphic,
619
            StaticText,
620
            Text,
621
            PushButton,
622
            CheckButton,
623
            RadioButton,
624
            ComboBox,
625
            DropList,
626
            ProgressBar,
627
            Dial,
628
            HotkeyField,
629
            Slider,
630
            SpinButton,
631
            Diagram,
632
            Animation,
633
            Equation,
634
            ButtonDropdown,
635
            ButtonMenu,
636
            ButtonDropdownGrid,
637
            Whitespace,
638
            PageTabList,
639
            Clock,
640
            SplitButton,
641
            IpAddress,
642
            Nothing,
643
            Unknown,
644
        ]
645
    }
646

            
647
    /// Every `AccessibilityState`, in declaration order.
648
    fn all_states() -> Vec<AccessibilityState> {
649
        use AccessibilityState::*;
650
        vec![
651
            Unavailable,
652
            Selected,
653
            Focused,
654
            CheckedTrue,
655
            CheckedFalse,
656
            Readonly,
657
            Default,
658
            Expanded,
659
            Collapsed,
660
            Busy,
661
            Offscreen,
662
            Focusable,
663
            Selectable,
664
            Linked,
665
            Traversed,
666
            Multiselectable,
667
            Protected,
668
        ]
669
    }
670

            
671
    /// Ensures `all_roles()` and `all_states()` are exhaustive.
672
    #[test]
673
    fn role_exhaustiveness_canary() {
674
        use AccessibilityRole::*;
675
        for r in all_roles() {
676
            let known = match r {
677
                TitleBar | MenuBar | ScrollBar | Grip | Sound | Cursor | Caret | Alert | Window
678
                | Client | MenuPopup | MenuItem | Tooltip | Application | Document | Pane
679
                | Chart | Dialog | Border | Grouping | Separator | Toolbar | StatusBar | Table
680
                | ColumnHeader | RowHeader | Column | Row | Cell | Link | HelpBalloon
681
                | Character | List | ListItem | Outline | OutlineItem | PageTab | PropertyPage
682
                | Indicator | Graphic | StaticText | Text | PushButton | CheckButton
683
                | RadioButton | ComboBox | DropList | ProgressBar | Dial | HotkeyField | Slider
684
                | SpinButton | Diagram | Animation | Equation | ButtonDropdown | ButtonMenu
685
                | ButtonDropdownGrid | Whitespace | PageTabList | Clock | SplitButton
686
                | IpAddress | Nothing | Unknown => true,
687
            };
688
            assert!(known);
689
        }
690

            
691
        use AccessibilityState::*;
692
        for s in all_states() {
693
            let known = match s {
694
                Unavailable | Selected | Focused | CheckedTrue | CheckedFalse | Readonly
695
                | Default | Expanded | Collapsed | Busy | Offscreen | Focusable | Selectable
696
                | Linked | Traversed | Multiselectable | Protected => true,
697
            };
698
            assert!(known);
699
        }
700
    }
701

            
702
    // Total-order / Eq / Hash contracts on the plain C-like enums
703

            
704
    #[test]
705
    fn role_ord_is_strict_declaration_order() {
706
        let roles = all_roles();
707

            
708
        for pair in roles.windows(2) {
709
            assert!(
710
                pair[0] < pair[1],
711
                "roles must sort in declaration order: {:?} !< {:?}",
712
                pair[0],
713
                pair[1]
714
            );
715
        }
716

            
717
        for a in &roles {
718
            for b in &roles {
719
                let lt = a < b;
720
                let eq = a == b;
721
                let gt = a > b;
722
                assert_eq!(
723
                    u8::from(lt) + u8::from(eq) + u8::from(gt),
724
                    1,
725
                    "trichotomy violated for {a:?} vs {b:?}"
726
                );
727
            }
728
        }
729

            
730
        assert_eq!(roles[0], AccessibilityRole::TitleBar);
731
        assert_eq!(*roles.last().unwrap(), AccessibilityRole::Unknown);
732
        assert!(AccessibilityRole::TitleBar < AccessibilityRole::Unknown);
733
    }
734

            
735
    #[test]
736
    fn state_ord_is_strict_declaration_order() {
737
        let states = all_states();
738
        for pair in states.windows(2) {
739
            assert!(pair[0] < pair[1], "{:?} !< {:?}", pair[0], pair[1]);
740
        }
741

            
742
        assert_ne!(
743
            AccessibilityState::CheckedTrue,
744
            AccessibilityState::CheckedFalse
745
        );
746
        assert_ne!(
747
            hash_of(&AccessibilityState::CheckedTrue),
748
            hash_of(&AccessibilityState::CheckedFalse)
749
        );
750
    }
751

            
752
    #[test]
753
    fn role_and_state_hash_agrees_with_eq() {
754
        for r in all_roles() {
755
            let copy = r;
756
            assert_eq!(hash_of(&r), hash_of(&copy));
757
        }
758
        for s in all_states() {
759
            let copy = s;
760
            assert_eq!(hash_of(&s), hash_of(&copy));
761
        }
762

            
763
        let role_hashes: Vec<u64> = all_roles().iter().map(hash_of).collect();
764
        for (i, a) in role_hashes.iter().enumerate() {
765
            for (j, b) in role_hashes.iter().enumerate() {
766
                assert_eq!(i == j, a == b, "role hash collision at {i}/{j}");
767
            }
768
        }
769

            
770
        let state_hashes: Vec<u64> = all_states().iter().map(hash_of).collect();
771
        for (i, a) in state_hashes.iter().enumerate() {
772
            for (j, b) in state_hashes.iter().enumerate() {
773
                assert_eq!(i == j, a == b, "state hash collision at {i}/{j}");
774
            }
775
        }
776
    }
777

            
778
    // AccessibilityStateVec — FFI vec round-trip
779

            
780
    #[test]
781
    fn state_vec_round_trips_through_ffi_wrapper() {
782
        let cases: Vec<Vec<AccessibilityState>> = vec![
783
            Vec::new(),
784
            vec![AccessibilityState::Focused],
785
            all_states(),
786
            vec![
787
                AccessibilityState::Busy,
788
                AccessibilityState::Busy,
789
                AccessibilityState::Busy,
790
            ],
791
            std::iter::repeat_n(AccessibilityState::Selected, 10_000).collect(),
792
        ];
793

            
794
        for original in cases {
795
            let wrapped: AccessibilityStateVec = original.clone().into();
796

            
797
            assert_eq!(wrapped.len(), original.len());
798
            assert_eq!(wrapped.is_empty(), original.is_empty());
799
            assert_eq!(wrapped.as_slice(), original.as_slice());
800
            assert_eq!(wrapped.iter().count(), original.len());
801

            
802
            let cloned = wrapped.clone();
803
            assert_eq!(cloned.as_slice(), original.as_slice());
804
            assert_eq!(cloned, wrapped);
805
            assert_eq!(hash_of(&cloned), hash_of(&wrapped));
806
            drop(cloned);
807
            assert_eq!(wrapped.as_slice(), original.as_slice());
808

            
809
            let back = wrapped.into_library_owned_vec();
810
            assert_eq!(back, original);
811
        }
812
    }
813

            
814
    #[test]
815
    fn state_vec_indexing_is_bounds_safe() {
816
        let v: AccessibilityStateVec = all_states().into();
817
        let len = v.len();
818

            
819
        for (i, expected) in all_states().into_iter().enumerate() {
820
            assert_eq!(v.get(i), Some(&expected));
821
        }
822

            
823
        assert_eq!(v.get(len), None);
824
        assert_eq!(v.get(len + 1), None);
825
        assert_eq!(v.get(usize::MAX), None);
826
        assert!(v.c_get(usize::MAX).is_none());
827
        assert!(v.c_get(len).is_none());
828
        assert!(v.c_get(0).is_some());
829

            
830
        let empty = AccessibilityStateVec::new();
831
        assert!(empty.is_empty());
832
        assert_eq!(empty.get(0), None);
833
        assert_eq!(empty.get(usize::MAX), None);
834
        assert!(empty.c_get(0).is_none());
835
    }
836

            
837
    #[test]
838
    fn state_vec_from_vec_preserves_order_len_and_lookup() {
839
        let empty = AccessibilityStateVec::new();
840
        assert_eq!(empty.len(), 0);
841
        assert!(empty.is_empty());
842
        assert_eq!(empty.get(0), None);
843

            
844
        let states = all_states();
845
        let v = AccessibilityStateVec::from_vec(states.clone());
846
        assert_eq!(v.len(), states.len());
847
        assert!(!v.is_empty());
848
        assert!(v.capacity() >= v.len(), "capacity must never trail len");
849

            
850
        assert_eq!(v.as_slice(), states.as_slice());
851
        for (i, s) in states.iter().enumerate() {
852
            assert_eq!(v.get(i), Some(s));
853
        }
854
        assert_eq!(
855
            v.get(states.len()),
856
            None,
857
            "out-of-bounds must be None, not a panic"
858
        );
859
        assert!(v.iter().eq(states.iter()));
860
    }
861

            
862
    // AccessibilityAction — payload-carrying variants
863

            
864
    fn all_actions() -> Vec<AccessibilityAction> {
865
        use AccessibilityAction::*;
866
        vec![
867
            Default,
868
            Focus,
869
            Blur,
870
            Collapse,
871
            Expand,
872
            ScrollIntoView,
873
            Increment,
874
            Decrement,
875
            ShowContextMenu,
876
            HideTooltip,
877
            ShowTooltip,
878
            ScrollUp,
879
            ScrollDown,
880
            ScrollLeft,
881
            ScrollRight,
882
            ReplaceSelectedText("replacement".into()),
883
            ScrollToPoint(LogicalPosition::new(1.0, 2.0)),
884
            SetScrollOffset(LogicalPosition::new(-3.0, 4.0)),
885
            SetTextSelection(TextSelectionStartEnd {
886
                selection_start: 0,
887
                selection_end: 5,
888
            }),
889
            SetSequentialFocusNavigationStartingPoint,
890
            SetValue("value".into()),
891
            SetNumericValue(FloatValue::new(1.5)),
892
            CustomAction(42),
893
        ]
894
    }
895

            
896
    #[test]
897
    fn action_vec_round_trips_with_payloads() {
898
        let original = all_actions();
899
        let wrapped: AccessibilityActionVec = original.clone().into();
900

            
901
        assert_eq!(wrapped.len(), original.len());
902
        assert_eq!(wrapped.as_slice(), original.as_slice());
903

            
904
        let cloned = wrapped.clone();
905
        assert_eq!(cloned, wrapped);
906
        assert_eq!(hash_of(&cloned), hash_of(&wrapped));
907
        drop(cloned);
908
        assert_eq!(wrapped.as_slice(), original.as_slice());
909

            
910
        let back = wrapped.into_library_owned_vec();
911
        assert_eq!(back, original);
912

            
913
        for pair in original.windows(2) {
914
            assert!(pair[0] < pair[1], "{:?} !< {:?}", pair[0], pair[1]);
915
        }
916
    }
917

            
918
    proptest! {
919
        #[test]
920
        fn action_string_payloads_survive_adversarial_strings(s in any::<String>()) {
921
        let expected = s.clone();
922

            
923
        let replace = AccessibilityAction::ReplaceSelectedText(s.clone().into());
924
        let set = AccessibilityAction::SetValue(s.into());
925

            
926
        match &replace {
927
            AccessibilityAction::ReplaceSelectedText(got) => {
928
                assert_eq!(got.as_str(), expected.as_str());
929
                assert_eq!(got.as_str().len(), expected.len());
930
            }
931
            other => panic!("wrong variant: {other:?}"),
932
        }
933
        match &set {
934
            AccessibilityAction::SetValue(got) => assert_eq!(got.as_str(), expected.as_str()),
935
            other => panic!("wrong variant: {other:?}"),
936
        }
937

            
938
        assert_eq!(replace.clone(), replace);
939
        assert_eq!(hash_of(&replace.clone()), hash_of(&replace));
940

            
941
        assert_ne!(replace, set);
942
        }
943
    }
944

            
945
    #[test]
946
    fn action_custom_action_i32_limits() {
947
        let min = AccessibilityAction::CustomAction(i32::MIN);
948
        let zero = AccessibilityAction::CustomAction(0);
949
        let max = AccessibilityAction::CustomAction(i32::MAX);
950

            
951
        assert!(min < zero, "i32::MIN must sort below 0");
952
        assert!(zero < max);
953
        assert!(min < max);
954

            
955
        assert_eq!(min, AccessibilityAction::CustomAction(i32::MIN));
956
        assert_ne!(min, max);
957
        assert_eq!(
958
            hash_of(&min),
959
            hash_of(&AccessibilityAction::CustomAction(i32::MIN))
960
        );
961

            
962
        assert_ne!(
963
            AccessibilityAction::CustomAction(-1),
964
            AccessibilityAction::CustomAction(i32::MAX)
965
        );
966
    }
967

            
968
    #[test]
969
    fn text_selection_start_end_limits() {
970
        let huge = TextSelectionStartEnd {
971
            selection_start: usize::MAX,
972
            selection_end: usize::MAX,
973
        };
974
        assert_eq!(huge.selection_start, usize::MAX);
975
        assert_eq!(huge.selection_end, usize::MAX);
976
        assert_eq!(huge, huge);
977

            
978
        let inverted = TextSelectionStartEnd {
979
            selection_start: 10,
980
            selection_end: 0,
981
        };
982
        assert_eq!(inverted.selection_start, 10);
983
        assert_eq!(inverted.selection_end, 0);
984
        assert_ne!(
985
            inverted,
986
            TextSelectionStartEnd {
987
                selection_start: 0,
988
                selection_end: 10,
989
            }
990
        );
991

            
992
        let collapsed = TextSelectionStartEnd {
993
            selection_start: 7,
994
            selection_end: 7,
995
        };
996
        assert_ne!(
997
            collapsed,
998
            TextSelectionStartEnd {
999
                selection_start: 0,
                selection_end: 0,
            }
        );
        let a = TextSelectionStartEnd {
            selection_start: 1,
            selection_end: 99,
        };
        let b = TextSelectionStartEnd {
            selection_start: 2,
            selection_end: 0,
        };
        assert!(a < b, "selection_start must dominate the ordering");
        let action = AccessibilityAction::SetTextSelection(huge);
        assert_eq!(action.clone(), action);
        assert_eq!(hash_of(&action.clone()), hash_of(&action));
    }
    // f32-carrying payloads: the Eq/Ord/Hash total-order contract
    //
    // `AccessibilityAction` *derives* Eq + Ord + Hash while carrying
    // `LogicalPosition` (two f32s) and `FloatValue`. f32 is not Eq/Ord, so
    // those inner types must supply total impls. These tests pin the actual
    // behaviour at NaN / inf / overflow, where a naive impl breaks the
    // reflexivity (a == a) that HashMap and BTreeMap rely on.
    #[test]
    fn scroll_to_point_nan_is_reflexive_and_totally_ordered() {
        let nan = AccessibilityAction::ScrollToPoint(LogicalPosition::new(f32::NAN, f32::NAN));
        let origin = AccessibilityAction::ScrollToPoint(LogicalPosition::new(0.0, 0.0));
        assert_eq!(nan, nan.clone());
        assert_eq!(hash_of(&nan), hash_of(&nan.clone()));
        assert_eq!(nan.cmp(&nan.clone()), core::cmp::Ordering::Equal);
        assert_ne!(nan, origin);
        assert_ne!(hash_of(&nan), hash_of(&origin));
        assert!(nan < origin, "NaN sorts below every real coordinate");
        let neg = AccessibilityAction::ScrollToPoint(LogicalPosition::new(-1.0, -1.0));
        let pos = AccessibilityAction::ScrollToPoint(LogicalPosition::new(1.0, 1.0));
        let mut sorted = vec![pos.clone(), origin.clone(), nan.clone(), neg.clone()];
        sorted.sort();
        assert_eq!(sorted, vec![nan, neg, origin, pos]);
    }
    #[test]
    fn scroll_to_point_infinite_coords_saturate_without_panic() {
        let inf = AccessibilityAction::SetScrollOffset(LogicalPosition::new(
            f32::INFINITY,
            f32::NEG_INFINITY,
        ));
        let finite = AccessibilityAction::SetScrollOffset(LogicalPosition::new(1.0, 1.0));
        assert_eq!(inf, inf.clone());
        assert_eq!(hash_of(&inf), hash_of(&inf.clone()));
        assert!(
            inf > finite,
            "+inf x-coordinate must sort above a finite one"
        );
        let max = AccessibilityAction::SetScrollOffset(LogicalPosition::new(f32::MAX, f32::MAX));
        let plus_inf = AccessibilityAction::SetScrollOffset(LogicalPosition::new(
            f32::INFINITY,
            f32::INFINITY,
        ));
        assert_eq!(
            max, plus_inf,
            "f32::MAX and +inf both saturate to the same quantised coordinate"
        );
    }
    #[test]
    fn set_numeric_value_float_edges_are_defined() {
        for v in [0.0_f32, 1.5, -1.5, 2.25, -3.75, 1000.0] {
            let f = FloatValue::new(v);
            assert_eq!(f.get(), v, "FloatValue must round-trip {v}");
            let action = AccessibilityAction::SetNumericValue(f);
            assert_eq!(action.clone(), action);
        }
        assert_eq!(FloatValue::new(f32::INFINITY).number(), isize::MAX);
        assert_eq!(FloatValue::new(f32::NEG_INFINITY).number(), isize::MIN);
        // Known bug: FloatValue::new maps NaN to 0.
        assert_eq!(FloatValue::new(f32::NAN).number(), 0);
        assert_eq!(
            AccessibilityAction::SetNumericValue(FloatValue::new(f32::NAN)),
            AccessibilityAction::SetNumericValue(FloatValue::new(0.0)),
            "KNOWN ALIASING: NaN numeric value collides with 0.0"
        );
        let nan_action = AccessibilityAction::SetNumericValue(FloatValue::new(f32::NAN));
        assert_eq!(hash_of(&nan_action), hash_of(&nan_action.clone()));
        assert_eq!(FloatValue::new(f32::MAX).number(), isize::MAX);
        assert_eq!(FloatValue::new(f32::MIN).number(), isize::MIN);
    }
    // Float -> value-string encoding: format/parse round-trip
    proptest! {
        #[test]
        fn progress_value_string_round_trips_through_parse(v in proptest::num::f32::ANY) {
        let full = ProgressAriaInfo::create("p".into())
            .with_current_value(v)
            .to_full_info();
        let s = name_str(&full.accessibility_value).expect("determinate => Some");
        if v.is_nan() {
            assert_eq!(s, "NaN");
            assert!(s.parse::<f32>().unwrap().is_nan());
        } else if v.is_infinite() {
            assert_eq!(s, if v > 0.0 { "inf" } else { "-inf" });
        } else {
            let parsed: f32 = s.parse().expect("emitted value string must re-parse");
            assert_eq!(parsed, v, "round-trip failed for {v} via {s:?}");
            if v != 0.0 {
                assert_eq!(parsed.to_bits(), v.to_bits(), "lossy round-trip for {v}");
            }
        }
        }
    }
    proptest! {
        #[test]
        fn meter_value_string_round_trips_through_parse(v in proptest::num::f32::ANY) {
        let full = MeterAriaInfo::create("m".into(), v, 0.0, 1.0).to_full_info();
        let s = name_str(&full.accessibility_value).expect("meter always emits a value");
        if v.is_nan() {
            assert_eq!(s, "NaN");
        } else if v.is_infinite() {
            assert_eq!(s, if v > 0.0 { "inf" } else { "-inf" });
        } else {
            let parsed: f32 = s.parse().expect("emitted value string must re-parse");
            assert_eq!(parsed, v);
            if v != 0.0 {
                assert_eq!(parsed.to_bits(), v.to_bits());
            }
        }
        }
    }
    // Builder algebra: purity, idempotence, last-write-wins, order-independence
    #[test]
    fn to_full_info_is_pure_and_idempotent() {
        let small = SmallAriaInfo::label("s")
            .with_role(AccessibilityRole::Slider)
            .with_description("d");
        let progress = ProgressAriaInfo::create("p".into())
            .with_current_value(0.25)
            .with_max(10.0);
        let meter = MeterAriaInfo::create("m".into(), 1.0, 0.0, 2.0).with_low(0.5);
        let dialog = DialogAriaInfo::create("d".into()).with_modal(true);
        let (s0, p0, m0, d0) = (
            small.clone(),
            progress.clone(),
            meter.clone(),
            dialog.clone(),
        );
        assert_eq!(small.to_full_info(), small.to_full_info());
        assert_eq!(progress.to_full_info(), progress.to_full_info());
        assert_eq!(meter.to_full_info(), meter.to_full_info());
        assert_eq!(dialog.to_full_info(), dialog.to_full_info());
        assert_eq!(small, s0, "to_full_info must not mutate SmallAriaInfo");
        assert_eq!(
            progress, p0,
            "to_full_info must not mutate ProgressAriaInfo"
        );
        assert_eq!(meter, m0, "to_full_info must not mutate MeterAriaInfo");
        assert_eq!(dialog, d0, "to_full_info must not mutate DialogAriaInfo");
        let nan_meter = MeterAriaInfo::create("m".into(), f32::NAN, 0.0, 1.0);
        assert_eq!(nan_meter.to_full_info(), nan_meter.to_full_info());
    }
    proptest! {
        #[test]
        fn progress_max_is_never_surfaced_in_full_info(v in proptest::num::f32::ANY) {
        let baseline = ProgressAriaInfo::create("p".into())
            .with_current_value(0.5)
            .to_full_info();
        let with_max = ProgressAriaInfo::create("p".into())
            .with_current_value(0.5)
            .with_max(v)
            .to_full_info();
        assert_eq!(with_max, baseline, "with_max({v}) leaked into to_full_info");
        }
    }
    #[test]
    fn meter_threshold_builders_are_order_independent_and_last_write_wins() {
        let a = MeterAriaInfo::create("m".into(), 0.5, 0.0, 1.0)
            .with_low(0.1)
            .with_high(0.9)
            .with_optimum(0.7);
        let b = MeterAriaInfo::create("m".into(), 0.5, 0.0, 1.0)
            .with_optimum(0.7)
            .with_high(0.9)
            .with_low(0.1);
        assert_eq!(a, b);
        let m = MeterAriaInfo::create("m".into(), 0.5, 0.0, 1.0)
            .with_low(0.1)
            .with_low(f32::INFINITY);
        assert_eq!(f32_of(&m.low), Some(f32::INFINITY));
        let weird = MeterAriaInfo::create("m".into(), 5.0, 0.0, 1.0)
            .with_low(100.0)
            .with_high(-100.0)
            .with_optimum(-1.0);
        assert_eq!(f32_of(&weird.low), Some(100.0));
        assert_eq!(f32_of(&weird.high), Some(-100.0));
        assert_eq!(f32_of(&weird.optimum), Some(-1.0));
        assert_eq!(weird.current_value, 5.0); // out of [min,max], not clamped
        assert!(weird.to_full_info().accessibility_value.is_some());
    }
    #[test]
    fn progress_and_dialog_builders_last_write_wins() {
        let p = ProgressAriaInfo::create("p".into())
            .with_current_value(1.0)
            .with_current_value(2.0)
            .with_indeterminate(true)
            .with_indeterminate(false)
            .with_description("a".into())
            .with_description("b".into());
        assert_eq!(f32_of(&p.current_value), Some(2.0));
        assert!(!p.indeterminate);
        assert_eq!(name_str(&p.description), Some("b"));
        assert_eq!(name_str(&p.to_full_info().accessibility_value), Some("2"));
        let d = DialogAriaInfo::create("d".into())
            .with_modal(true)
            .with_modal(false)
            .with_role(AccessibilityRole::Alert)
            .with_role(AccessibilityRole::Dialog)
            .with_described_by("x".into())
            .with_described_by("y".into());
        assert!(!d.modal);
        assert_eq!(d.role, AccessibilityRole::Dialog);
        assert_eq!(name_str(&d.described_by), Some("y"));
    }
    // AccessibilityInfo — the fully-populated aggregate
    fn full_info_fixture() -> AccessibilityInfo {
        AccessibilityInfo {
            accessibility_name: OptionString::Some("name".into()),
            accessibility_value: OptionString::Some("value".into()),
            description: OptionString::Some("desc".into()),
            accelerator: OptionVirtualKeyCodeCombo::None,
            default_action: OptionString::Some("activate".into()),
            states: all_states().into(),
            supported_actions: all_actions().into(),
            labelled_by: OptionDomNodeId::Some(DomNodeId::ROOT),
            described_by: OptionDomNodeId::Some(DomNodeId {
                dom: DomId { inner: 3 },
                node: NodeHierarchyItemId::from_raw(7),
            }),
            role: AccessibilityRole::PushButton,
            is_live_region: true,
        }
    }
    #[test]
    fn full_info_clone_eq_hash_ord_are_consistent() {
        let a = full_info_fixture();
        let b = a.clone();
        assert_eq!(a, b);
        assert_eq!(hash_of(&a), hash_of(&b));
        assert_eq!(a.cmp(&b), core::cmp::Ordering::Equal);
        drop(b);
        assert_eq!(a.states.len(), all_states().len());
        assert_eq!(a.supported_actions.len(), all_actions().len());
        assert_eq!(name_str(&a.accessibility_name), Some("name"));
        let mut differs = a.clone();
        differs.is_live_region = false;
        assert_ne!(a, differs);
        let mut differs = a.clone();
        differs.role = AccessibilityRole::Unknown;
        assert_ne!(a, differs);
        let mut differs = a.clone();
        differs.labelled_by = OptionDomNodeId::None;
        assert_ne!(a, differs);
        let mut differs = a.clone();
        differs.states = Vec::new().into();
        assert_ne!(a, differs);
        let mut differs = a.clone();
        differs.supported_actions = Vec::new().into();
        assert_ne!(a, differs);
        let mut differs = a.clone();
        differs.default_action = OptionString::None;
        assert_ne!(a, differs);
    }
    // Option<T> FFI wrappers — Some/None round-trip
    #[test]
    fn option_wrappers_round_trip() {
        for r in all_roles() {
            let opt = OptionAccessibilityRole::Some(r);
            assert!(opt.is_some());
            assert!(!opt.is_none());
            assert_eq!(opt.as_ref(), Some(&r));
            assert_eq!(opt.into_option(), Some(r));
        }
        assert!(OptionAccessibilityRole::None.is_none());
        assert_eq!(OptionAccessibilityRole::None.into_option(), None);
        for s in all_states() {
            assert_eq!(OptionAccessibilityState::Some(s).into_option(), Some(s));
        }
        assert_eq!(OptionAccessibilityState::None.into_option(), None);
        for a in all_actions() {
            let opt = OptionAccessibilityAction::Some(a.clone());
            assert!(opt.is_some());
            assert_eq!(opt.into_option(), Some(a));
        }
        assert!(OptionAccessibilityAction::None.is_none());
        let small = SmallAriaInfo::label("s").with_role(AccessibilityRole::Link);
        assert_eq!(
            OptionSmallAriaInfo::Some(small.clone()).into_option(),
            Some(small)
        );
        assert!(OptionSmallAriaInfo::None.is_none());
        let progress = ProgressAriaInfo::create("p".into()).with_current_value(0.5);
        assert_eq!(
            OptionProgressAriaInfo::Some(progress.clone()).into_option(),
            Some(progress)
        );
        let meter = MeterAriaInfo::create("m".into(), 1.0, 0.0, 2.0);
        assert_eq!(
            OptionMeterAriaInfo::Some(meter.clone()).into_option(),
            Some(meter)
        );
        let dialog = DialogAriaInfo::create("d".into()).with_modal(true);
        assert_eq!(
            OptionDialogAriaInfo::Some(dialog.clone()).into_option(),
            Some(dialog)
        );
        let info = full_info_fixture();
        assert_eq!(
            OptionAccessibilityInfo::Some(info.clone()).into_option(),
            Some(info)
        );
        assert!(OptionAccessibilityInfo::None.is_none());
    }
}