2 # vim:ts=4:sw=4:expandtab
11 ################################################################################
12 # Open two containers, split, open another container. Then verify
13 # the layout is like we expect it to be
14 ################################################################################
16 sub verify_split_layout {
19 $tmp = fresh_workspace;
22 is($ws->{orientation}, 'horizontal', 'orientation horizontal by default');
25 is($ws->{orientation}, 'vertical', 'split v changes workspace orientation');
29 my $content = get_ws_content($tmp);
31 is(@{$content}, 2, 'two containers on workspace level');
32 my $first = $content->[0];
33 my $second = $content->[1];
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};
39 cmd $args{split_command};
42 $content = get_ws_content($tmp);
44 is(@{$content}, 2, 'two containers on workspace level');
45 $first = $content->[0];
46 $second = $content->[1];
48 is(@{$first->{nodes}}, 0, 'first container has no children');
49 isnt($second->{name}, $old_name, 'second container was replaced');
50 is($second->{orientation}, 'horizontal', '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');
55 verify_split_layout(split_command => 'split h');
56 verify_split_layout(split_command => 'split horizontal');
58 # TODO: extend this test-case (test next/prev)
59 # - wrapping (no horizontal switch possible, goes level-up)
60 # - going level-up "manually"
62 ######################################################################
63 # Test splitting multiple times without actually creating windows
64 ######################################################################
66 $tmp = fresh_workspace;
69 is($ws->{orientation}, 'horizontal', 'orientation horizontal by default');
72 is($ws->{orientation}, 'vertical', 'split v changes workspace orientation');
75 my @content = @{get_ws_content($tmp)};
77 # recursively sums up all nodes and their children
81 return 0 if !@{$nodes};
83 my @children = (map { @{$_->{nodes}} } @{$nodes},
84 map { @{$_->{'floating_nodes'}} } @{$nodes});
86 return @{$nodes} + sum_nodes(\@children);
89 my $old_count = sum_nodes(\@content);
92 @content = @{get_ws_content($tmp)};
93 $old_count = sum_nodes(\@content);
97 @content = @{get_ws_content($tmp)};
98 my $count = sum_nodes(\@content);
99 is($count, $old_count, 'not more windows after splitting again');
101 ######################################################################
102 # In the special case of being inside a stacked or tabbed container, we don’t
103 # want this to happen.
104 ######################################################################
106 $tmp = fresh_workspace;
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');
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');