зеркало из https://github.com/github/ruby.git
[PRISM] Match style for invalid encoding error
This commit is contained in:
Родитель
eb995a6410
Коммит
ab2ee308aa
|
@ -8385,7 +8385,30 @@ pm_parse_process_error(const pm_parse_result_t *result)
|
|||
// over as the only argument that gets raised. This is to allow priority
|
||||
// messages that should be handled before anything else.
|
||||
if (error->level == PM_ERROR_LEVEL_ARGUMENT) {
|
||||
return rb_exc_new(rb_eArgError, error->message, strlen(error->message));
|
||||
int32_t line_number = (int32_t) pm_location_line_number(parser, &error->location);
|
||||
|
||||
pm_buffer_append_format(
|
||||
&buffer,
|
||||
"%.*s:%" PRIi32 ": %s",
|
||||
(int) pm_string_length(filepath),
|
||||
pm_string_source(filepath),
|
||||
line_number,
|
||||
error->message
|
||||
);
|
||||
|
||||
if (pm_parse_process_error_utf8_p(parser, &error->location)) {
|
||||
pm_buffer_append_byte(&buffer, '\n');
|
||||
|
||||
pm_list_node_t *list_node = (pm_list_node_t *) error;
|
||||
pm_list_t error_list = { .size = 1, .head = list_node, .tail = list_node };
|
||||
|
||||
pm_parser_errors_format(parser, &error_list, &buffer, rb_stderr_tty_p(), false);
|
||||
}
|
||||
|
||||
VALUE arg_error = rb_exc_new(rb_eArgError, pm_buffer_value(&buffer), pm_buffer_length(&buffer));
|
||||
pm_buffer_free(&buffer);
|
||||
|
||||
return arg_error;
|
||||
}
|
||||
|
||||
// It is implicitly assumed that the error messages will be encodeable
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
exclude(:test_assign_in_conditional, "missing warning")
|
||||
exclude(:test_magic_comment, "incorrect encoding")
|
||||
exclude(:test_shareable_constant_value_nested, "ractor support")
|
||||
exclude(:test_shareable_constant_value_nonliteral, "ractor support")
|
||||
exclude(:test_shareable_constant_value_simple, "ractor support")
|
||||
|
|
|
@ -803,14 +803,20 @@ x = __ENCODING__
|
|||
# coding: foo
|
||||
END
|
||||
end
|
||||
assert_include(e.message, "# coding: foo\n ^~~")
|
||||
|
||||
message = e.message.gsub(/\033\[.*?m/, "")
|
||||
assert_include(message, "# coding: foo\n")
|
||||
assert_include(message, " ^")
|
||||
|
||||
e = assert_raise(ArgumentError) do
|
||||
eval <<-END, nil, __FILE__, __LINE__+1
|
||||
# coding = foo
|
||||
END
|
||||
end
|
||||
assert_include(e.message, "# coding = foo\n ^~~")
|
||||
|
||||
message = e.message.gsub(/\033\[.*?m/, "")
|
||||
assert_include(message, "# coding = foo\n")
|
||||
assert_include(message, " ^")
|
||||
end
|
||||
|
||||
def test_utf8_bom
|
||||
|
|
Загрузка…
Ссылка в новой задаче