]> git.sur5r.net Git - i3/i3/blob - testcases/t/122-split.t
Merge branch 'master' into next
[i3/i3] / testcases / t / 122-split.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Tests splitting
5 #
6 use i3test;
7
8 my $tmp = fresh_workspace;
9
10 my $ws = get_ws($tmp);
11 is($ws->{orientation}, 'horizontal', 'orientation horizontal by default');
12 cmd 'split v';
13 $ws = get_ws($tmp);
14 is($ws->{orientation}, 'vertical', 'split v changes workspace orientation');
15
16 ######################################################################
17 # Open two containers, split, open another container. Then verify
18 # the layout is like we expect it to be
19 ######################################################################
20 cmd 'open';
21 cmd 'open';
22 my $content = get_ws_content($tmp);
23
24 is(@{$content}, 2, 'two containers on workspace level');
25 my $first = $content->[0];
26 my $second = $content->[1];
27
28 is(@{$first->{nodes}}, 0, 'first container has no children');
29 is(@{$second->{nodes}}, 0, 'second container has no children (yet)');
30 my $old_name = $second->{name};
31
32
33 cmd 'split h';
34 cmd 'open';
35
36 $content = get_ws_content($tmp);
37
38 is(@{$content}, 2, 'two containers on workspace level');
39 $first = $content->[0];
40 $second = $content->[1];
41
42 is(@{$first->{nodes}}, 0, 'first container has no children');
43 isnt($second->{name}, $old_name, 'second container was replaced');
44 is($second->{orientation}, 'horizontal', 'orientation is horizontal');
45 is(@{$second->{nodes}}, 2, 'second container has 2 children');
46 is($second->{nodes}->[0]->{name}, $old_name, 'found old second container');
47
48 # TODO: extend this test-case (test next/prev)
49 # - wrapping (no horizontal switch possible, goes level-up)
50 # - going level-up "manually"
51
52 ######################################################################
53 # Test splitting multiple times without actually creating windows
54 ######################################################################
55
56 $tmp = fresh_workspace;
57
58 $ws = get_ws($tmp);
59 is($ws->{orientation}, 'horizontal', 'orientation horizontal by default');
60 cmd 'split v';
61 $ws = get_ws($tmp);
62 is($ws->{orientation}, 'vertical', 'split v changes workspace orientation');
63
64 cmd 'open';
65 my @content = @{get_ws_content($tmp)};
66
67 # recursively sums up all nodes and their children
68 sub sum_nodes {
69     my ($nodes) = @_;
70
71     return 0 if !@{$nodes};
72
73     my @children = (map { @{$_->{nodes}} } @{$nodes},
74                     map { @{$_->{'floating_nodes'}} } @{$nodes});
75
76     return @{$nodes} + sum_nodes(\@children);
77 }
78
79 my $old_count = sum_nodes(\@content);
80 cmd 'split v';
81
82 @content = @{get_ws_content($tmp)};
83 $old_count = sum_nodes(\@content);
84
85 cmd 'split v';
86
87 @content = @{get_ws_content($tmp)};
88 my $count = sum_nodes(\@content);
89 is($count, $old_count, 'not more windows after splitting again');
90
91 ######################################################################
92 # In the special case of being inside a stacked or tabbed container, we don’t
93 # want this to happen.
94 ######################################################################
95
96 $tmp = fresh_workspace;
97
98 cmd 'open';
99 @content = @{get_ws_content($tmp)};
100 is(scalar @content, 1, 'Precisely one container on this ws');
101 cmd 'layout stacked';
102 @content = @{get_ws_content($tmp)};
103 is(scalar @content, 1, 'Still one container on this ws');
104 is(scalar @{$content[0]->{nodes}}, 1, 'Stacked con has one child node');
105
106 cmd 'split h';
107 cmd 'open';
108 @content = @{get_ws_content($tmp)};
109 is(scalar @content, 1, 'Still one container on this ws');
110 is(scalar @{$content[0]->{nodes}}, 1, 'Stacked con still has one child node');
111
112 done_testing;