]> git.sur5r.net Git - i3/i3/blob - testcases/t/116-nestedcons.t
Merge branch 'doc-fixes'
[i3/i3] / testcases / t / 116-nestedcons.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3
4 use i3test;
5 use List::Util qw(first);
6
7 # to not depend on List::MoreUtils
8 sub all (&@) {
9     my $cb = shift;
10     for (@_) {
11         return 0 unless $cb->();
12     }
13     return 1;
14 }
15
16 sub none (&@) {
17     my $cb = shift;
18     for (@_) {
19         return 0 if $cb->();
20     }
21     return 1;
22 }
23
24 my $i3 = i3(get_socket_path());
25
26 ####################
27 # Request tree
28 ####################
29
30 my $tree = $i3->get_tree->recv;
31
32 my $expected = {
33     fullscreen_mode => 0,
34     nodes => ignore(),
35     window => undef,
36     name => 'root',
37     orientation => ignore(),
38     type => 0,
39     id => ignore(),
40     rect => ignore(),
41     window_rect => ignore(),
42     geometry => ignore(),
43     swallows => ignore(),
44     percent => undef,
45     layout => 'default',
46     focus => ignore(),
47     focused => JSON::XS::false,
48     urgent => JSON::XS::false,
49     border => 'normal',
50     'floating_nodes' => ignore(),
51 };
52
53 cmp_deeply($tree, $expected, 'root node OK');
54
55 my @nodes = @{$tree->{nodes}};
56
57 ok(@nodes > 0, 'root node has at least one leaf');
58
59 ok((all { $_->{type} == 1 } @nodes), 'all nodes are of type CT_OUTPUT');
60 ok((none { defined($_->{window}) } @nodes), 'no CT_OUTPUT contains a window');
61 ok((all { @{$_->{nodes}} > 0 } @nodes), 'all nodes have at least one leaf (workspace)');
62 my @workspaces;
63 for my $ws (@nodes) {
64     my $content = first { $_->{type} == 2 } @{$ws->{nodes}};
65     @workspaces = (@workspaces, @{$content->{nodes}});
66 }
67
68 ok((all { $_->{type} == 4 } @workspaces), 'all workspaces are of type CT_WORKSPACE');
69 #ok((all { @{$_->{nodes}} == 0 } @workspaces), 'all workspaces are empty yet');
70 ok((none { defined($_->{window}) } @workspaces), 'no CT_OUTPUT contains a window');
71
72 # TODO: get the focused container
73
74 $i3->command('open')->recv;
75
76 # TODO: get the focused container, check if it changed.
77 # TODO: get the old focused container, check if there is a new child
78
79 #diag(Dumper(\@workspaces));
80
81 #diag(Dumper($tree));
82
83
84 done_testing;