summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/ripper/test_parser_events.rb7
-rw-r--r--test/ripper/test_scanner_events.rb2
-rw-r--r--test/ruby/test_ast.rb9
-rw-r--r--test/ruby/test_method.rb19
-rw-r--r--test/ruby/test_syntax.rb1
5 files changed, 38 insertions, 0 deletions
diff --git a/test/ripper/test_parser_events.rb b/test/ripper/test_parser_events.rb
index 95ec661fcf..3c78daf16e 100644
--- a/test/ripper/test_parser_events.rb
+++ b/test/ripper/test_parser_events.rb
@@ -434,6 +434,13 @@ class TestRipper::ParserEvents < Test::Unit::TestCase
assert_equal "[call(ref(self),&.,foo,[])]", tree
end
+ def test_methref
+ thru_methref = false
+ tree = parse("obj.:foo", :on_methref) {thru_methref = true}
+ assert_equal true, thru_methref
+ assert_equal "[methref(vcall(obj),foo)]", tree
+ end
+
def test_excessed_comma
thru_excessed_comma = false
parse("proc{|x,|}", :on_excessed_comma) {thru_excessed_comma = true}
diff --git a/test/ripper/test_scanner_events.rb b/test/ripper/test_scanner_events.rb
index c9fce34a77..94df6616e8 100644
--- a/test/ripper/test_scanner_events.rb
+++ b/test/ripper/test_scanner_events.rb
@@ -550,6 +550,8 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase
scan('op', ':[]=')
assert_equal ['&.'],
scan('op', 'a&.f')
+ assert_equal %w(.:),
+ scan('op', 'obj.:foo')
assert_equal [],
scan('op', %q[`make all`])
end
diff --git a/test/ruby/test_ast.rb b/test/ruby/test_ast.rb
index 055567d574..ed4bcb37c0 100644
--- a/test/ruby/test_ast.rb
+++ b/test/ruby/test_ast.rb
@@ -249,4 +249,13 @@ class TestAst < Test::Unit::TestCase
assert_equal(:b, mid)
assert_equal(:SCOPE, defn.type)
end
+
+ def test_methref
+ node = RubyVM::AbstractSyntaxTree.parse("obj.:foo")
+ _, _, body = *node.children
+ assert_equal(:METHREF, body.type)
+ recv, mid = body.children
+ assert_equal(:VCALL, recv.type)
+ assert_equal(:foo, mid)
+ end
end
diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb
index a9051b81fa..5cfcdb8dc5 100644
--- a/test/ruby/test_method.rb
+++ b/test/ruby/test_method.rb
@@ -1095,4 +1095,23 @@ class TestMethod < Test::Unit::TestCase
(f >> 5).call(2)
}
end
+
+ def test_method_reference_operator
+ m = 1.:succ
+ assert_equal(1.method(:succ), m)
+ assert_equal(2, m.())
+ m = 1.:+
+ assert_equal(1.method(:+), m)
+ assert_equal(42, m.(41))
+ m = 1.:-@
+ assert_equal(1.method(:-@), m)
+ assert_equal(-1, m.())
+ o = Object.new
+ def o.foo; 42; end
+ m = o.method(:foo)
+ assert_equal(m, o.:foo)
+ def o.method(m); nil; end
+ assert_equal(m, o.:foo)
+ assert_nil(o.method(:foo))
+ end
end
diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb
index dee9187a9c..5534056327 100644
--- a/test/ruby/test_syntax.rb
+++ b/test/ruby/test_syntax.rb
@@ -908,6 +908,7 @@ eom
def test_fluent_dot
assert_valid_syntax("a\n.foo")
assert_valid_syntax("a\n&.foo")
+ assert_valid_syntax("a\n.:foo")
end
def test_no_warning_logop_literal