aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeon Henrik Plickat <leonhenrik.plickat@stud.uni-goettingen.de>2020-10-26 20:40:40 +0100
committerIsaac Freund <ifreund@ifreund.xyz>2020-10-26 22:58:09 +0100
commit5407325400f2136556d7f74096a54efc1573b277 (patch)
treefec1c54a821c21d4259a6a566c60afb01bb4b4cd
parent0c7b0de297f913806a9335907a0f4b74eefdb591 (diff)
downloadriver-5407325400f2136556d7f74096a54efc1573b277.tar.gz
river-5407325400f2136556d7f74096a54efc1573b277.tar.xz
Add tests for ViewStack.swap()
-rw-r--r--river/view_stack.zig41
1 files changed, 41 insertions, 0 deletions
diff --git a/river/view_stack.zig b/river/view_stack.zig
index 80c3e4a..2bf695e 100644
--- a/river/view_stack.zig
+++ b/river/view_stack.zig
@@ -442,4 +442,45 @@ test "iteration (View)" {
testing.expect(it.next() == &five_b.view);
testing.expect(it.next() == null);
}
+
+ // Swap, then iterate
+ {
+ var view_a = views.first orelse unreachable;
+ var view_b = view_a.next orelse unreachable;
+ ViewStack(View).swap(&views, view_a, view_b); // {2, 5, 4, 1, 3} -> {5, 2, 4, 1, 3}
+
+ view_a = views.last orelse unreachable;
+ view_b = view_a.prev orelse unreachable;
+ ViewStack(View).swap(&views, view_a, view_b); // {5, 2, 4, 1, 3} -> {5, 2, 4, 3, 1}
+
+ view_a = views.last orelse unreachable;
+ view_b = views.first orelse unreachable;
+ ViewStack(View).swap(&views, view_a, view_b); // {5, 2, 4, 3, 1} -> {1, 2, 4, 3, 5}
+
+ view_a = views.first orelse unreachable;
+ view_b = views.last orelse unreachable;
+ ViewStack(View).swap(&views, view_a, view_b); // {1, 2, 4, 3, 5} -> {5, 2, 4, 3, 1}
+
+ view_a = views.first orelse unreachable;
+ view_a = view_a.next orelse unreachable;
+ view_b = view_a.next orelse unreachable;
+ view_b = view_b.next orelse unreachable;
+ ViewStack(View).swap(&views, view_a, view_b); // {5, 2, 4, 3, 1} -> {5, 3, 4, 2, 1}
+
+ var it = ViewStack(View).iter(views.first, .forward, {}, filters.all);
+ testing.expect(it.next() == &five_b.view);
+ testing.expect(it.next() == &three_b_pa.view);
+ testing.expect(it.next() == &four_b.view);
+ testing.expect(it.next() == &two_a.view);
+ testing.expect(it.next() == &one_a_pb.view);
+ testing.expect(it.next() == null);
+
+ it = ViewStack(View).iter(views.last, .reverse, {}, filters.all);
+ testing.expect(it.next() == &one_a_pb.view);
+ testing.expect(it.next() == &two_a.view);
+ testing.expect(it.next() == &four_b.view);
+ testing.expect(it.next() == &three_b_pa.view);
+ testing.expect(it.next() == &five_b.view);
+ testing.expect(it.next() == null);
+ }
}