]> git.sur5r.net Git - i3/i3/blob - testcases/t/302-tree.t
Merge pull request #3665 from lasers/add-markup
[i3/i3] / testcases / t / 302-tree.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 # Contains various tests that use the cmp_tree subroutine.
18 # Ticket: #3503
19 use i3test;
20
21 sub sanity_check {
22     local $Test::Builder::Level = $Test::Builder::Level + 1;
23
24     my ($layout, $focus_idx) = @_;
25     my @windows = cmp_tree(
26         msg => 'Sanity check',
27         layout_before => $layout,
28         layout_after => $layout);
29     is($x->input_focus, $windows[$focus_idx]->id, 'Correct window focused') if $focus_idx >= 0;
30 }
31
32 sanity_check('H[ V[ a* V[ b c ] d ] e ]', 0);
33 sanity_check('H[ a b c d* ]', 3);
34 sanity_check('V[a b] V[c d*]', 3);
35 sanity_check('T[a b] S[c*]', 2);
36
37 cmp_tree(
38     msg => 'Simple focus test',
39     layout_before => 'H[a b] V[c* d]',
40     layout_after => 'H[a* b] V[c d]',
41     cb => sub {
42         cmd '[class=a] focus';
43     });
44
45 cmp_tree(
46     msg => 'Simple move test',
47     layout_before => 'H[a b] V[c* d]',
48     layout_after => 'H[a b] V[d c*]',
49     cb => sub {
50         cmd 'move down';
51     });
52
53 cmp_tree(
54     msg => 'Move from horizontal to vertical',
55     layout_before => 'H[a b] V[c d*]',
56     layout_after => 'H[b] V[c d a*]',
57     cb => sub {
58         cmd '[class=a] focus';
59         cmd 'move right, move right';
60     });
61
62 cmp_tree(
63     msg => 'Move unfocused non-leaf container',
64     layout_before => 'S[a b] V[c d* T[e f g]]',
65     layout_after => 'S[a T[e f g] b] V[c d*]',
66     cb => sub {
67         cmd '[con_mark=T1] move up, move up, move left, move up';
68     });
69
70 cmp_tree(
71     msg => 'Simple swap test',
72     layout_before => 'H[a b] V[c d*]',
73     layout_after => 'H[a d*] V[c b]',
74     cb => sub {
75         cmd '[class=b] swap with id ' . $_[0][3]->{id};
76     });
77
78 cmp_tree(
79     msg => 'Swap non-leaf containers',
80     layout_before => 'S[a b] V[c d*]',
81     layout_after => 'V[c d*] S[a b]',
82     cb => sub {
83         cmd '[con_mark=S1] swap with mark V1';
84     });
85
86 cmp_tree(
87     msg => 'Swap nested non-leaf containers',
88     layout_before => 'S[a b] V[c d* T[e f g]]',
89     layout_after => 'T[e f g] V[c d* S[a b]]',
90     cb => sub {
91         cmd '[con_mark=S1] swap with mark T1';
92     });
93
94 done_testing;