2 # vim:ts=4:sw=4:expandtab
5 use List::Util qw(first);
7 # to not depend on List::MoreUtils
11 return 0 unless $cb->();
24 my $i3 = i3(get_socket_path());
30 my $tree = $i3->get_tree->recv;
40 orientation => $ignore,
44 window_rect => $ignore,
50 focused => JSON::XS::false,
51 urgent => JSON::XS::false,
53 'floating_nodes' => $ignore,
56 # a shallow copy is sufficient, since we only ignore values at the root
57 my $tree_copy = { %$tree };
59 for (keys %$expected) {
60 my $val = $expected->{$_};
62 # delete unwanted keys, so we can use is_deeply()
63 if (ref($val) eq 'SCALAR' and $val == $ignore) {
64 delete $tree_copy->{$_};
65 delete $expected->{$_};
69 is_deeply($tree_copy, $expected, 'root node OK');
71 my @nodes = @{$tree->{nodes}};
73 ok(@nodes > 0, 'root node has at least one leaf');
75 ok((all { $_->{type} == 1 } @nodes), 'all nodes are of type CT_OUTPUT');
76 ok((none { defined($_->{window}) } @nodes), 'no CT_OUTPUT contains a window');
77 ok((all { @{$_->{nodes}} > 0 } @nodes), 'all nodes have at least one leaf (workspace)');
80 my $content = first { $_->{type} == 2 } @{$ws->{nodes}};
81 @workspaces = (@workspaces, @{$content->{nodes}});
84 ok((all { $_->{type} == 4 } @workspaces), 'all workspaces are of type CT_WORKSPACE');
85 #ok((all { @{$_->{nodes}} == 0 } @workspaces), 'all workspaces are empty yet');
86 ok((none { defined($_->{window}) } @workspaces), 'no CT_OUTPUT contains a window');
88 # TODO: get the focused container
90 $i3->command('open')->recv;
92 # TODO: get the focused container, check if it changed.
93 # TODO: get the old focused container, check if there is a new child
95 #diag(Dumper(\@workspaces));