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,
42 split => JSON::XS::false,
45 window_rect => $ignore,
50 floating => 'auto_off',
51 last_split_layout => 'splith',
52 scratchpad_state => 'none',
54 focused => JSON::XS::false,
55 urgent => JSON::XS::false,
57 'floating_nodes' => $ignore,
60 # a shallow copy is sufficient, since we only ignore values at the root
61 my $tree_copy = { %$tree };
63 for (keys %$expected) {
64 my $val = $expected->{$_};
66 # delete unwanted keys, so we can use is_deeply()
67 if (ref($val) eq 'SCALAR' and $val == $ignore) {
68 delete $tree_copy->{$_};
69 delete $expected->{$_};
73 is_deeply($tree_copy, $expected, 'root node OK');
75 my @nodes = @{$tree->{nodes}};
77 ok(@nodes > 0, 'root node has at least one leaf');
79 ok((all { $_->{type} == 1 } @nodes), 'all nodes are of type CT_OUTPUT');
80 ok((none { defined($_->{window}) } @nodes), 'no CT_OUTPUT contains a window');
81 ok((all { @{$_->{nodes}} > 0 } @nodes), 'all nodes have at least one leaf (workspace)');
84 my $content = first { $_->{type} == 2 } @{$ws->{nodes}};
85 @workspaces = (@workspaces, @{$content->{nodes}});
88 ok((all { $_->{type} == 4 } @workspaces), 'all workspaces are of type CT_WORKSPACE');
89 #ok((all { @{$_->{nodes}} == 0 } @workspaces), 'all workspaces are empty yet');
90 ok((none { defined($_->{window}) } @workspaces), 'no CT_OUTPUT contains a window');
92 # TODO: get the focused container
94 $i3->command('open')->recv;
96 # TODO: get the focused container, check if it changed.
97 # TODO: get the old focused container, check if there is a new child
99 #diag(Dumper(\@workspaces));
101 #diag(Dumper($tree));