aboutsummaryrefslogtreecommitdiff
path: root/testcases/t/119-match.t
blob: 65c41f1f1b39b822b97d5abd120e086778878b9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!perl
# vim:ts=4:sw=4:expandtab
#
# Please read the following documents before working on tests:
# • https://build.i3wm.org/docs/testsuite.html
#   (or docs/testsuite)
#
# • https://build.i3wm.org/docs/lib-i3test.html
#   (alternatively: perldoc ./testcases/lib/i3test.pm)
#
# • https://build.i3wm.org/docs/ipc.html
#   (or docs/ipc)
#
# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
#   (unless you are already familiar with Perl)
#
# Tests all kinds of matching methods
#
use i3test;

my $tmp = fresh_workspace;

ok(@{get_ws_content($tmp)} == 0, 'no containers yet');

# Open a new window
my $window = open_window;
my $content = get_ws_content($tmp);
ok(@{$content} == 1, 'window mapped');
my $win = $content->[0];

######################################################################
# first test that matches which should not match this window really do
# not match it
######################################################################
# TODO: specify more match types
# Try matching with an empty pattern since there isn't a WM_CLASS set.
cmd q|[con_id="99999"] kill|;

is_num_children($tmp, 1, 'window still there');

# now kill the window
cmd 'nop now killing the window';
my $id = $win->{id};
cmd qq|[con_id="$id"] kill|;

wait_for_unmap $window;

cmd 'nop checking if its gone';
is_num_children($tmp, 0, 'window killed');

# TODO: same test, but with pcre expressions

######################################################################
# check that multiple criteria work are checked with a logical AND,
# not a logical OR (that is, matching is not cancelled after the first
# criterion matches).
######################################################################

$tmp = fresh_workspace;

my $left = open_window(wm_class => 'special', name => 'left');
ok($left->mapped, 'left window mapped');

my $right = open_window(wm_class => 'special', name => 'right');
ok($right->mapped, 'right window mapped');

# two windows should be here
is_num_children($tmp, 2, 'two windows opened');

cmd '[class="special" title="left"] kill';

sync_with_i3;

is_num_children($tmp, 1, 'one window still there');

######################################################################
# check that regular expressions work
######################################################################

$tmp = fresh_workspace;

$left = open_window(name => 'left', wm_class => 'special7');
ok($left->mapped, 'left window mapped');
is_num_children($tmp, 1, 'window opened');

cmd '[class="^special[0-9]$"] kill';
wait_for_unmap $left;
is_num_children($tmp, 0, 'window killed');

######################################################################
# check that UTF-8 works when matching
######################################################################

$tmp = fresh_workspace;

$left = open_window(name => 'ä 3', wm_class => 'special7');
ok($left->mapped, 'left window mapped');
is_num_children($tmp, 1, 'window opened');

cmd '[title="^\w [3]$"] kill';
wait_for_unmap $left;
is_num_children($tmp, 0, 'window killed');

######################################################################
# check that we can match empty properties
######################################################################

$tmp = fresh_workspace;

$left = open_window(name => 'class is empty', wm_class => '');
ok($left->mapped, 'left window mapped');
is_num_children($tmp, 1, 'window opened');

cmd '[class="^$"] kill';
wait_for_unmap $left;
is_num_children($tmp, 0, 'window killed');

done_testing;