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