зеркало из 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 {
|
else {
|
||||||
st_data_t line;
|
st_data_t line;
|
||||||
if (st_lookup(p->case_labels, (st_data_t)arg, &line)) {
|
if (st_lookup(p->case_labels, (st_data_t)arg, &line)) {
|
||||||
rb_warning1("duplicated 'when' clause with line %d is ignored",
|
rb_warning2("'when' clause on line %d duplicates 'when' clause on line %d and is ignored",
|
||||||
WARN_I((int)line));
|
WARN_I((int)nd_line(arg)), WARN_I((int)line));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -416,17 +416,34 @@ describe "The 'case'-construct" do
|
||||||
self.test(true).should == true
|
self.test(true).should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "warns if there are identical when clauses" do
|
ruby_version_is ""..."3.4" do
|
||||||
-> {
|
it "warns if there are identical when clauses" do
|
||||||
eval <<~RUBY
|
-> {
|
||||||
case 1
|
eval <<~RUBY
|
||||||
when 2
|
case 1
|
||||||
:foo
|
when 2
|
||||||
when 2
|
:foo
|
||||||
:bar
|
when 2
|
||||||
end
|
:bar
|
||||||
RUBY
|
end
|
||||||
}.should complain(/warning: duplicated .when' clause with line \d+ is ignored/, verbose: true)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
exclude(:test_dedented_heredoc_continued_line, "https://bugs.ruby-lang.org/issues/20503")
|
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_optional_self_reference, "https://bugs.ruby-lang.org/issues/20478")
|
||||||
exclude(:test_keyword_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
|
else
|
||||||
end
|
end
|
||||||
STR
|
STR
|
||||||
assert_match(/duplicated 'when' clause/, fmt)
|
assert_match(/duplicates 'when' clause/, fmt)
|
||||||
assert_equal([3], args)
|
assert_equal([4, 3], args)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_warn_duplicated_hash_keys
|
def test_warn_duplicated_hash_keys
|
||||||
|
|
|
@ -713,8 +713,8 @@ class TestSyntax < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_duplicated_when
|
def test_duplicated_when
|
||||||
w = 'warning: duplicated \'when\' clause with line 3 is ignored'
|
w = ->(line) { "warning: 'when' clause on line #{line} duplicates 'when' clause on line 3 and is ignored" }
|
||||||
assert_warning(/3: #{w}.+4: #{w}.+4: #{w}.+5: #{w}.+5: #{w}/m) {
|
assert_warning(/#{w[3]}.+#{w[4]}.+#{w[4]}.+#{w[5]}.+#{w[5]}/m) {
|
||||||
eval %q{
|
eval %q{
|
||||||
case 1
|
case 1
|
||||||
when 1, 1
|
when 1, 1
|
||||||
|
@ -723,7 +723,7 @@ class TestSyntax < Test::Unit::TestCase
|
||||||
end
|
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
|
a = a = 1
|
||||||
eval %q{
|
eval %q{
|
||||||
case 1
|
case 1
|
||||||
|
@ -733,7 +733,7 @@ class TestSyntax < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert_warning(/3: #{w}/m) {
|
assert_warning(/#{w[3]}/) {
|
||||||
eval %q{
|
eval %q{
|
||||||
case 1
|
case 1
|
||||||
when __LINE__, __LINE__
|
when __LINE__, __LINE__
|
||||||
|
@ -742,7 +742,7 @@ class TestSyntax < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert_warning(/3: #{w}/m) {
|
assert_warning(/#{w[3]}/) {
|
||||||
eval %q{
|
eval %q{
|
||||||
case 1
|
case 1
|
||||||
when __FILE__, __FILE__
|
when __FILE__, __FILE__
|
||||||
|
@ -754,7 +754,7 @@ class TestSyntax < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_duplicated_when_check_option
|
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)
|
assert_in_out_err(%[-wc], "#{<<~"begin;"}\n#{<<~'end;'}", ["Syntax OK"], w)
|
||||||
begin;
|
begin;
|
||||||
case 1
|
case 1
|
||||||
|
|
Загрузка…
Ссылка в новой задаче