]> git.sur5r.net Git - i3/i3/blob - testcases/t/255-multiple-marks.t
925e39db656c126e7cecc10115e256a06a054072
[i3/i3] / testcases / t / 255-multiple-marks.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 for mark/unmark with multiple marks on a single window.
18 # Ticket: #2014
19 use i3test;
20 use List::Util qw(first);
21
22 my ($ws, $con, $first, $second);
23
24 sub get_marks {
25     return i3(get_socket_path())->get_marks->recv;
26 }
27
28 sub get_mark_for_window_on_workspace {
29     my ($ws, $con) = @_;
30
31     my $current = first { $_->{window} == $con->{id} } @{get_ws_content($ws)};
32     return $current->{marks};
33 }
34
35 ###############################################################################
36 # Verify that multiple marks can be set on a window.
37 ###############################################################################
38
39 $ws = fresh_workspace;
40 $con = open_window;
41 cmd 'mark --add A';
42 cmd 'mark --add B';
43
44 is_deeply(sort(get_marks()), [ 'A', 'B' ], 'both marks exist');
45 is_deeply(get_mark_for_window_on_workspace($ws, $con), [ 'A', 'B' ], 'both marks are on the same window');
46
47 cmd 'unmark';
48
49 ###############################################################################
50 # Verify that toggling a mark can affect only the specified mark.
51 ###############################################################################
52
53 $ws = fresh_workspace;
54 $con = open_window;
55 cmd 'mark A';
56
57 cmd 'mark --add --toggle B';
58 is_deeply(get_mark_for_window_on_workspace($ws, $con), [ 'A', 'B' ], 'both marks are on the same window');
59 cmd 'mark --add --toggle B';
60 is_deeply(get_mark_for_window_on_workspace($ws, $con), [ 'A' ], 'only mark B has been removed');
61
62 cmd 'unmark';
63
64 ###############################################################################
65 # Verify that unmarking a mark leaves other marks on the same window intact.
66 ###############################################################################
67
68 $ws = fresh_workspace;
69 $con = open_window;
70 cmd 'mark --add A';
71 cmd 'mark --add B';
72 cmd 'mark --add C';
73
74 cmd 'unmark B';
75 is_deeply(get_mark_for_window_on_workspace($ws, $con), [ 'A', 'C' ], 'only mark B has been removed');
76
77 cmd 'unmark';
78
79 ###############################################################################
80 # Verify that matching via mark works on windows with multiple marks.
81 ###############################################################################
82
83 $ws = fresh_workspace;
84 $con = open_window;
85 cmd 'mark --add A';
86 cmd 'mark --add B';
87 open_window;
88
89 cmd '[con_mark=B] mark --add C';
90 is_deeply(get_mark_for_window_on_workspace($ws, $con), [ 'A', 'B', 'C' ], 'matching on a mark works with multiple marks');
91
92 cmd 'unmark';
93
94 ###############################################################################
95
96 done_testing;