]> git.sur5r.net Git - i3/i3/blob - testcases/t/518-interpret-workspace-numbers.t
tests: replace http:// with https:// where appropriate
[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 # • https://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • https://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_config => <<EOT;
22 # i3 config file (v4)
23 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
24
25 workspace 1:override output fake-0
26 workspace 2 output fake-0
27 workspace 1 output fake-1
28 workspace 2:override output fake-1
29
30 fake-outputs 1024x768+0+0,1024x768+1024+0
31 EOT
32
33 my $i3 = i3(get_socket_path());
34 $i3->connect->recv;
35
36 # Returns the name of the output on which this workspace resides
37 sub get_output_for_workspace {
38     my $ws_name = shift @_;
39
40     foreach (grep { not $_->{name} =~ /^__/ } @{$i3->get_tree->recv->{nodes}}) {
41         my $output = $_->{name};
42         foreach (grep { $_->{name} =~ "content" } @{$_->{nodes}}) {
43             return $output if $_->{nodes}[0]->{name} =~ $ws_name;
44         }
45     }
46 }
47
48 ################################################################################
49 # Workspace assignments with bare numbers should be interpreted as `workspace
50 # number` config directives. Any workspace beginning with that number should be
51 # assigned to the specified output.
52 ################################################################################
53
54 cmd 'focus output fake-1';
55 cmd 'workspace "2:foo"';
56 is(get_output_for_workspace('2:foo'), 'fake-0',
57     'Workspaces should be assigned by number when the assignment is a plain number')
58     or diag 'Since workspace number 2 is assigned to fake-0, 2:foo should open on fake-0';
59
60 cmd 'focus output fake-0';
61 cmd 'workspace "2:override"';
62 is(get_output_for_workspace('2:override'), 'fake-1',
63     'Workspace assignments by name should override numbered assignments')
64     or diag 'Since workspace "2:override" is assigned by name to fake-1, it should open on fake-1';
65
66 cmd 'focus output fake-1';
67 cmd 'workspace "1:override"';
68 is(get_output_for_workspace('1:override'), 'fake-0',
69     'Assignment rules should not be affected by the order assignments are declared')
70     or diag 'Since workspace "1:override" is assigned by name to fake-0, it should open on fake-0';
71
72 done_testing;