-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
vlist.rs
1348 lines (1235 loc) · 40.8 KB
/
vlist.rs
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
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//! This module contains fragments implementation.
use super::{Key, VDiff, VNode, VText};
use crate::html::{AnyScope, NodeRef};
use std::collections::HashMap;
use std::ops::{Deref, DerefMut};
use web_sys::Element;
/// This struct represents a fragment of the Virtual DOM tree.
#[derive(Clone, Debug, PartialEq)]
pub struct VList {
/// The list of child [VNode]s
children: Vec<VNode>,
/// All [VNode]s in the VList have keys
fully_keyed: bool,
pub key: Option<Key>,
}
impl Default for VList {
fn default() -> Self {
Self::new()
}
}
impl Deref for VList {
type Target = Vec<VNode>;
fn deref(&self) -> &Self::Target {
&self.children
}
}
impl DerefMut for VList {
fn deref_mut(&mut self) -> &mut Self::Target {
// Caller might change the keys of the VList or add unkeyed children.
// Defensively assume they will.
self.fully_keyed = false;
&mut self.children
}
}
/// Log an operation during tests for debugging purposes
/// Set RUSTFLAGS="--cfg verbose_tests" environment variable to activate.
macro_rules! test_log {
($fmt:literal, $($arg:expr),* $(,)?) => {
#[cfg(all(test, feature = "wasm_test", verbose_tests))]
::wasm_bindgen_test::console_log!(concat!("\t ", $fmt), $($arg),*);
};
}
struct ElementWriter<'s> {
parent_scope: &'s AnyScope,
parent: &'s Element,
next_sibling: NodeRef,
}
impl<'s> ElementWriter<'s> {
fn add(self, node: &mut VNode) -> Self {
test_log!("adding: {:?}", node);
self.write(node, None)
}
fn patch(self, node: &mut VNode, ancestor: VNode) -> Self {
test_log!("patching: {:?} -> {:?}", ancestor, node);
self.write(node, Some(ancestor))
}
fn write(self, node: &mut VNode, ancestor: Option<VNode>) -> Self {
test_log!("parent={:?}", self.parent.outer_html());
// Advance the next sibling reference (from right to left) and log it for testing purposes
// Set RUSTFLAGS="--cfg verbose_tests" environment variable to activate.
#[cfg(all(test, feature = "wasm_test", verbose_tests))]
let current = format!("{:?}", self.next_sibling);
let next = node.apply(self.parent_scope, self.parent, self.next_sibling, ancestor);
test_log!("advance next_sibling: {:?} -> {:?}", current, next);
Self {
next_sibling: next,
..self
}
}
}
impl VList {
/// Creates a new empty [VList] instance.
pub const fn new() -> Self {
Self {
children: Vec::new(),
key: None,
fully_keyed: true,
}
}
/// Creates a new [VList] instance with children.
pub fn with_children(children: Vec<VNode>, key: Option<Key>) -> Self {
VList {
fully_keyed: children.iter().all(|ch| ch.has_key()),
children,
key,
}
}
/// Add [VNode] child.
pub fn add_child(&mut self, child: VNode) {
if self.fully_keyed && !child.has_key() {
self.fully_keyed = false;
}
self.children.push(child);
}
/// Add multiple [VNode] children.
pub fn add_children(&mut self, children: impl IntoIterator<Item = VNode>) {
let it = children.into_iter();
let bound = it.size_hint();
self.children.reserve(bound.1.unwrap_or(bound.0));
for ch in it {
self.add_child(ch);
}
}
/// Recheck, if the all the children have keys.
///
/// Run this, after modifying the child list that contained only keyed children prior to the
/// mutable dereference.
pub fn recheck_fully_keyed(&mut self) {
self.fully_keyed = self.children.iter().all(|ch| ch.has_key());
}
/// Diff and patch unkeyed child lists
fn apply_unkeyed(
parent_scope: &AnyScope,
parent: &Element,
next_sibling: NodeRef,
lefts: &mut [VNode],
rights: Vec<VNode>,
) -> NodeRef {
let mut diff = lefts.len() as isize - rights.len() as isize;
let mut lefts_it = lefts.iter_mut().rev();
let mut rights_it = rights.into_iter().rev();
let mut writer = ElementWriter {
parent_scope,
parent,
next_sibling,
};
// Add missing nodes
while diff > 0 {
let l = lefts_it.next().unwrap();
writer = writer.add(l);
diff -= 1;
}
// Remove extra nodes
while diff < 0 {
let mut r = rights_it.next().unwrap();
test_log!("removing: {:?}", r);
r.detach(parent, false);
diff += 1;
}
for (l, r) in lefts_it.zip(rights_it) {
writer = writer.patch(l, r);
}
writer.next_sibling
}
/// Diff and patch fully keyed child lists.
///
/// Optimized for node addition or removal from either end of the list and small changes in the
/// middle.
fn apply_keyed(
parent_scope: &AnyScope,
parent: &Element,
next_sibling: NodeRef,
lefts: &mut [VNode],
rights: Vec<VNode>,
) -> NodeRef {
macro_rules! map_keys {
($src:expr) => {
$src.iter()
.map(|v| v.key().expect("unkeyed child in fully keyed list"))
.collect::<Vec<Key>>()
};
}
let lefts_keys = map_keys!(lefts);
let rights_keys = map_keys!(rights);
/// Find the first differing key in 2 iterators
fn matching_len<'a, 'b>(
a: impl Iterator<Item = &'a Key>,
b: impl Iterator<Item = &'b Key>,
) -> usize {
a.zip(b).take_while(|(a, b)| a == b).count()
}
// Find first key mismatch from the front
let from_start = matching_len(lefts_keys.iter(), rights_keys.iter());
if from_start == std::cmp::min(lefts.len(), rights.len()) {
// No key changes
return Self::apply_unkeyed(parent_scope, parent, next_sibling, lefts, rights);
}
let mut writer = ElementWriter {
parent_scope,
parent,
next_sibling,
};
// Find first key mismatch from the back
let from_end = matching_len(
lefts_keys[from_start..].iter().rev(),
rights_keys[from_start..].iter().rev(),
);
// We partially deconstruct the rights vector in several steps.
let mut rights = rights;
// Diff matching children at the end
let lefts_to = lefts_keys.len() - from_end;
let rights_to = rights_keys.len() - from_end;
for (l, r) in lefts[lefts_to..]
.iter_mut()
.zip(rights.drain(rights_to..))
.rev()
{
writer = writer.patch(l, r);
}
// Diff mismatched children in the middle
let mut next_right_key: Option<&Key> = None;
let mut rights_diff: HashMap<&Key, (VNode, Option<&Key>)> =
HashMap::with_capacity(rights_to - from_start);
for (k, v) in rights_keys[from_start..rights_to]
.iter()
.zip(rights.drain(from_start..)) // rights_to.. has been drained already
.rev()
{
let next_r_key = std::mem::replace(&mut next_right_key, Some(k));
rights_diff.insert(k, (v, next_r_key));
}
let mut next_left_key: Option<&Key> = None;
for (l_key, l) in lefts_keys[from_start..lefts_to]
.iter()
.zip(lefts[from_start..lefts_to].iter_mut())
.rev()
{
match rights_diff.remove(l_key) {
// Reorder and diff any existing children
Some((r, next_r_key)) => {
match (next_r_key, next_left_key) {
// If the next sibling was already the same, we don't need to move the node
(Some(r_next), Some(l_next)) if r_next == l_next => (),
_ => {
test_log!("moving as next: {:?}", r);
r.move_before(parent, &writer.next_sibling.get());
}
}
writer = writer.patch(l, r);
}
// Add new children
None => {
writer = writer.add(l);
}
}
next_left_key = Some(l_key);
}
// Remove any extra rights
for (_, (mut r, _)) in rights_diff.drain() {
test_log!("removing: {:?}", r);
r.detach(parent, false);
}
// Diff matching children at the start
for (l, r) in lefts[..from_start]
.iter_mut()
.zip(rights.into_iter()) // from_start.. has been drained already
.rev()
{
writer = writer.patch(l, r);
}
writer.next_sibling
}
}
#[cfg(feature = "ssr")]
mod feat_ssr {
use super::*;
impl VList {
pub(crate) async fn render_to_string(&self, w: &mut String, parent_scope: &AnyScope) {
// Concurrently render all children.
for fragment in futures::future::join_all(self.children.iter().map(|m| async move {
let mut w = String::new();
m.render_to_string(&mut w, parent_scope).await;
w
}))
.await
{
w.push_str(&fragment)
}
}
}
}
impl VDiff for VList {
fn detach(&mut self, parent: &Element, parent_to_detach: bool) {
for mut child in self.children.drain(..) {
child.detach(parent, parent_to_detach);
}
}
fn shift(&self, previous_parent: &Element, next_parent: &Element, next_sibling: NodeRef) {
let mut last_node_ref = next_sibling;
for node in self.children.iter().rev() {
node.shift(previous_parent, next_parent, last_node_ref);
last_node_ref = NodeRef::default();
last_node_ref.set(node.first_node());
}
}
fn apply(
&mut self,
parent_scope: &AnyScope,
parent: &Element,
next_sibling: NodeRef,
ancestor: Option<VNode>,
) -> NodeRef {
// Here, we will try to diff the previous list elements with the new
// ones we want to insert. For that, we will use two lists:
// - lefts: new elements to render in the DOM
// - rights: previously rendered elements.
//
// The left items are known since we want to insert them
// (self.children). For the right ones, we will look at the ancestor,
// i.e. the current DOM list element that we want to replace with self.
if self.children.is_empty() {
// Without a placeholder the next element becomes first
// and corrupts the order of rendering
// We use empty text element to stake out a place
self.add_child(VText::new("").into());
}
let lefts = &mut self.children;
let (rights, rights_fully_keyed) = match ancestor {
// If the ancestor is also a VList, then the "right" list is the previously
// rendered items.
Some(VNode::VList(v)) => (v.children, v.fully_keyed),
// If the ancestor was not a VList, then the "right" list is a single node
Some(v) => {
let has_key = v.has_key();
(vec![v], has_key)
}
// No unkeyed nodes in an empty VList
_ => (vec![], true),
};
test_log!("lefts: {:?}", lefts);
test_log!("rights: {:?}", rights);
#[allow(clippy::let_and_return)]
let first = if self.fully_keyed && rights_fully_keyed {
Self::apply_keyed(parent_scope, parent, next_sibling, lefts, rights)
} else {
Self::apply_unkeyed(parent_scope, parent, next_sibling, lefts, rights)
};
test_log!("result: {:?}", lefts);
first
}
}
#[cfg(test)]
mod layout_tests {
extern crate self as yew;
use crate::html;
use crate::tests::layout_tests::{diff_layouts, TestLayout};
#[cfg(feature = "wasm_test")]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};
#[cfg(feature = "wasm_test")]
wasm_bindgen_test_configure!(run_in_browser);
#[test]
fn diff() {
let layout1 = TestLayout {
name: "1",
node: html! {
<>
{"a"}
{"b"}
<>
{"c"}
{"d"}
</>
{"e"}
</>
},
expected: "abcde",
};
let layout2 = TestLayout {
name: "2",
node: html! {
<>
{"a"}
{"b"}
<></>
{"e"}
{"f"}
</>
},
expected: "abef",
};
let layout3 = TestLayout {
name: "3",
node: html! {
<>
{"a"}
<></>
{"b"}
{"e"}
</>
},
expected: "abe",
};
let layout4 = TestLayout {
name: "4",
node: html! {
<>
{"a"}
<>
{"c"}
{"d"}
</>
{"b"}
{"e"}
</>
},
expected: "acdbe",
};
diff_layouts(vec![layout1, layout2, layout3, layout4]);
}
}
#[cfg(test)]
mod layout_tests_keys {
extern crate self as yew;
use crate::html;
use crate::tests::layout_tests::{diff_layouts, TestLayout};
use crate::virtual_dom::VNode;
use crate::{Children, Component, Context, Html, Properties};
use web_sys::Node;
#[cfg(feature = "wasm_test")]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};
#[cfg(feature = "wasm_test")]
wasm_bindgen_test_configure!(run_in_browser);
struct Comp {}
#[derive(Properties, Clone, PartialEq)]
struct CountingCompProps {
id: usize,
#[prop_or(false)]
can_change: bool,
}
impl Component for Comp {
type Message = ();
type Properties = CountingCompProps;
fn create(_: &Context<Self>) -> Self {
Comp {}
}
fn update(&mut self, _ctx: &Context<Self>, _: Self::Message) -> bool {
unimplemented!();
}
fn view(&self, ctx: &Context<Self>) -> Html {
html! { <p>{ ctx.props().id }</p> }
}
}
#[derive(Clone, Properties, PartialEq)]
pub struct ListProps {
pub children: Children,
}
pub struct List();
impl Component for List {
type Message = ();
type Properties = ListProps;
fn create(_: &Context<Self>) -> Self {
Self()
}
fn update(&mut self, _ctx: &Context<Self>, _: Self::Message) -> bool {
unimplemented!();
}
fn view(&self, ctx: &Context<Self>) -> Html {
html! { <>{ for ctx.props().children.iter() }</> }
}
}
#[test]
fn diff() {
let mut layouts = vec![];
let vref_node: Node = gloo_utils::document().create_element("i").unwrap().into();
layouts.push(TestLayout {
name: "All VNode types as children",
node: html! {
<>
{"a"}
<span key="vtag"></span>
{"c"}
{"d"}
<Comp id=0 key="vchild" />
<key="vlist">
{"foo"}
{"bar"}
</>
{VNode::VRef(vref_node)}
</>
},
expected: "a<span></span>cd<p>0</p>foobar<i></i>",
});
layouts.extend(vec![
TestLayout {
name: "Inserting into VList first child - before",
node: html! {
<>
<key="VList">
<i key="i"></i>
</>
<p key="p"></p>
</>
},
expected: "<i></i><p></p>",
},
TestLayout {
name: "Inserting into VList first child - after",
node: html! {
<>
<key="VList">
<i key="i"></i>
<e key="e"></e>
</>
<p key="p"></p>
</>
},
expected: "<i></i><e></e><p></p>",
},
]);
layouts.extend(vec![
TestLayout {
name: "No matches - before",
node: html! {
<>
<i key="i"></i>
<e key="e"></e>
</>
},
expected: "<i></i><e></e>",
},
TestLayout {
name: "No matches - after",
node: html! {
<>
<a key="a"></a>
<p key="p"></p>
</>
},
expected: "<a></a><p></p>",
},
]);
layouts.extend(vec![
TestLayout {
name: "Append - before",
node: html! {
<>
<i key="i"></i>
<e key="e"></e>
</>
},
expected: "<i></i><e></e>",
},
TestLayout {
name: "Append - after",
node: html! {
<>
<i key="i"></i>
<e key="e"></e>
<p key="p"></p>
</>
},
expected: "<i></i><e></e><p></p>",
},
]);
layouts.extend(vec![
TestLayout {
name: "Prepend - before",
node: html! {
<>
<i key="i"></i>
<e key="e"></e>
</>
},
expected: "<i></i><e></e>",
},
TestLayout {
name: "Prepend - after",
node: html! {
<>
<p key="p"></p>
<i key="i"></i>
<e key="e"></e>
</>
},
expected: "<p></p><i></i><e></e>",
},
]);
layouts.extend(vec![
TestLayout {
name: "Delete first - before",
node: html! {
<>
<i key="i"></i>
<e key="e"></e>
<p key="p"></p>
</>
},
expected: "<i></i><e></e><p></p>",
},
TestLayout {
name: "Delete first - after",
node: html! {
<>
<e key="e"></e>
<p key="p"></p>
</>
},
expected: "<e></e><p></p>",
},
]);
layouts.extend(vec![
TestLayout {
name: "Delete last - before",
node: html! {
<>
<i key="i"></i>
<e key="e"></e>
<p key="p"></p>
</>
},
expected: "<i></i><e></e><p></p>",
},
TestLayout {
name: "Delete last - after",
node: html! {
<>
<i key="i"></i>
<e key="e"></e>
</>
},
expected: "<i></i><e></e>",
},
]);
layouts.extend(vec![
TestLayout {
name: "Delete last and change node type - before",
node: html! {
<>
<i key="i"></i>
<e key="e"></e>
<p key="p"></p>
</>
},
expected: "<i></i><e></e><p></p>",
},
TestLayout {
name: "Delete last - after",
node: html! {
<>
<List key="i"><i/></List>
<List key="e"><e/></List>
<List key="a"><a/></List>
</>
},
expected: "<i></i><e></e><a></a>",
},
]);
layouts.extend(vec![
TestLayout {
name: "Delete middle - before",
node: html! {
<>
<i key="i"></i>
<e key="e"></e>
<p key="p"></p>
<a key="a"></a>
</>
},
expected: "<i></i><e></e><p></p><a></a>",
},
TestLayout {
name: "Delete middle - after",
node: html! {
<>
<i key="i"></i>
<e key="e2"></e>
<p key="p2"></p>
<a key="a"></a>
</>
},
expected: "<i></i><e></e><p></p><a></a>",
},
]);
layouts.extend(vec![
TestLayout {
name: "Delete middle and change node type - before",
node: html! {
<>
<i key="i"></i>
<e key="e"></e>
<p key="p"></p>
<a key="a"></a>
</>
},
expected: "<i></i><e></e><p></p><a></a>",
},
TestLayout {
name: "Delete middle and change node type- after",
node: html! {
<>
<List key="i2"><i/></List>
<e key="e"></e>
<List key="p"><p/></List>
<List key="a2"><a/></List>
</>
},
expected: "<i></i><e></e><p></p><a></a>",
},
]);
layouts.extend(vec![
TestLayout {
name: "Reverse - before",
node: html! {
<>
<i key="i"></i>
<e key="e"></e>
<p key="p"></p>
<u key="u"></u>
</>
},
expected: "<i></i><e></e><p></p><u></u>",
},
TestLayout {
name: "Reverse - after",
node: html! {
<>
<u key="u"></u>
<p key="p"></p>
<e key="e"></e>
<i key="i"></i>
</>
},
expected: "<u></u><p></p><e></e><i></i>",
},
]);
layouts.extend(vec![
TestLayout {
name: "Reverse and change node type - before",
node: html! {
<>
<i key="i"></i>
<key="i1"></>
<key="i2"></>
<key="i3"></>
<e key="e"></e>
<key="yo">
<p key="p"></p>
</>
<u key="u"></u>
</>
},
expected: "<i></i><e></e><p></p><u></u>",
},
TestLayout {
name: "Reverse and change node type - after",
node: html! {
<>
<List key="u"><u/></List>
<List key="p"><p/></List>
<List key="e"><e/></List>
<List key="i"><i/></List>
</>
},
expected: "<u></u><p></p><e></e><i></i>",
},
]);
layouts.extend(vec![
TestLayout {
name: "Swap 1&2 - before",
node: html! {
<>
<i key="1"></i>
<e key="2"></e>
<p key="3"></p>
<a key="4"></a>
<u key="5"></u>
</>
},
expected: "<i></i><e></e><p></p><a></a><u></u>",
},
TestLayout {
name: "Swap 1&2 - after",
node: html! {
<>
<e key="2"></e>
<i key="1"></i>
<p key="3"></p>
<a key="4"></a>
<u key="5"></u>
</>
},
expected: "<e></e><i></i><p></p><a></a><u></u>",
},
]);
layouts.extend(vec![
TestLayout {
name: "Swap 1&2 and change node type - before",
node: html! {
<>
<i key="1"></i>
<e key="2"></e>
<p key="3"></p>
<a key="4"></a>
<u key="5"></u>
</>
},
expected: "<i></i><e></e><p></p><a></a><u></u>",
},
TestLayout {
name: "Swap 1&2 and change node type - after",
node: html! {
<>
<List key="2"><e/></List>
<List key="1"><i/></List>
<List key="3"><p/></List>
<List key="4"><a/></List>
<List key="5"><u/></List>
</>
},
expected: "<e></e><i></i><p></p><a></a><u></u>",
},
]);
layouts.extend(vec![
TestLayout {
name: "test - before",
node: html! {
<>
<key="1">
<e key="e"></e>
<p key="p"></p>
<a key="a"></a>
<u key="u"></u>
</>
<key="2">
<e key="e"></e>
<p key="p"></p>
<a key="a"></a>
<u key="u"></u>
</>
</>
},
expected: "<e></e><p></p><a></a><u></u><e></e><p></p><a></a><u></u>",
},
TestLayout {
name: "Swap 4&5 - after",
node: html! {
<>
<e key="1"></e>
<key="2">
<p key="p"></p>
<i key="i"></i>
</>
</>
},
expected: "<e></e><p></p><i></i>",
},
]);
layouts.extend(vec![
TestLayout {
name: "Swap 4&5 - before",
node: html! {
<>
<i key="1"></i>
<e key="2"></e>
<p key="3"></p>
<a key="4"></a>
<u key="5"></u>
</>
},
expected: "<i></i><e></e><p></p><a></a><u></u>",
},
TestLayout {
name: "Swap 4&5 - after",
node: html! {
<>
<i key="1"></i>
<e key="2"></e>
<p key="3"></p>
<u key="5"></u>
<a key="4"></a>
</>
},
expected: "<i></i><e></e><p></p><u></u><a></a>",
},
]);
layouts.extend(vec![
TestLayout {
name: "Swap 1&5 - before",
node: html! {
<>
<i key="1"></i>
<e key="2"></e>
<p key="3"></p>
<a key="4"></a>
<u key="5"></u>
</>
},
expected: "<i></i><e></e><p></p><a></a><u></u>",
},
TestLayout {
name: "Swap 1&5 - after",
node: html! {
<>
<u key="5"></u>
<e key="2"></e>
<p key="3"></p>
<a key="4"></a>
<i key="1"></i>
</>
},
expected: "<u></u><e></e><p></p><a></a><i></i>",
},
]);
layouts.extend(vec![
TestLayout {
name: "Move 2 after 4 - before",
node: html! {
<>
<i key="1"></i>
<e key="2"></e>
<p key="3"></p>
<a key="4"></a>
<u key="5"></u>
</>
},
expected: "<i></i><e></e><p></p><a></a><u></u>",
},
TestLayout {
name: "Move 2 after 4 - after",
node: html! {
<>