]> git.sur5r.net Git - i3/i3/blob - testcases/t/24-move.t
refactor tree_move() into src/move.c, change config (!), change testcase
[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 cmd "workspace $tmp";
17
18 ######################################################################
19 # 1) move a container which cannot be moved
20 ######################################################################
21
22 cmd 'open';
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 left')->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 left')->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 right')->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 right')->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 left')->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 up')->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 left')->recv;
105 $content = get_ws_content($tmp);
106 is(@{$content}, 3, 'three nodes on this workspace');
107
108 # due to automatic flattening/cleanup, the remaining split container
109 # will be replaced by the con itself, so we will still have 3 nodes
110 $i3->command('move right')->recv;
111 $content = get_ws_content($tmp);
112 is(@{$content}, 3, 'two nodes on this workspace');
113
114 ######################################################################
115 # 4) We create two v-split containers on the workspace, then we move
116 #    all Cons from the left v-split to the right one. The old vsplit
117 #    container needs to be closed. Verify that it will be closed.
118 ######################################################################
119
120 my $otmp = get_unused_workspace();
121 cmd "workspace $otmp";
122
123 $i3->command("open")->recv;
124 $i3->command("open")->recv;
125 $i3->command("split v")->recv;
126 $i3->command("open")->recv;
127 $i3->command("prev h")->recv;
128 $i3->command("split v")->recv;
129 $i3->command("open")->recv;
130 $i3->command("move right")->recv;
131 $i3->command("prev h")->recv;
132 $i3->command("move right")->recv;
133
134 $content = get_ws_content($otmp);
135 is(@{$content}, 1, 'only one nodes on this workspace');
136
137 diag( "Testing i3, Perl $], $^X" );