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