put common part of error messages into variable

This makes future changes easier when new tokens are added to the
parser.
This commit is contained in:
Sascha Kruse 2013-01-28 16:36:38 +01:00 committed by Michael Stapelberg
parent 23078f6ded
commit 0a0d66dc8a
1 changed files with 24 additions and 11 deletions

View File

@ -391,8 +391,11 @@ hide_edge_border both
client.focused #4c7899 #285577 #ffffff #2e9ef4 client.focused #4c7899 #285577 #ffffff #2e9ef4
EOT EOT
$expected = <<'EOT'; my $expected_all_tokens = <<'EOT';
ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'bindsym', 'bindcode', 'bind', 'bar', 'font', 'mode', 'floating_minimum_size', 'floating_maximum_size', 'floating_modifier', 'default_orientation', 'workspace_layout', 'new_window', 'new_float', 'hide_edge_borders', 'for_window', 'assign', 'focus_follows_mouse', 'force_focus_wrapping', 'force_xinerama', 'force-xinerama', 'workspace_auto_back_and_forth', 'fake_outputs', 'fake-outputs', 'force_display_urgency_hint', 'workspace', 'ipc_socket', 'ipc-socket', 'restart_state', 'popup_during_fullscreen', 'exec_always', 'exec', 'client.background', 'client.focused_inactive', 'client.focused', 'client.unfocused', 'client.urgent' ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'bindsym', 'bindcode', 'bind', 'bar', 'font', 'mode', 'floating_minimum_size', 'floating_maximum_size', 'floating_modifier', 'default_orientation', 'workspace_layout', 'new_window', 'new_float', 'hide_edge_borders', 'for_window', 'assign', 'focus_follows_mouse', 'force_focus_wrapping', 'force_xinerama', 'force-xinerama', 'workspace_auto_back_and_forth', 'fake_outputs', 'fake-outputs', 'force_display_urgency_hint', 'workspace', 'ipc_socket', 'ipc-socket', 'restart_state', 'popup_during_fullscreen', 'exec_always', 'exec', 'client.background', 'client.focused_inactive', 'client.focused', 'client.unfocused', 'client.urgent'
EOT
my $expected_end = <<'EOT';
ERROR: CONFIG: (in file <stdin>) ERROR: CONFIG: (in file <stdin>)
ERROR: CONFIG: Line 1: hide_edge_border both ERROR: CONFIG: Line 1: hide_edge_border both
ERROR: CONFIG: ^^^^^^^^^^^^^^^^^^^^^ ERROR: CONFIG: ^^^^^^^^^^^^^^^^^^^^^
@ -400,6 +403,8 @@ ERROR: CONFIG: Line 2: client.focused #4c7899 #285577 #ffffff #2e9ef4
cfg_color(client.focused, #4c7899, #285577, #ffffff, #2e9ef4) cfg_color(client.focused, #4c7899, #285577, #ffffff, #2e9ef4)
EOT EOT
$expected = $expected_all_tokens . $expected_end;
is(parser_calls($config), is(parser_calls($config),
$expected, $expected,
'errors dont harm subsequent statements'); 'errors dont harm subsequent statements');
@ -438,9 +443,11 @@ unknown qux
# this should not show up # this should not show up
EOT EOT
$expected = <<'EOT'; my $expected_head = <<'EOT';
cfg_font(foobar) cfg_font(foobar)
ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'bindsym', 'bindcode', 'bind', 'bar', 'font', 'mode', 'floating_minimum_size', 'floating_maximum_size', 'floating_modifier', 'default_orientation', 'workspace_layout', 'new_window', 'new_float', 'hide_edge_borders', 'for_window', 'assign', 'focus_follows_mouse', 'force_focus_wrapping', 'force_xinerama', 'force-xinerama', 'workspace_auto_back_and_forth', 'fake_outputs', 'fake-outputs', 'force_display_urgency_hint', 'workspace', 'ipc_socket', 'ipc-socket', 'restart_state', 'popup_during_fullscreen', 'exec_always', 'exec', 'client.background', 'client.focused_inactive', 'client.focused', 'client.unfocused', 'client.urgent' EOT
my $expected_tail = <<'EOT';
ERROR: CONFIG: (in file <stdin>) ERROR: CONFIG: (in file <stdin>)
ERROR: CONFIG: Line 3: font foobar ERROR: CONFIG: Line 3: font foobar
ERROR: CONFIG: Line 4: ERROR: CONFIG: Line 4:
@ -450,6 +457,8 @@ ERROR: CONFIG: Line 6:
ERROR: CONFIG: Line 7: # yay ERROR: CONFIG: Line 7: # yay
EOT EOT
$expected = $expected_head . $expected_all_tokens . $expected_tail;
is(parser_calls($config), is(parser_calls($config),
$expected, $expected,
'error message (2+2 context) ok'); 'error message (2+2 context) ok');
@ -462,13 +471,14 @@ $config = <<'EOT';
unknown qux unknown qux
EOT EOT
$expected = <<'EOT'; $expected_tail = <<'EOT';
ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'bindsym', 'bindcode', 'bind', 'bar', 'font', 'mode', 'floating_minimum_size', 'floating_maximum_size', 'floating_modifier', 'default_orientation', 'workspace_layout', 'new_window', 'new_float', 'hide_edge_borders', 'for_window', 'assign', 'focus_follows_mouse', 'force_focus_wrapping', 'force_xinerama', 'force-xinerama', 'workspace_auto_back_and_forth', 'fake_outputs', 'fake-outputs', 'force_display_urgency_hint', 'workspace', 'ipc_socket', 'ipc-socket', 'restart_state', 'popup_during_fullscreen', 'exec_always', 'exec', 'client.background', 'client.focused_inactive', 'client.focused', 'client.unfocused', 'client.urgent'
ERROR: CONFIG: (in file <stdin>) ERROR: CONFIG: (in file <stdin>)
ERROR: CONFIG: Line 1: unknown qux ERROR: CONFIG: Line 1: unknown qux
ERROR: CONFIG: ^^^^^^^^^^^ ERROR: CONFIG: ^^^^^^^^^^^
EOT EOT
$expected = $expected_all_tokens . $expected_tail;
is(parser_calls($config), is(parser_calls($config),
$expected, $expected,
'error message (0+0 context) ok'); 'error message (0+0 context) ok');
@ -482,14 +492,15 @@ $config = <<'EOT';
unknown qux unknown qux
EOT EOT
$expected = <<'EOT'; $expected_tail = <<'EOT';
ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'bindsym', 'bindcode', 'bind', 'bar', 'font', 'mode', 'floating_minimum_size', 'floating_maximum_size', 'floating_modifier', 'default_orientation', 'workspace_layout', 'new_window', 'new_float', 'hide_edge_borders', 'for_window', 'assign', 'focus_follows_mouse', 'force_focus_wrapping', 'force_xinerama', 'force-xinerama', 'workspace_auto_back_and_forth', 'fake_outputs', 'fake-outputs', 'force_display_urgency_hint', 'workspace', 'ipc_socket', 'ipc-socket', 'restart_state', 'popup_during_fullscreen', 'exec_always', 'exec', 'client.background', 'client.focused_inactive', 'client.focused', 'client.unfocused', 'client.urgent'
ERROR: CONFIG: (in file <stdin>) ERROR: CONFIG: (in file <stdin>)
ERROR: CONFIG: Line 1: # context before ERROR: CONFIG: Line 1: # context before
ERROR: CONFIG: Line 2: unknown qux ERROR: CONFIG: Line 2: unknown qux
ERROR: CONFIG: ^^^^^^^^^^^ ERROR: CONFIG: ^^^^^^^^^^^
EOT EOT
$expected = $expected_all_tokens . $expected_tail;
is(parser_calls($config), is(parser_calls($config),
$expected, $expected,
'error message (1+0 context) ok'); 'error message (1+0 context) ok');
@ -503,14 +514,15 @@ unknown qux
# context after # context after
EOT EOT
$expected = <<'EOT'; $expected_tail = <<'EOT';
ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'bindsym', 'bindcode', 'bind', 'bar', 'font', 'mode', 'floating_minimum_size', 'floating_maximum_size', 'floating_modifier', 'default_orientation', 'workspace_layout', 'new_window', 'new_float', 'hide_edge_borders', 'for_window', 'assign', 'focus_follows_mouse', 'force_focus_wrapping', 'force_xinerama', 'force-xinerama', 'workspace_auto_back_and_forth', 'fake_outputs', 'fake-outputs', 'force_display_urgency_hint', 'workspace', 'ipc_socket', 'ipc-socket', 'restart_state', 'popup_during_fullscreen', 'exec_always', 'exec', 'client.background', 'client.focused_inactive', 'client.focused', 'client.unfocused', 'client.urgent'
ERROR: CONFIG: (in file <stdin>) ERROR: CONFIG: (in file <stdin>)
ERROR: CONFIG: Line 1: unknown qux ERROR: CONFIG: Line 1: unknown qux
ERROR: CONFIG: ^^^^^^^^^^^ ERROR: CONFIG: ^^^^^^^^^^^
ERROR: CONFIG: Line 2: # context after ERROR: CONFIG: Line 2: # context after
EOT EOT
$expected = $expected_all_tokens . $expected_tail;
is(parser_calls($config), is(parser_calls($config),
$expected, $expected,
'error message (0+1 context) ok'); 'error message (0+1 context) ok');
@ -525,8 +537,7 @@ unknown qux
# context 2 after # context 2 after
EOT EOT
$expected = <<'EOT'; $expected_tail = <<'EOT';
ERROR: CONFIG: Expected one of these tokens: <end>, '#', 'set', 'bindsym', 'bindcode', 'bind', 'bar', 'font', 'mode', 'floating_minimum_size', 'floating_maximum_size', 'floating_modifier', 'default_orientation', 'workspace_layout', 'new_window', 'new_float', 'hide_edge_borders', 'for_window', 'assign', 'focus_follows_mouse', 'force_focus_wrapping', 'force_xinerama', 'force-xinerama', 'workspace_auto_back_and_forth', 'fake_outputs', 'fake-outputs', 'force_display_urgency_hint', 'workspace', 'ipc_socket', 'ipc-socket', 'restart_state', 'popup_during_fullscreen', 'exec_always', 'exec', 'client.background', 'client.focused_inactive', 'client.focused', 'client.unfocused', 'client.urgent'
ERROR: CONFIG: (in file <stdin>) ERROR: CONFIG: (in file <stdin>)
ERROR: CONFIG: Line 1: unknown qux ERROR: CONFIG: Line 1: unknown qux
ERROR: CONFIG: ^^^^^^^^^^^ ERROR: CONFIG: ^^^^^^^^^^^
@ -534,6 +545,8 @@ ERROR: CONFIG: Line 2: # context after
ERROR: CONFIG: Line 3: # context 2 after ERROR: CONFIG: Line 3: # context 2 after
EOT EOT
$expected = $expected_all_tokens . $expected_tail;
is(parser_calls($config), is(parser_calls($config),
$expected, $expected,
'error message (0+2 context) ok'); 'error message (0+2 context) ok');