]> git.sur5r.net Git - i3/i3/blob - testcases/t/518-interpret-workspace-numbers.t
Fix 'rename workspace to tosomething'
[i3/i3] / testcases / t / 518-interpret-workspace-numbers.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • http://build.i3wm.org/docs/ipc.html
12 #   (or docs/ipc)
13 #
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 #   (unless you are already familiar with Perl)
16 #
17 # Tests that workspace assignment config directives for plain numbers will
18 # assign any workspace of that number to the specified output.
19 # Ticket: #1238
20 # Bug still in: 4.7.2-147-g3760a48
21 use i3test i3_autostart => 0;
22
23 my $config = <<EOT;
24 # i3 config file (v4)
25 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
26
27 workspace 1:override output fake-0
28 workspace 2 output fake-0
29 workspace 1 output fake-1
30 workspace 2:override output fake-1
31
32 fake-outputs 1024x768+0+0,1024x768+1024+0
33 EOT
34
35 my $pid = launch_with_config($config);
36 my $i3 = i3(get_socket_path());
37 $i3->connect->recv;
38
39 # Returns the name of the output on which this workspace resides
40 sub get_output_for_workspace {
41     my $ws_name = shift @_;
42
43     foreach (grep { not $_->{name} =~ /^__/ } @{$i3->get_tree->recv->{nodes}}) {
44         my $output = $_->{name};
45         foreach (grep { $_->{name} =~ "content" } @{$_->{nodes}}) {
46             return $output if $_->{nodes}[0]->{name} =~ $ws_name;
47         }
48     }
49 }
50
51 ################################################################################
52 # Workspace assignments with bare numbers should be interpreted as `workspace
53 # number` config directives. Any workspace beginning with that number should be
54 # assigned to the specified output.
55 ################################################################################
56
57 cmd 'focus output fake-1';
58 cmd 'workspace "2:foo"';
59 is(get_output_for_workspace('2:foo'), 'fake-0',
60     'Workspaces should be assigned by number when the assignment is a plain number')
61     or diag 'Since workspace number 2 is assigned to fake-0, 2:foo should open on fake-0';
62
63 cmd 'focus output fake-0';
64 cmd 'workspace "2:override"';
65 is(get_output_for_workspace('2:override'), 'fake-1',
66     'Workspace assignments by name should override numbered assignments')
67     or diag 'Since workspace "2:override" is assigned by name to fake-1, it should open on fake-1';
68
69 cmd 'focus output fake-1';
70 cmd 'workspace "1:override"';
71 is(get_output_for_workspace('1:override'), 'fake-0',
72     'Assignment rules should not be affected by the order assignments are declared')
73     or diag 'Since workspace "1:override" is assigned by name to fake-0, it should open on fake-0';
74
75 exit_gracefully($pid);
76
77 done_testing;