2 # vim:ts=4:sw=4:expandtab
4 # Tests the standalone parser binary to see if it calls the right code when
5 # confronted with various commands, if it prints proper error messages for
6 # wrong commands and if it terminates in every case.
8 use i3test i3_autostart => 0;
13 # TODO: use a timeout, so that we can error out if it doesn’t terminate
14 # TODO: better way of passing arguments
15 my $stdout = qx(../test.commands_parser '$command');
17 # Filter out all debugging output.
18 my @lines = split("\n", $stdout);
19 @lines = grep { not /^# / } @lines;
21 # The criteria management calls are irrelevant and not what we want to test
23 @lines = grep { !(/cmd_criteria_init()/ || /cmd_criteria_match_windows/) } @lines;
24 return join("\n", @lines);
27 ################################################################################
28 # 1: First that the parser properly recognizes commands which are ok.
29 ################################################################################
31 is(parser_calls('move workspace 3'),
32 'cmd_move_con_to_workspace_name(3)',
33 'single number (move workspace 3) ok');
35 is(parser_calls('move to workspace 3'),
36 'cmd_move_con_to_workspace_name(3)',
37 'to (move to workspace 3) ok');
39 is(parser_calls('move window to workspace 3'),
40 'cmd_move_con_to_workspace_name(3)',
41 'window to (move window to workspace 3) ok');
43 is(parser_calls('move container to workspace 3'),
44 'cmd_move_con_to_workspace_name(3)',
45 'container to (move container to workspace 3) ok');
47 is(parser_calls('move workspace foobar'),
48 'cmd_move_con_to_workspace_name(foobar)',
49 'single word (move workspace foobar) ok');
51 is(parser_calls('move workspace 3: foobar'),
52 'cmd_move_con_to_workspace_name(3: foobar)',
53 'multiple words (move workspace 3: foobar) ok');
55 is(parser_calls('move workspace "3: foobar"'),
56 'cmd_move_con_to_workspace_name(3: foobar)',
57 'double quotes (move workspace "3: foobar") ok');
59 is(parser_calls('move workspace "3: foobar, baz"'),
60 'cmd_move_con_to_workspace_name(3: foobar, baz)',
61 'quotes with comma (move workspace "3: foobar, baz") ok');
63 is(parser_calls('move workspace 3: foobar, nop foo'),
64 "cmd_move_con_to_workspace_name(3: foobar)\n" .
66 'multiple ops (move workspace 3: foobar, nop foo) ok');
68 is(parser_calls('exec i3-sensible-terminal'),
69 'cmd_exec((null), i3-sensible-terminal)',
72 is(parser_calls('exec --no-startup-id i3-sensible-terminal'),
73 'cmd_exec(--no-startup-id, i3-sensible-terminal)',
74 'exec --no-startup-id ok');
76 is(parser_calls('resize shrink left'),
77 'cmd_resize(shrink, left, 10, 10)',
80 is(parser_calls('resize shrink left 25 px'),
81 'cmd_resize(shrink, left, 25, 10)',
84 is(parser_calls('resize shrink left 25 px or 33 ppt'),
85 'cmd_resize(shrink, left, 25, 33)',
86 'px + ppt resize ok');
88 is(parser_calls('resize shrink left 25 px or 33 ppt'),
89 'cmd_resize(shrink, left, 25, 33)',
90 'px + ppt resize ok');
92 is(parser_calls('resize shrink left 25 px or 33 ppt,'),
93 'cmd_resize(shrink, left, 25, 33)',
94 'trailing comma resize ok');
96 is(parser_calls('resize shrink left 25 px or 33 ppt;'),
97 'cmd_resize(shrink, left, 25, 33)',
98 'trailing semicolon resize ok');
100 is(parser_calls('resize shrink left 25'),
101 'cmd_resize(shrink, left, 25, 10)',
102 'resize early end ok');
104 is(parser_calls('[con_mark=yay] focus'),
105 "cmd_criteria_add(con_mark, yay)\n" .
107 'criteria focus ok');
109 is(parser_calls("[con_mark=yay con_mark=bar] focus"),
110 "cmd_criteria_add(con_mark, yay)\n" .
111 "cmd_criteria_add(con_mark, bar)\n" .
113 'criteria focus ok');
115 is(parser_calls("[con_mark=yay\tcon_mark=bar] focus"),
116 "cmd_criteria_add(con_mark, yay)\n" .
117 "cmd_criteria_add(con_mark, bar)\n" .
119 'criteria focus ok');
121 is(parser_calls("[con_mark=yay\tcon_mark=bar]\tfocus"),
122 "cmd_criteria_add(con_mark, yay)\n" .
123 "cmd_criteria_add(con_mark, bar)\n" .
125 'criteria focus ok');
127 is(parser_calls('[con_mark="yay"] focus'),
128 "cmd_criteria_add(con_mark, yay)\n" .
130 'quoted criteria focus ok');
132 ################################################################################
133 # 2: Verify that the parser spits out the right error message on commands which
135 ################################################################################
137 is(parser_calls('unknown_literal'),
138 "Expected one of these tokens: <end>, '[', 'move', 'exec', 'exit', 'restart', 'reload', 'border', 'layout', 'append_layout', 'workspace', 'focus', 'kill', 'open', 'fullscreen', 'split', 'floating', 'mark', 'resize', 'nop', 'scratchpad', 'mode'\n" .
139 "Your command: unknown_literal\n" .
141 'error for unknown literal ok');
143 is(parser_calls('move something to somewhere'),
144 "Expected one of these tokens: 'window', 'container', 'to', 'workspace', 'output', 'scratchpad', 'left', 'right', 'up', 'down'\n" .
145 "Your command: move something to somewhere\n" .
146 " ^^^^^^^^^^^^^^^^^^^^^^",
147 'error for unknown literal ok');