]> git.sur5r.net Git - i3/i3/blob - testcases/t/24-move.t
testcases: remove 'use v5.10' as this is automatically done in lib/i3test
[i3/i3] / testcases / t / 24-move.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Tests moving. Basically, there are four different code-paths:
5 # 1) move a container which cannot be moved (single container on a workspace)
6 # 2) move a container before another single container
7 # 3) move a container inside another container
8 # 4) move a container in a different direction so that we need to go up in tree
9 #
10 use i3test tests => 16;
11 use X11::XCB qw(:all);
12
13 my $i3 = i3("/tmp/nestedcons");
14
15 my $tmp = get_unused_workspace();
16 $i3->command("workspace $tmp")->recv;
17
18 ######################################################################
19 # 1) move a container which cannot be moved
20 ######################################################################
21
22 $i3->command('open')->recv;
23
24 my $old_content = get_ws_content($tmp);
25 is(@{$old_content}, 1, 'one container on this workspace');
26
27 my $first = $old_content->[0]->{id};
28
29 $i3->command('move before h')->recv;
30 $i3->command('move before v')->recv;
31 $i3->command('move after v')->recv;
32 $i3->command('move after h')->recv;
33
34 my $content = get_ws_content($tmp);
35 is_deeply($old_content, $content, 'workspace unmodified after useless moves');
36
37 ######################################################################
38 # 2) move a container before another single container
39 ######################################################################
40
41 $i3->command('open')->recv;
42 $content = get_ws_content($tmp);
43 is(@{$content}, 2, 'two containers on this workspace');
44 my $second = $content->[1]->{id};
45
46 is($content->[0]->{id}, $first, 'first container unmodified');
47
48 # Move the second container before the first one (→ swap them)
49 $i3->command('move before h')->recv;
50 $content = get_ws_content($tmp);
51 is($content->[0]->{id}, $second, 'first container modified');
52
53 # We should not be able to move any further
54 $i3->command('move before h')->recv;
55 $content = get_ws_content($tmp);
56 is($content->[0]->{id}, $second, 'first container unmodified');
57
58 # Now move in the other direction
59 $i3->command('move after h')->recv;
60 $content = get_ws_content($tmp);
61 is($content->[0]->{id}, $first, 'first container modified');
62
63 # We should not be able to move any further
64 $i3->command('move after h')->recv;
65 $content = get_ws_content($tmp);
66 is($content->[0]->{id}, $first, 'first container unmodified');
67
68 ######################################################################
69 # 3) move a container inside another container
70 ######################################################################
71
72 # Split the current (second) container and create a new container on workspace
73 # level. Our layout looks like this now:
74 # --------------------------
75 # |       | second |       |
76 # | first | ------ | third |
77 # |       |        |       |
78 # --------------------------
79 $i3->command('split v')->recv;
80 $i3->command('level up')->recv;
81 $i3->command('open')->recv;
82
83 $content = get_ws_content($tmp);
84 is(@{$content}, 3, 'three containers on this workspace');
85 my $third = $content->[2]->{id};
86
87 $i3->command('move before h')->recv;
88 $content = get_ws_content($tmp);
89 is(@{$content}, 2, 'only two containers on this workspace');
90 my $nodes = $content->[1]->{nodes};
91 is($nodes->[0]->{id}, $second, 'second container on top');
92 is($nodes->[1]->{id}, $third, 'third container on bottom');
93
94 ######################################################################
95 # move it inside the split container
96 ######################################################################
97
98 $i3->command('move before v')->recv;
99 $nodes = get_ws_content($tmp)->[1]->{nodes};
100 is($nodes->[0]->{id}, $third, 'third container on top');
101 is($nodes->[1]->{id}, $second, 'second container on bottom');
102
103 # move it outside again
104 $i3->command('move before h')->recv;
105 $content = get_ws_content($tmp);
106 is(@{$content}, 3, 'three nodes on this workspace');
107
108 $i3->command('move after h')->recv;
109 $content = get_ws_content($tmp);
110 is(@{$content}, 2, 'two nodes on this workspace');
111
112 diag( "Testing i3, Perl $], $^X" );