]> git.sur5r.net Git - i3/i3/blob - testcases/t/210-mark-unmark.t
Merge branch 'next' into master
[i3/i3] / testcases / t / 210-mark-unmark.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 # checks if mark and unmark work correctly
18 use i3test;
19 use List::Util qw(first);
20
21 my ($con, $first, $second);
22
23 sub get_marks {
24     return i3(get_socket_path())->get_marks->recv;
25 }
26
27 sub get_mark_for_window_on_workspace {
28     my ($ws, $con) = @_;
29
30     my $current = first { $_->{window} == $con->{id} } @{get_ws_content($ws)};
31     return $current->{marks};
32 }
33
34 ##############################################################
35 # 1: check that there are no marks set yet
36 ##############################################################
37
38 my $tmp = fresh_workspace;
39
40 cmd 'split h';
41
42 is_deeply(get_marks(), [], 'no marks set yet');
43
44 ##############################################################
45 # 2: mark a con, check that it's marked, unmark it, check that
46 ##############################################################
47
48 my $one = open_window;
49 cmd 'mark foo';
50
51 is_deeply(get_marks(), ["foo"], 'mark foo set');
52
53 cmd 'unmark foo';
54
55 is_deeply(get_marks(), [], 'mark foo removed');
56
57 ##############################################################
58 # 3: mark three cons, check that they are marked
59 #    unmark one con, check that it's unmarked
60 #    unmark all cons, check that they are unmarked
61 ##############################################################
62
63 my $left = open_window;
64 my $middle = open_window;
65 my $right = open_window;
66
67 cmd 'mark right';
68 cmd 'focus left';
69 cmd 'mark middle';
70 cmd 'focus left';
71 cmd 'mark left';
72
73 #
74 # get_marks replys an array of marks, whose order is undefined,
75 # so we use sort to be able to compare the output
76 #
77
78 is_deeply(sort(get_marks()), ["left","middle","right"], 'all three marks set');
79
80 cmd 'unmark right';
81
82 is_deeply(sort(get_marks()), ["left","middle"], 'mark right removed');
83
84 cmd 'unmark';
85
86 is_deeply(get_marks(), [], 'all marks removed');
87
88 ##############################################################
89 # 4: mark a con, use same mark to mark another con,
90 #    check that only the latter is marked
91 ##############################################################
92
93 $first = open_window;
94 $second = open_window;
95
96 cmd 'mark important';
97 cmd 'focus left';
98 cmd 'mark important';
99
100 is_deeply(get_mark_for_window_on_workspace($tmp, $first), [ 'important' ], 'first container now has the mark');
101 ok(!get_mark_for_window_on_workspace($tmp, $second), 'second container lost the mark');
102
103 ##############################################################
104 # 5: mark a con, toggle the mark, check that the mark is gone
105 ##############################################################
106
107 $con = open_window;
108 cmd 'mark important';
109 cmd 'mark --toggle important';
110 ok(!get_mark_for_window_on_workspace($tmp, $con), 'container no longer has the mark');
111
112 ##############################################################
113 # 6: toggle a mark on an unmarked con, check it is marked
114 ##############################################################
115
116 $con = open_window;
117 cmd 'mark --toggle important';
118 is_deeply(get_mark_for_window_on_workspace($tmp, $con), [ 'important' ], 'container now has the mark');
119
120 ##############################################################
121 # 7: mark a con, toggle a different mark, check it is marked
122 #    with the new mark
123 ##############################################################
124
125 $con = open_window;
126 cmd 'mark boring';
127 cmd 'mark --replace --toggle important';
128 is_deeply(get_mark_for_window_on_workspace($tmp, $con), [ 'important' ], 'container has the most recent mark');
129
130 ##############################################################
131 # 8: mark a con, toggle the mark on another con,
132 #    check only the latter has the mark
133 ##############################################################
134
135 $first = open_window;
136 $second = open_window;
137
138 cmd 'mark important';
139 cmd 'focus left';
140 cmd 'mark --toggle important';
141
142 is_deeply(get_mark_for_window_on_workspace($tmp, $first), [ 'important' ], 'left container has the mark now');
143 ok(!get_mark_for_window_on_workspace($tmp, $second), 'second containr no longer has the mark');
144
145 ##############################################################
146 # 9: try to mark two cons with the same mark and check that
147 #    it fails
148 ##############################################################
149
150 $first = open_window(wm_class => 'iamnotunique');
151 $second = open_window(wm_class => 'iamnotunique');
152
153 my $result = cmd "[instance=iamnotunique] mark important";
154
155 is($result->[0]->{success}, 0, 'command was unsuccessful');
156 is($result->[0]->{error}, 'A mark must not be put onto more than one window', 'correct error is returned');
157 ok(!get_mark_for_window_on_workspace($tmp, $first), 'first container is not marked');
158 ok(!get_mark_for_window_on_workspace($tmp, $second), 'second containr is not marked');
159
160 ##############################################################
161
162 done_testing;