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,
49 floating => 'auto_off',
50 scratchpad_state => 'none',
52 focused => JSON::XS::false,
53 urgent => JSON::XS::false,
55 'floating_nodes' => $ignore,
58 # a shallow copy is sufficient, since we only ignore values at the root
59 my $tree_copy = { %$tree };
61 for (keys %$expected) {
62 my $val = $expected->{$_};
64 # delete unwanted keys, so we can use is_deeply()
65 if (ref($val) eq 'SCALAR' and $val == $ignore) {
66 delete $tree_copy->{$_};
67 delete $expected->{$_};
71 is_deeply($tree_copy, $expected, 'root node OK');
73 my @nodes = @{$tree->{nodes}};
75 ok(@nodes > 0, 'root node has at least one leaf');
77 ok((all { $_->{type} == 1 } @nodes), 'all nodes are of type CT_OUTPUT');
78 ok((none { defined($_->{window}) } @nodes), 'no CT_OUTPUT contains a window');
79 ok((all { @{$_->{nodes}} > 0 } @nodes), 'all nodes have at least one leaf (workspace)');
82 my $content = first { $_->{type} == 2 } @{$ws->{nodes}};
83 @workspaces = (@workspaces, @{$content->{nodes}});
86 ok((all { $_->{type} == 4 } @workspaces), 'all workspaces are of type CT_WORKSPACE');
87 #ok((all { @{$_->{nodes}} == 0 } @workspaces), 'all workspaces are empty yet');
88 ok((none { defined($_->{window}) } @workspaces), 'no CT_OUTPUT contains a window');
90 # TODO: get the focused container
92 $i3->command('open')->recv;
94 # TODO: get the focused container, check if it changed.
95 # TODO: get the old focused container, check if there is a new child
97 #diag(Dumper(\@workspaces));