2 # vim:ts=4:sw=4:expandtab
4 # Tests whether we can switch to a non-existant workspace
5 # (necessary for further tests)
7 use List::Util qw(first);
10 sub workspace_exists {
12 ($name ~~ @{get_workspace_names()})
15 my $tmp = fresh_workspace;
16 ok(workspace_exists($tmp), 'workspace created');
17 # if the workspace could not be created, we cannot run any other test
18 # (every test starts by creating its workspace)
19 if (!workspace_exists($tmp)) {
20 BAIL_OUT('Cannot create workspace, further tests make no sense');
23 my $otmp = fresh_workspace;
24 diag("Other temporary workspace name: $otmp\n");
26 # As the old workspace was empty, it should get
27 # cleaned up as we switch away from it
28 cmd "workspace $otmp";
29 ok(!workspace_exists($tmp), 'old workspace cleaned up');
31 # Switch to the same workspace again to make sure it doesn’t get cleaned up
32 cmd "workspace $otmp";
33 cmd "workspace $otmp";
34 ok(workspace_exists($otmp), 'other workspace still exists');
37 #####################################################################
38 # check if the workspace next / prev commands work
39 #####################################################################
43 ok(!workspace_exists('next'), 'workspace "next" does not exist');
48 ok(workspace_exists($tmp), 'workspace created');
50 cmd "workspace $otmp";
53 ok(workspace_exists($tmp), 'workspace tmp still exists');
54 ok(workspace_exists($otmp), 'workspace otmp created');
57 my $i3 = i3("/tmp/nestedcons");
58 my $tree = $i3->get_tree->recv;
59 my @outputs = @{$tree->{nodes}};
61 for my $output (@outputs) {
62 # get the first CT_CON of each output
63 my $content = first { $_->{type} == 2 } @{$output->{nodes}};
64 my @focused = @{$content->{focus}};
65 return first { $_->{id} == $focused[0] } @{$content->{nodes}};
70 my $con = focused_ws_con;
74 is(focused_ws(), $otmp, 'focused workspace is otmp');
77 is(focused_ws(), $tmp, 'focused workspace is tmp after workspace prev');
80 is(focused_ws(), $otmp, 'focused workspace is otmp after workspace next');
83 #####################################################################
84 # check that wrapping works
85 #####################################################################
88 is(focused_ws(), '1', 'focused workspace is 1 after workspace next');
91 is(focused_ws(), $tmp, 'focused workspace is tmp after workspace next');
94 is(focused_ws(), $otmp, 'focused workspace is otmp after workspace next');
98 is(focused_ws(), $tmp, 'focused workspace is tmp after workspace prev');
100 cmd 'workspace prev';
101 is(focused_ws(), '1', 'focused workspace is tmp after workspace prev');
103 cmd 'workspace prev';
104 is(focused_ws(), $otmp, 'focused workspace is otmp after workspace prev');
107 #####################################################################
108 # check if we can change to "next" / "prev"
109 #####################################################################
111 cmd 'workspace "next"';
113 ok(workspace_exists('next'), 'workspace "next" exists');
114 is(focused_ws(), 'next', 'now on workspace next');
116 cmd 'workspace "prev"';
118 ok(workspace_exists('prev'), 'workspace "prev" exists');
119 is(focused_ws(), 'prev', 'now on workspace prev');