diff options
author | Kevin Newton <[email protected]> | 2024-07-03 11:23:17 -0400 |
---|---|---|
committer | Kevin Newton <[email protected]> | 2024-07-11 14:25:54 -0400 |
commit | aa473489a2ff5e5ed6d3536466e6108539c97a8b (patch) | |
tree | c628ff4d6e08926e06c29b56ac0fa2b7acdf9d5b /test | |
parent | 2bf9ae3fa1b5dec1c63176f39db84d697ede3581 (diff) |
[ruby/prism] Various cleanup for initializers and typechecks
https://github.com/ruby/prism/commit/86cf82794a
Diffstat (limited to 'test')
-rw-r--r-- | test/prism/errors_test.rb | 8 | ||||
-rw-r--r-- | test/prism/result/warnings_test.rb | 59 |
2 files changed, 39 insertions, 28 deletions
diff --git a/test/prism/errors_test.rb b/test/prism/errors_test.rb index 4c5f93cc9f..9a108ceca7 100644 --- a/test/prism/errors_test.rb +++ b/test/prism/errors_test.rb @@ -18,6 +18,12 @@ module Prism ] end + if RUBY_VERSION < "3.4" + filepaths -= [ + "it_with_ordinary_parameter.txt" + ] + end + filepaths.each do |filepath| define_method(:"test_#{File.basename(filepath, ".txt")}") do assert_errors(File.join(base, filepath)) @@ -77,7 +83,7 @@ module Prism private def assert_errors(filepath) - expected = File.read(filepath) + expected = File.read(filepath, binmode: true, external_encoding: Encoding::UTF_8) source = expected.lines.grep_v(/^\s*\^/).join.gsub(/\n*\z/, "") refute_valid_syntax(source) diff --git a/test/prism/result/warnings_test.rb b/test/prism/result/warnings_test.rb index 747440dd76..c147616a6a 100644 --- a/test/prism/result/warnings_test.rb +++ b/test/prism/result/warnings_test.rb @@ -76,33 +76,38 @@ module Prism end def test_literal_in_conditionals - source = <<~RUBY - if (a = 2); a; end - if ($a = 2); end - if (@a = 2); end - if (@@a = 2); end - if a; elsif b = 2; b end - unless (a = 2); a; end - unless ($a = 2); end - unless (@a = 2); end - unless (@@a = 2); end - while (a = 2); a; end - while ($a = 2); end - while (@a = 2); end - while (@@a = 2); end - until (a = 2); a; end - until ($a = 2); end - until (@a = 2); end - until (@@a = 2); end - foo if (a, b = 2); [a, b] - foo if a = 2 and a - (@foo = 1) ? a : b - !(a = 2) and a - not a = 2 and a - RUBY - - source.each_line(chomp: true) do |line| - assert_warning(line, "found '= literal' in conditional, should be ==") + sources = [ + "if (a = 2); a; end", + "if ($a = 2); end", + "if (@a = 2); end", + "if a; elsif b = 2; b end", + "unless (a = 2); a; end", + "unless ($a = 2); end", + "unless (@a = 2); end", + "while (a = 2); a; end", + "while ($a = 2); end", + "while (@a = 2); end", + "until (a = 2); a; end", + "until ($a = 2); end", + "until (@a = 2); end", + "foo if (a, b = 2); [a, b]", + "foo if a = 2 and a", + "(@foo = 1) ? a : b", + "!(a = 2) and a", + "not a = 2 and a" + ] + + if RUBY_VERSION >= "3.3" + sources.push( + "if (@@a = 2); end", + "unless (@@a = 2); end", + "while (@@a = 2); end", + "until (@@a = 2); end" + ) + end + + sources.each do |source| + assert_warning(source, "= literal' in conditional, should be ==") end end |