summaryrefslogtreecommitdiff
path: root/test/ruby/test_parse.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_parse.rb')
-rw-r--r--test/ruby/test_parse.rb81
1 files changed, 79 insertions, 2 deletions
diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb
index 20364c5a0d..def41d6017 100644
--- a/test/ruby/test_parse.rb
+++ b/test/ruby/test_parse.rb
@@ -2,6 +2,7 @@
# frozen_string_literal: false
require 'test/unit'
require 'stringio'
+require_relative '../lib/parser_support'
class TestParse < Test::Unit::TestCase
def setup
@@ -185,6 +186,15 @@ class TestParse < Test::Unit::TestCase
end;
end
+ c = Class.new
+ c.freeze
+ assert_valid_syntax("#{<<~"begin;"}\n#{<<~'end;'}") do
+ begin;
+ c::FOO &= p 1
+ ::FOO &= p 1
+ end;
+ end
+
assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /Can't set variable/) do
begin;
$1 &= 1
@@ -342,6 +352,21 @@ class TestParse < Test::Unit::TestCase
assert_equal("foobar", b)
end
+ def test_call_command
+ a = b = nil
+ o = Object.new
+ def o.m(*arg); proc {|a| arg.join + a }; end
+
+ assert_nothing_raised do
+ o.instance_eval <<-END, __FILE__, __LINE__+1
+ a = o.m "foo", "bar" do end.("buz")
+ b = o.m "foo", "bar" do end::("buz")
+ END
+ end
+ assert_equal("foobarbuz", a)
+ assert_equal("foobarbuz", b)
+ end
+
def test_xstring
assert_raise(Errno::ENOENT) do
eval("``")
@@ -463,6 +488,14 @@ class TestParse < Test::Unit::TestCase
assert_parse_error(%q[def ((%w();1)).foo; end], msg)
assert_parse_error(%q[def ("#{42}").foo; end], msg)
assert_parse_error(%q[def (:"#{42}").foo; end], msg)
+ assert_parse_error(%q[def ([]).foo; end], msg)
+ assert_parse_error(%q[def ([1]).foo; end], msg)
+ assert_parse_error(%q[def (__FILE__).foo; end], msg)
+ assert_parse_error(%q[def (__LINE__).foo; end], msg)
+ assert_parse_error(%q[def (__ENCODING__).foo; end], msg)
+ assert_parse_error(%q[def __FILE__.foo; end], msg)
+ assert_parse_error(%q[def __LINE__.foo; end], msg)
+ assert_parse_error(%q[def __ENCODING__.foo; end], msg)
end
def test_flip_flop
@@ -645,6 +678,8 @@ class TestParse < Test::Unit::TestCase
assert_equal("\u{1234}", eval('?\u{1234}'))
assert_equal("\u{1234}", eval('?\u1234'))
assert_syntax_error('?\u{41 42}', 'Multiple codepoints at single character literal')
+ assert_syntax_error("?and", /unexpected '\?'/)
+ assert_syntax_error("?\u1234and", /unexpected '\?'/)
e = assert_syntax_error('"#{?\u123}"', 'invalid Unicode escape')
assert_not_match(/end-of-input/, e.message)
@@ -950,6 +985,7 @@ x = __ENCODING__
assert_nil assert_warning(useless_use) {eval("true; nil")}
assert_nil assert_warning(useless_use) {eval("false; nil")}
assert_nil assert_warning(useless_use) {eval("defined?(1); nil")}
+ assert_nil assert_warning(useless_use) {eval("begin; ensure; x; end")}
assert_equal 1, x
assert_syntax_error("1; next; 2", /Invalid next/)
@@ -1523,7 +1559,7 @@ x = __ENCODING__
end
def test_shareable_constant_value_simple
- obj = [['unsharable_value']]
+ obj = [['unshareable_value']]
a, b, c = eval_separately("#{<<~"begin;"}\n#{<<~'end;'}")
begin;
# shareable_constant_value: experimental_everything
@@ -1552,7 +1588,7 @@ x = __ENCODING__
assert_ractor_shareable(a)
assert_not_ractor_shareable(obj)
assert_equal obj, a
- assert !obj.equal?(a)
+ assert_not_same obj, a
bug_20339 = '[ruby-core:117186] [Bug #20339]'
bug_20341 = '[ruby-core:117197] [Bug #20341]'
@@ -1573,6 +1609,21 @@ x = __ENCODING__
assert_equal(2, b[1], bug_20341)
end
+ def test_shareable_constant_value_literal_const_refs
+ a = eval_separately("#{<<~"begin;"}\n#{<<~'end;'}")
+ begin;
+ # shareable_constant_value: literal
+ # [Bug #20668]
+ SOME_CONST = {
+ 'Object' => Object,
+ 'String' => String,
+ 'Array' => Array,
+ }
+ SOME_CONST
+ end;
+ assert_ractor_shareable(a)
+ end
+
def test_shareable_constant_value_nested
a, b = eval_separately("#{<<~"begin;"}\n#{<<~'end;'}")
begin;
@@ -1591,6 +1642,23 @@ x = __ENCODING__
assert_ractor_shareable(a[0])
end
+ def test_shareable_constant_value_hash_with_keyword_splat
+ a, b = eval_separately("#{<<~"begin;"}\n#{<<~'end;'}")
+ begin;
+ # shareable_constant_value: experimental_everything
+ # [Bug #20927]
+ x = { x: {} }
+ y = { y: {} }
+ A = { **x }
+ B = { x: {}, **y }
+ [A, B]
+ end;
+ assert_ractor_shareable(a)
+ assert_ractor_shareable(b)
+ assert_equal({ x: {}}, a)
+ assert_equal({ x: {}, y: {}}, b)
+ end
+
def test_shareable_constant_value_unshareable_literal
assert_raise_separately(Ractor::IsolationError, /unshareable object to C/,
"#{<<~"begin;"}\n#{<<~'end;'}")
@@ -1685,6 +1753,15 @@ x = __ENCODING__
end;
end
+ def test_shareable_constant_value_massign
+ a = eval_separately("#{<<~"begin;"}\n#{<<~'end;'}")
+ begin;
+ # shareable_constant_value: experimental_everything
+ A, = 1
+ end;
+ assert_equal(1, a)
+ end
+
def test_if_after_class
assert_valid_syntax('module if true; Object end::Kernel; end')
assert_valid_syntax('module while true; break Object end::Kernel; end')