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