X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=testcases%2Ft%2F132-move-workspace.t;h=60705f96d4de586998724d1270f77d6c3721e4ca;hb=HEAD;hp=a4f6b6082ad7da6f4a4ebef73241aad0ba402899;hpb=cd2a1267c8de435219d3808a71b7a09288ad3585;p=i3%2Fi3 diff --git a/testcases/t/132-move-workspace.t b/testcases/t/132-move-workspace.t index a4f6b608..60705f96 100644 --- a/testcases/t/132-move-workspace.t +++ b/testcases/t/132-move-workspace.t @@ -2,13 +2,13 @@ # vim:ts=4:sw=4:expandtab # # Please read the following documents before working on tests: -# • http://build.i3wm.org/docs/testsuite.html +# • https://build.i3wm.org/docs/testsuite.html # (or docs/testsuite) # -# • http://build.i3wm.org/docs/lib-i3test.html +# • https://build.i3wm.org/docs/lib-i3test.html # (alternatively: perldoc ./testcases/lib/i3test.pm) # -# • http://build.i3wm.org/docs/ipc.html +# • https://build.i3wm.org/docs/ipc.html # (or docs/ipc) # # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf @@ -22,7 +22,9 @@ my $i3 = i3(get_socket_path()); # We move the pointer out of our way to avoid a bug where the focus will # be set to the window under the cursor +sync_with_i3; $x->root->warp_pointer(0, 0); +sync_with_i3; sub move_workspace_test { my ($movecmd) = @_; @@ -198,4 +200,154 @@ cmd 'move workspace number 17'; ok(workspace_exists('17'), 'workspace 17 created by moving'); is(@{get_ws('17')->{nodes}}, 1, 'one node on ws 16'); +################################################################################ +# The following four tests verify the various 'move workspace' commands when +# the selection is itself a workspace. +################################################################################ + +# borrowed from 122-split.t +# recursively sums up all nodes and their children +sub sum_nodes { + my ($nodes) = @_; + + return 0 if !@{$nodes}; + + my @children = (map { @{$_->{nodes}} } @{$nodes}, + map { @{$_->{'floating_nodes'}} } @{$nodes}); + + return @{$nodes} + sum_nodes(\@children); +} + +############################################################ +# move workspace 'next|prev' +############################################################ +$tmp = get_unused_workspace(); +$tmp2 = get_unused_workspace(); + +cmd "workspace $tmp"; +cmd 'open'; +is_num_children($tmp, 1, 'one container on first ws'); + +cmd "workspace $tmp2"; +cmd 'open'; +is_num_children($tmp2, 1, 'one container on second ws'); +cmd 'open'; +is_num_children($tmp2, 2, 'two containers on second ws'); + +cmd 'focus parent'; +cmd 'move workspace prev'; + +is_num_children($tmp, 2, 'two child containers on first ws'); +is(sum_nodes(get_ws_content($tmp)), 4, 'four total containers on first ws'); +is_num_children($tmp2, 0, 'no containers on second ws'); + +############################################################ +# move workspace current +# This is a special case that should be a no-op. +############################################################ +$tmp = fresh_workspace(); + +cmd 'open'; +is_num_children($tmp, 1, 'one container on first ws'); +my $tmpcount = sum_nodes(get_ws_content($tmp)); + +cmd 'focus parent'; +cmd "move workspace $tmp"; + +is(sum_nodes(get_ws_content($tmp)), $tmpcount, 'number of containers in first ws unchanged'); + +############################################################ +# move workspace '' +############################################################ +$tmp2 = get_unused_workspace(); +$tmp = fresh_workspace(); + +cmd 'open'; +is_num_children($tmp, 1, 'one container on first ws'); + +cmd "workspace $tmp2"; +cmd 'open'; +is_num_children($tmp2, 1, 'one container on second ws'); +cmd 'open'; +is_num_children($tmp2, 2, 'two containers on second ws'); + +cmd 'focus parent'; +cmd "move workspace $tmp"; + +is_num_children($tmp, 2, 'two child containers on first ws'); +is(sum_nodes(get_ws_content($tmp)), 4, 'four total containers on first ws'); +is_num_children($tmp2, 0, 'no containers on second ws'); + +############################################################ +# move workspace number '' +############################################################ +cmd 'workspace 18'; +cmd 'open'; +is_num_children('18', 1, 'one container on ws 18'); + +cmd 'workspace 19'; +cmd 'open'; +is_num_children('19', 1, 'one container on ws 19'); +cmd 'open'; +is_num_children('19', 2, 'two containers on ws 19'); + +cmd 'focus parent'; +cmd 'move workspace number 18'; + +is_num_children('18', 2, 'two child containers on ws 18'); +is(sum_nodes(get_ws_content('18')), 4, 'four total containers on ws 18'); +is_num_children('19', 0, 'no containers on ws 19'); + +################################################################### +# move workspace '' with a floating child +################################################################### +$tmp2 = get_unused_workspace(); +$tmp = fresh_workspace(); +cmd 'open'; +cmd 'floating toggle'; +cmd 'open'; +cmd 'floating toggle'; +cmd 'open'; + +$ws = get_ws($tmp); +is_num_children($tmp, 1, 'one container on first workspace'); +is(@{$ws->{floating_nodes}}, 2, 'two floating nodes on first workspace'); + +cmd 'focus parent'; +cmd "move workspace $tmp2"; + +$ws = get_ws($tmp2); +is_num_children($tmp2, 1, 'one container on second workspace'); +is(@{$ws->{floating_nodes}}, 2, 'two floating nodes on second workspace'); + +################################################################### +# same as the above, but with only floating children +################################################################### +$tmp2 = get_unused_workspace(); +$tmp = fresh_workspace(); +cmd 'open'; +cmd 'floating toggle'; + +$ws = get_ws($tmp); +is_num_children($tmp, 0, 'no regular nodes on first workspace'); +is(@{$ws->{floating_nodes}}, 1, 'one floating node on first workspace'); + +cmd 'focus parent'; +cmd "move workspace $tmp2"; + +$ws = get_ws($tmp2); +is_num_children($tmp2, 0, 'no regular nodes on second workspace'); +is(@{$ws->{floating_nodes}}, 1, 'one floating node on second workspace'); + +################################################################### +# Check that moving an empty workspace using criteria doesn't +# create unfocused empty workspace. +################################################################### +$tmp2 = get_unused_workspace(); +$tmp = fresh_workspace(); +cmd 'mark a'; +cmd "[con_mark=a] move to workspace $tmp2"; + +is (get_ws($tmp2), undef, 'No empty workspace created'); + done_testing;