Skip to content

Commit

Permalink
Expand and simplify specs
Browse files Browse the repository at this point in the history
  • Loading branch information
oprypin committed Jan 5, 2025
1 parent 45b7b13 commit 7ba3ed3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions spec/compiler/parser/parser_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions spec/support/syntax.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7ba3ed3

Please sign in to comment.