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' 2>&-);
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 # The first call has only a single command, the following ones are consolidated
33 is(parser_calls('move workspace 3'),
34 'cmd_move_con_to_workspace_name(3)',
35 'single number (move workspace 3) ok');
38 'move to workspace 3; ' .
39 'move window to workspace 3; ' .
40 'move container to workspace 3; ' .
41 'move workspace foobar; ' .
42 'move workspace 3: foobar; ' .
43 'move workspace "3: foobar"; ' .
44 'move workspace "3: foobar, baz"; '),
45 "cmd_move_con_to_workspace_name(3)\n" .
46 "cmd_move_con_to_workspace_name(3)\n" .
47 "cmd_move_con_to_workspace_name(3)\n" .
48 "cmd_move_con_to_workspace_name(foobar)\n" .
49 "cmd_move_con_to_workspace_name(3: foobar)\n" .
50 "cmd_move_con_to_workspace_name(3: foobar)\n" .
51 "cmd_move_con_to_workspace_name(3: foobar, baz)",
54 is(parser_calls('move workspace 3: foobar, nop foo'),
55 "cmd_move_con_to_workspace_name(3: foobar)\n" .
57 'multiple ops (move workspace 3: foobar, nop foo) ok');
60 'exec i3-sensible-terminal; ' .
61 'exec --no-startup-id i3-sensible-terminal'),
62 "cmd_exec((null), i3-sensible-terminal)\n" .
63 "cmd_exec(--no-startup-id, i3-sensible-terminal)",
67 'resize shrink left; ' .
68 'resize shrink left 25 px; ' .
69 'resize shrink left 25 px or 33 ppt; ' .
70 'resize shrink left 25'),
71 "cmd_resize(shrink, left, 10, 10)\n" .
72 "cmd_resize(shrink, left, 25, 10)\n" .
73 "cmd_resize(shrink, left, 25, 33)\n" .
74 "cmd_resize(shrink, left, 25, 10)",
77 is(parser_calls('resize shrink left 25 px or 33 ppt,'),
78 'cmd_resize(shrink, left, 25, 33)',
79 'trailing comma resize ok');
81 is(parser_calls('resize shrink left 25 px or 33 ppt;'),
82 'cmd_resize(shrink, left, 25, 33)',
83 'trailing semicolon resize ok');
85 is(parser_calls('[con_mark=yay] focus'),
86 "cmd_criteria_add(con_mark, yay)\n" .
90 is(parser_calls("[con_mark=yay con_mark=bar] focus"),
91 "cmd_criteria_add(con_mark, yay)\n" .
92 "cmd_criteria_add(con_mark, bar)\n" .
96 is(parser_calls("[con_mark=yay\tcon_mark=bar] focus"),
97 "cmd_criteria_add(con_mark, yay)\n" .
98 "cmd_criteria_add(con_mark, bar)\n" .
100 'criteria focus ok');
102 is(parser_calls("[con_mark=yay\tcon_mark=bar]\tfocus"),
103 "cmd_criteria_add(con_mark, yay)\n" .
104 "cmd_criteria_add(con_mark, bar)\n" .
106 'criteria focus ok');
108 is(parser_calls('[con_mark="yay"] focus'),
109 "cmd_criteria_add(con_mark, yay)\n" .
111 'quoted criteria focus ok');
113 # Make sure trailing whitespace is stripped off: While this is not an issue for
114 # commands being parsed due to the configuration, people might send IPC
115 # commands with leading or trailing newlines.
116 is(parser_calls("workspace test\n"),
117 'cmd_workspace_name(test)',
118 'trailing whitespace stripped off ok');
120 is(parser_calls("\nworkspace test"),
121 'cmd_workspace_name(test)',
122 'trailing whitespace stripped off ok');
124 ################################################################################
125 # 2: Verify that the parser spits out the right error message on commands which
127 ################################################################################
129 is(parser_calls('unknown_literal'),
130 "Expected one of these tokens: <end>, '[', 'move', 'exec', 'exit', 'restart', 'reload', 'border', 'layout', 'append_layout', 'workspace', 'focus', 'kill', 'open', 'fullscreen', 'split', 'floating', 'mark', 'resize', 'rename', 'nop', 'scratchpad', 'mode'\n" .
131 "Your command: unknown_literal\n" .
133 'error for unknown literal ok');
135 is(parser_calls('move something to somewhere'),
136 "Expected one of these tokens: 'window', 'container', 'to', 'workspace', 'output', 'scratchpad', 'left', 'right', 'up', 'down', 'position', 'absolute'\n" .
137 "Your command: move something to somewhere\n" .
138 " ^^^^^^^^^^^^^^^^^^^^^^",
139 'error for unknown literal ok');
141 ################################################################################
142 # 3: Verify that escaping of double quotes works correctly
143 ################################################################################
145 is(parser_calls('workspace "foo"'),
146 'cmd_workspace_name(foo)',
147 'Command with simple double quotes ok');
149 is(parser_calls('workspace "foo'),
150 'cmd_workspace_name(foo)',
151 'Command without ending double quotes ok');
153 is(parser_calls('workspace "foo \"bar"'),
154 'cmd_workspace_name(foo "bar)',
155 'Command with escaped double quotes ok');