зеркало из https://github.com/github/ruby.git
Update duplicated when clause warning message
This commit is contained in:
Родитель
7021e15652
Коммит
47f0965269
4
parse.y
4
parse.y
|
@ -13334,8 +13334,8 @@ check_literal_when(struct parser_params *p, NODE *arg, const YYLTYPE *loc)
|
|||
else {
|
||||
st_data_t line;
|
||||
if (st_lookup(p->case_labels, (st_data_t)arg, &line)) {
|
||||
rb_warning1("duplicated 'when' clause with line %d is ignored",
|
||||
WARN_I((int)line));
|
||||
rb_warning2("'when' clause on line %d duplicates 'when' clause on line %d and is ignored",
|
||||
WARN_I((int)nd_line(arg)), WARN_I((int)line));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -416,17 +416,34 @@ describe "The 'case'-construct" do
|
|||
self.test(true).should == true
|
||||
end
|
||||
|
||||
it "warns if there are identical when clauses" do
|
||||
-> {
|
||||
eval <<~RUBY
|
||||
case 1
|
||||
when 2
|
||||
:foo
|
||||
when 2
|
||||
:bar
|
||||
end
|
||||
RUBY
|
||||
}.should complain(/warning: duplicated .when' clause with line \d+ is ignored/, verbose: true)
|
||||
ruby_version_is ""..."3.4" do
|
||||
it "warns if there are identical when clauses" do
|
||||
-> {
|
||||
eval <<~RUBY
|
||||
case 1
|
||||
when 2
|
||||
:foo
|
||||
when 2
|
||||
:bar
|
||||
end
|
||||
RUBY
|
||||
}.should complain(/warning: duplicated .when' clause with line \d+ is ignored/, verbose: true)
|
||||
end
|
||||
end
|
||||
|
||||
ruby_version_is "3.4" do
|
||||
it "warns if there are identical when clauses" do
|
||||
-> {
|
||||
eval <<~RUBY
|
||||
case 1
|
||||
when 2
|
||||
:foo
|
||||
when 2
|
||||
:bar
|
||||
end
|
||||
RUBY
|
||||
}.should complain(/warning: 'when' clause on line \d+ duplicates 'when' clause on line \d+ and is ignored/, verbose: true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
exclude(:test_dedented_heredoc_continued_line, "https://bugs.ruby-lang.org/issues/20503")
|
||||
exclude(:test_duplicated_when, "https://bugs.ruby-lang.org/issues/20401")
|
||||
exclude(:test_optional_self_reference, "https://bugs.ruby-lang.org/issues/20478")
|
||||
exclude(:test_keyword_self_reference, "https://bugs.ruby-lang.org/issues/20478")
|
||||
|
|
|
@ -1694,8 +1694,8 @@ class TestRipper::ParserEvents < Test::Unit::TestCase
|
|||
else
|
||||
end
|
||||
STR
|
||||
assert_match(/duplicated 'when' clause/, fmt)
|
||||
assert_equal([3], args)
|
||||
assert_match(/duplicates 'when' clause/, fmt)
|
||||
assert_equal([4, 3], args)
|
||||
end
|
||||
|
||||
def test_warn_duplicated_hash_keys
|
||||
|
|
|
@ -713,8 +713,8 @@ class TestSyntax < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_duplicated_when
|
||||
w = 'warning: duplicated \'when\' clause with line 3 is ignored'
|
||||
assert_warning(/3: #{w}.+4: #{w}.+4: #{w}.+5: #{w}.+5: #{w}/m) {
|
||||
w = ->(line) { "warning: 'when' clause on line #{line} duplicates 'when' clause on line 3 and is ignored" }
|
||||
assert_warning(/#{w[3]}.+#{w[4]}.+#{w[4]}.+#{w[5]}.+#{w[5]}/m) {
|
||||
eval %q{
|
||||
case 1
|
||||
when 1, 1
|
||||
|
@ -723,7 +723,7 @@ class TestSyntax < Test::Unit::TestCase
|
|||
end
|
||||
}
|
||||
}
|
||||
assert_warning(/#{w}/) {#/3: #{w}.+4: #{w}.+5: #{w}.+5: #{w}/m){
|
||||
assert_warning(/#{w[3]}.+#{w[4]}.+#{w[5]}.+#{w[5]}/m) {
|
||||
a = a = 1
|
||||
eval %q{
|
||||
case 1
|
||||
|
@ -733,7 +733,7 @@ class TestSyntax < Test::Unit::TestCase
|
|||
end
|
||||
}
|
||||
}
|
||||
assert_warning(/3: #{w}/m) {
|
||||
assert_warning(/#{w[3]}/) {
|
||||
eval %q{
|
||||
case 1
|
||||
when __LINE__, __LINE__
|
||||
|
@ -742,7 +742,7 @@ class TestSyntax < Test::Unit::TestCase
|
|||
end
|
||||
}
|
||||
}
|
||||
assert_warning(/3: #{w}/m) {
|
||||
assert_warning(/#{w[3]}/) {
|
||||
eval %q{
|
||||
case 1
|
||||
when __FILE__, __FILE__
|
||||
|
@ -754,7 +754,7 @@ class TestSyntax < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_duplicated_when_check_option
|
||||
w = /duplicated \'when\' clause with line 3 is ignored/
|
||||
w = /'when' clause on line 4 duplicates 'when' clause on line 3 and is ignored/
|
||||
assert_in_out_err(%[-wc], "#{<<~"begin;"}\n#{<<~'end;'}", ["Syntax OK"], w)
|
||||
begin;
|
||||
case 1
|
||||
|
|
Загрузка…
Ссылка в новой задаче