Added test cases for 'mark --toggle' (#1463)
This commit is contained in:
parent
47222ab261
commit
7a75cb7e0b
|
@ -1061,11 +1061,12 @@ void cmd_mark(I3_CMD, char *mark, char *toggle) {
|
||||||
TAILQ_FOREACH(con, &all_cons, all_cons) {
|
TAILQ_FOREACH(con, &all_cons, all_cons) {
|
||||||
/* Skip matched windows, we took care of them already. */
|
/* Skip matched windows, we took care of them already. */
|
||||||
bool matched = false;
|
bool matched = false;
|
||||||
TAILQ_FOREACH(current, &owindows, owindows)
|
TAILQ_FOREACH(current, &owindows, owindows) {
|
||||||
if (current->con == con) {
|
if (current->con == con) {
|
||||||
matched = true;
|
matched = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (matched)
|
if (matched)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
|
@ -16,11 +16,19 @@
|
||||||
#
|
#
|
||||||
# checks if mark and unmark work correctly
|
# checks if mark and unmark work correctly
|
||||||
use i3test;
|
use i3test;
|
||||||
|
use List::Util qw(first);
|
||||||
|
|
||||||
sub get_marks {
|
sub get_marks {
|
||||||
return i3(get_socket_path())->get_marks->recv;
|
return i3(get_socket_path())->get_marks->recv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub get_mark_for_window_on_workspace {
|
||||||
|
my ($ws, $con) = @_;
|
||||||
|
|
||||||
|
my $current = first { $_->{window} == $con->{id} } @{get_ws_content($ws)};
|
||||||
|
return $current->{mark};
|
||||||
|
}
|
||||||
|
|
||||||
##############################################################
|
##############################################################
|
||||||
# 1: check that there are no marks set yet
|
# 1: check that there are no marks set yet
|
||||||
##############################################################
|
##############################################################
|
||||||
|
@ -76,4 +84,61 @@ cmd 'unmark';
|
||||||
|
|
||||||
is_deeply(get_marks(), [], 'all marks removed');
|
is_deeply(get_marks(), [], 'all marks removed');
|
||||||
|
|
||||||
|
##############################################################
|
||||||
|
# 4: mark a con, use same mark to mark another con,
|
||||||
|
# check that only the latter is marked
|
||||||
|
##############################################################
|
||||||
|
|
||||||
|
my $first = open_window;
|
||||||
|
my $second = open_window;
|
||||||
|
|
||||||
|
cmd 'mark important';
|
||||||
|
cmd 'focus left';
|
||||||
|
cmd 'mark important';
|
||||||
|
|
||||||
|
is(get_mark_for_window_on_workspace($tmp, $first), 'important', 'first container now has the mark');
|
||||||
|
ok(!get_mark_for_window_on_workspace($tmp, $second), 'second container lost the mark');
|
||||||
|
|
||||||
|
##############################################################
|
||||||
|
# 5: mark a con, toggle the mark, check that the mark is gone
|
||||||
|
##############################################################
|
||||||
|
|
||||||
|
my $con = open_window;
|
||||||
|
cmd 'mark important';
|
||||||
|
cmd 'mark --toggle important';
|
||||||
|
ok(!get_mark_for_window_on_workspace($tmp, $con), 'container no longer has the mark');
|
||||||
|
|
||||||
|
##############################################################
|
||||||
|
# 6: toggle a mark on an unmarked con, check it is marked
|
||||||
|
##############################################################
|
||||||
|
|
||||||
|
my $con = open_window;
|
||||||
|
cmd 'mark --toggle important';
|
||||||
|
is(get_mark_for_window_on_workspace($tmp, $con), 'important', 'container now has the mark');
|
||||||
|
|
||||||
|
##############################################################
|
||||||
|
# 7: mark a con, toggle a different mark, check it is marked
|
||||||
|
# with the new mark
|
||||||
|
##############################################################
|
||||||
|
|
||||||
|
my $con = open_window;
|
||||||
|
cmd 'mark boring';
|
||||||
|
cmd 'mark --toggle important';
|
||||||
|
is(get_mark_for_window_on_workspace($tmp, $con), 'important', 'container has the most recent mark');
|
||||||
|
|
||||||
|
##############################################################
|
||||||
|
# 8: mark a con, toggle the mark on another con,
|
||||||
|
# check only the latter has the mark
|
||||||
|
##############################################################
|
||||||
|
|
||||||
|
my $first = open_window;
|
||||||
|
my $second = open_window;
|
||||||
|
|
||||||
|
cmd 'mark important';
|
||||||
|
cmd 'focus left';
|
||||||
|
cmd 'mark --toggle important';
|
||||||
|
|
||||||
|
is(get_mark_for_window_on_workspace($tmp, $first), 'important', 'left container has the mark now');
|
||||||
|
ok(!get_mark_for_window_on_workspace($tmp, $second), 'second containr no longer has the mark');
|
||||||
|
|
||||||
done_testing;
|
done_testing;
|
||||||
|
|
Loading…
Reference in New Issue