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.rb45
1 files changed, 43 insertions, 2 deletions
diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb
index a2f64200f3..def41d6017 100644
--- a/test/ruby/test_parse.rb
+++ b/test/ruby/test_parse.rb
@@ -186,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
@@ -343,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("``")
@@ -466,6 +490,12 @@ class TestParse < Test::Unit::TestCase
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
@@ -648,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)
@@ -1527,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
@@ -1556,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]'
@@ -1721,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')