2 # vim:ts=4:sw=4:expandtab
6 use i3test tests => 14;
9 my $i3 = i3("/tmp/nestedcons");
11 my $tmp = get_unused_workspace();
12 $i3->command("workspace $tmp")->recv;
14 my $ws = get_ws($tmp);
15 is($ws->{orientation}, 1, 'orientation horizontal by default');
16 $i3->command('split v')->recv;
18 is($ws->{orientation}, 2, 'split v changes workspace orientation');
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);
28 is(@{$content}, 2, 'two containers on workspace level');
29 my $first = $content->[0];
30 my $second = $content->[1];
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};
37 $i3->command('split h')->recv;
38 $i3->command('open')->recv;
40 $content = get_ws_content($tmp);
42 is(@{$content}, 2, 'two containers on workspace level');
43 $first = $content->[0];
44 $second = $content->[1];
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');
52 # TODO: extend this test-case (test next/prev)
53 # - wrapping (no horizontal switch possible, goes level-up)
54 # - going level-up "manually"
56 ######################################################################
57 # Test splitting multiple times without actually creating windows
58 ######################################################################
60 $tmp = get_unused_workspace();
61 $i3->command("workspace $tmp")->recv;
64 is($ws->{orientation}, 1, 'orientation horizontal by default');
65 $i3->command('split v')->recv;
67 is($ws->{orientation}, 2, 'split v changes workspace orientation');
69 $i3->command('open')->recv;
70 my @content = @{get_ws_content($tmp)};
72 # recursively sums up all nodes and their children
76 return 0 if !@{$nodes};
78 my @children = (map { @{$_->{nodes}} } @{$nodes},
79 map { @{$_->{'floating-nodes'}} } @{$nodes});
81 return @{$nodes} + sum_nodes(\@children);
84 my $old_count = sum_nodes(\@content);
85 $i3->command('split v')->recv;
87 @content = @{get_ws_content($tmp)};
88 my $old_count = sum_nodes(\@content);
90 $i3->command('split v')->recv;
92 @content = @{get_ws_content($tmp)};
93 my $count = sum_nodes(\@content);
94 is($count, $old_count, 'not more windows after splitting again');
96 diag( "Testing i3, Perl $], $^X" );