summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-07-03 14:45:24 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2022-07-06 08:32:36 +0900
commiteaeb130b11fefe91aaf61f294ea32af76dada74f (patch)
tree9718801a7fc867f025f62589f1b7881c1e221db7 /test/ruby
parent902d1a5c513ed6e49e7f577ffe7146d30798b3e9 (diff)
downloadruby-eaeb130b11fefe91aaf61f294ea32af76dada74f.tar.gz
[Bug #18890] newline should be insignificant after pattern label
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_parse.rb33
-rw-r--r--test/ruby/test_pattern_matching.rb15
2 files changed, 48 insertions, 0 deletions
diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb
index 8b7c8f0e5b..16764a2146 100644
--- a/test/ruby/test_parse.rb
+++ b/test/ruby/test_parse.rb
@@ -1370,6 +1370,39 @@ x = __ENCODING__
assert_syntax_error('x = \ 42', /escaped space/)
end
+ def test_label
+ expected = {:foo => 1}
+
+ code = '{"foo": 1}'
+ assert_valid_syntax(code)
+ assert_equal(expected, eval(code))
+
+ code = '{foo: 1}'
+ assert_valid_syntax(code)
+ assert_equal(expected, eval(code))
+
+ class << (obj = Object.new)
+ attr_reader :arg
+ def set(arg)
+ @arg = arg
+ end
+ end
+
+ assert_valid_syntax(code = "#{<<~"do;"}\n#{<<~'end;'}")
+ do;
+ obj.set foo:
+ 1
+ end;
+ assert_equal(expected, eval(code))
+
+ assert_valid_syntax(code = "#{<<~"do;"}\n#{<<~'end;'}")
+ do;
+ obj.set "foo":
+ 1
+ end;
+ assert_equal(expected, eval(code))
+ end
+
=begin
def test_past_scope_variable
assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}}
diff --git a/test/ruby/test_pattern_matching.rb b/test/ruby/test_pattern_matching.rb
index 7531466f91..b8c445c806 100644
--- a/test/ruby/test_pattern_matching.rb
+++ b/test/ruby/test_pattern_matching.rb
@@ -1155,6 +1155,21 @@ END
end
end
+ [{a: 42}, {b: 42}].each do |i|
+ assert_block('newline should be insignificant after pattern label') do
+ case i
+ in a:
+ 0
+ true
+ in "b":
+ 0
+ true
+ else
+ false
+ end
+ end
+ end
+
assert_syntax_error(%q{
case _
in a:, a: