]> git.sur5r.net Git - i3/i3/blobdiff - testcases/t/17-workspace.t
Merge branch 'master' into next
[i3/i3] / testcases / t / 17-workspace.t
index 1c0c7e285beef134a488690cbc8dd6f57f75da31..3c3b6cc675421a510dc8c25b723198c2e8bf5006 100644 (file)
 # Tests whether we can switch to a non-existant workspace
 # (necessary for further tests)
 #
-use Test::More tests => 2;
-use List::MoreUtils qw(all none);
-use Data::Dumper;
-use AnyEvent::I3;
-use File::Temp qw(tmpnam);
-use v5.10;
-
-my $i3 = i3("/tmp/nestedcons");
-
-sub get_workspace_names {
-    my $tree = $i3->get_workspaces->recv;
-    my @workspaces = map { @{$_->{nodes}} } @{$tree->{nodes}};
-    [ map { $_->{name} } @workspaces ]
-}
-
-sub workspace_exists {
-    my ($name) = @_;
-    ($name ~~ @{get_workspace_names()})
-}
-
-sub get_unused_workspace {
-    my @names = get_workspace_names();
-    my $tmp;
-    do { $tmp = tmpnam() } while ($tmp ~~ @names);
-    $tmp
-}
+use List::Util qw(first);
+use i3test;
 
-my $tmp = get_unused_workspace();
-diag("Temporary workspace name: $tmp\n");
+# to ensure that workspace 1 stays open
+cmd 'open';
 
-$i3->command("workspace $tmp")->recv;
+my $tmp = fresh_workspace;
 ok(workspace_exists($tmp), 'workspace created');
+# if the workspace could not be created, we cannot run any other test
+# (every test starts by creating its workspace)
+if (!workspace_exists($tmp)) {
+    BAIL_OUT('Cannot create workspace, further tests make no sense');
+}
 
-my $otmp = get_unused_workspace();
+my $otmp = fresh_workspace;
 diag("Other temporary workspace name: $otmp\n");
 
 # As the old workspace was empty, it should get
 # cleaned up as we switch away from it
-$i3->command("workspace $otmp")->recv;
+cmd "workspace $otmp";
 ok(!workspace_exists($tmp), 'old workspace cleaned up');
 
-diag( "Testing i3, Perl $], $^X" );
+# Switch to the same workspace again to make sure it doesn’t get cleaned up
+cmd "workspace $otmp";
+cmd "workspace $otmp";
+ok(workspace_exists($otmp), 'other workspace still exists');
+
+
+#####################################################################
+# check if the workspace next / prev commands work
+#####################################################################
+
+cmd 'workspace next';
+
+ok(!workspace_exists('next'), 'workspace "next" does not exist');
+
+cmd "workspace $tmp";
+cmd 'open';
+
+ok(workspace_exists($tmp), 'workspace created');
+
+cmd "workspace $otmp";
+cmd 'open';
+
+ok(workspace_exists($tmp), 'workspace tmp still exists');
+ok(workspace_exists($otmp), 'workspace otmp created');
+
+is(focused_ws(), $otmp, 'focused workspace is otmp');
+
+cmd 'workspace prev';
+is(focused_ws(), $tmp, 'focused workspace is tmp after workspace prev');
+
+cmd 'workspace next';
+is(focused_ws(), $otmp, 'focused workspace is otmp after workspace next');
+
+
+#####################################################################
+# check that wrapping works
+#####################################################################
+
+cmd 'workspace next';
+is(focused_ws(), '1', 'focused workspace is 1 after workspace next');
+
+cmd 'workspace next';
+is(focused_ws(), $tmp, 'focused workspace is tmp after workspace next');
+
+cmd 'workspace next';
+is(focused_ws(), $otmp, 'focused workspace is otmp after workspace next');
+
+
+cmd 'workspace prev';
+is(focused_ws(), $tmp, 'focused workspace is tmp after workspace prev');
+
+cmd 'workspace prev';
+is(focused_ws(), '1', 'focused workspace is tmp after workspace prev');
+
+cmd 'workspace prev';
+is(focused_ws(), $otmp, 'focused workspace is otmp after workspace prev');
+
+
+#####################################################################
+# check if we can change to "next" / "prev"
+#####################################################################
+
+cmd 'workspace "next"';
+
+ok(workspace_exists('next'), 'workspace "next" exists');
+is(focused_ws(), 'next', 'now on workspace next');
+
+cmd 'workspace "prev"';
+
+ok(workspace_exists('prev'), 'workspace "prev" exists');
+is(focused_ws(), 'prev', 'now on workspace prev');
+
+#####################################################################
+# check that the numbers are assigned/recognized correctly
+#####################################################################
+
+cmd "workspace 3: $tmp";
+my $ws = get_ws("3: $tmp");
+ok(defined($ws), "workspace 3: $tmp was created");
+is($ws->{num}, 3, 'workspace number is 3');
+
+cmd "workspace 0: $tmp";
+my $ws = get_ws("0: $tmp");
+ok(defined($ws), "workspace 0: $tmp was created");
+is($ws->{num}, 0, 'workspace number is 0');
+
+cmd "workspace aa: $tmp";
+my $ws = get_ws("aa: $tmp");
+ok(defined($ws), "workspace aa: $tmp was created");
+is($ws->{num}, -1, 'workspace number is -1');
+
+done_testing;