From 7ba3ed3d6cd9802061a2a322fdf87b3ac1b50bd1 Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Sun, 5 Jan 2025 18:39:52 +0100 Subject: [PATCH] Expand and simplify specs --- spec/compiler/parser/parser_spec.cr | 15 +++++++++------ spec/support/syntax.cr | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/spec/compiler/parser/parser_spec.cr b/spec/compiler/parser/parser_spec.cr index 6829f8ecbd5b..0445974e06d5 100644 --- a/spec/compiler/parser/parser_spec.cr +++ b/spec/compiler/parser/parser_spec.cr @@ -338,19 +338,22 @@ module Crystal %w( bar? bar! ).each do |name| - assert_syntax_warning "def foo(#{name}); end", "invalid parameter name: #{name}", 1, 14 - assert_syntax_warning "def foo(foo #{name}); end", "invalid parameter name: #{name}", 1, 17 + assert_syntax_warning "def foo(#{name}); end", "invalid parameter name: #{name}" + assert_syntax_warning "def foo(foo #{name}); end", "invalid parameter name: #{name}" it_parses "def foo(#{name} foo); end", Def.new("foo", [Arg.new("foo", external_name: name.to_s)]) - assert_syntax_warning "macro foo(#{name}); end", "invalid parameter name: #{name}", 1, 16 - assert_syntax_warning "macro foo(foo #{name}); end", "invalid parameter name: #{name}", 1, 19 + assert_syntax_warning "macro foo(#{name}); end", "invalid parameter name: #{name}" + assert_syntax_warning "macro foo(foo #{name}); end", "invalid parameter name: #{name}" it_parses "macro foo(#{name} foo); end", Macro.new("foo", [Arg.new("foo", external_name: name.to_s)], body: MacroLiteral.new(" ")) it_parses "foo(#{name})", Call.new(nil, "foo", [name.call] of ASTNode) it_parses "foo #{name}", Call.new(nil, "foo", [name.call] of ASTNode) - assert_syntax_warning "foo { |#{name}| }", "invalid parameter name: #{name}", 1, 12 - assert_syntax_warning "foo { |(#{name})| }", "invalid parameter name: #{name}", 1, 13 + assert_syntax_warning "foo { |#{name}| }", "invalid parameter name: #{name}" + assert_syntax_warning "foo { |foo, (#{name})| }", "invalid parameter name: #{name}" + + assert_syntax_warning "foo do |foo, #{name}|\nend", "invalid parameter name: #{name}" + assert_syntax_warning "foo do |(#{name})|\nend", "invalid parameter name: #{name}" end it_parses "def self.foo\n1\nend", Def.new("foo", body: 1.int32, receiver: "self".var) diff --git a/spec/support/syntax.cr b/spec/support/syntax.cr index 689bd5c8fb18..df45df7d9648 100644 --- a/spec/support/syntax.cr +++ b/spec/support/syntax.cr @@ -158,11 +158,11 @@ def assert_syntax_error(str, message = nil, line = nil, column = nil, metafile = end end -def assert_syntax_warning(str, message = nil, line = nil, column = nil, metafile = __FILE__, metaline = __LINE__, metaendline = __END_LINE__) +def assert_syntax_warning(str, message, *, metafile = __FILE__, metaline = __LINE__, metaendline = __END_LINE__) it "says syntax warning on #{str.inspect}", metafile, metaline, metaendline do warnings = WarningCollection.new parse str, false, nil, warnings - if warnings.infos.find { |info| info.ends_with?(message) }.nil? + unless warnings.infos.find(&.ends_with?(message)) fail "Expected warnings to include '#{message}'" end end