summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-20 06:01:57 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-20 06:01:57 +0000
commitaba824fece59d1afffa78d145a4f301f7fdc3688 (patch)
tree89173d1abb36ebd286ea8f1bbb33fad496a4b0f3 /test
parent035917adc127083ac851394e56ba3636b58e4823 (diff)
parse.y: junk sigil only names
* parse.y (intern_str): sigil only names are junk, at least one identifier character is needed. [ruby-dev:47723] [Bug #8928] * parse.y (rb_enc_symname_type): fix out of bound access. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42988 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/-ext-/symbol/test_type.rb96
-rw-r--r--test/ruby/test_module.rb4
-rw-r--r--test/ruby/test_object.rb6
3 files changed, 106 insertions, 0 deletions
diff --git a/test/-ext-/symbol/test_type.rb b/test/-ext-/symbol/test_type.rb
new file mode 100644
index 0000000000..427888eeb9
--- /dev/null
+++ b/test/-ext-/symbol/test_type.rb
@@ -0,0 +1,96 @@
+require 'test/unit'
+require "-test-/symbol"
+
+module Test_Symbol
+ class TestType < Test::Unit::TestCase
+ def assert_symtype(sym, pred, msg = nil)
+ assert_send([Bug::Symbol, pred, sym], msg)
+ end
+
+ def assert_not_symtype(sym, pred, msg = nil)
+ assert_not_send([Bug::Symbol, pred, sym], msg)
+ end
+
+ def test_const
+ assert_symtype("Foo", :const?)
+ assert_not_symtype("F!", :const?)
+ assert_not_symtype("foo", :const?)
+ assert_not_symtype("@foo", :const?)
+ assert_not_symtype("@@foo", :const?)
+ assert_not_symtype("$foo", :const?)
+ assert_not_symtype("foo=", :const?)
+ assert_not_symtype("[foo]", :const?)
+ assert_not_symtype("xFoo", :const?)
+ end
+
+ def test_local
+ assert_symtype("foo", :local?)
+ assert_symtype("fooBar", :local?)
+ assert_symtype("foo_bar", :local?)
+ assert_not_symtype("foo!", :local?)
+ assert_not_symtype("foo?", :local?)
+ assert_not_symtype("Foo", :local?)
+ assert_not_symtype("@foo", :local?)
+ assert_not_symtype("@@foo", :local?)
+ assert_not_symtype("$foo", :local?)
+ assert_not_symtype("foo=", :local?)
+ assert_not_symtype("[foo]", :local?)
+ end
+
+ def test_global
+ assert_symtype("$foo", :global?)
+ assert_symtype("$$", :global?)
+ assert_not_symtype("$()", :global?)
+ assert_not_symtype("$", :global?)
+ assert_not_symtype("foo", :global?)
+ assert_not_symtype("Foo", :global?)
+ assert_not_symtype("@foo", :global?)
+ assert_not_symtype("@@foo", :global?)
+ assert_not_symtype("foo=", :global?)
+ assert_not_symtype("[foo]", :global?)
+ end
+
+ def test_instance
+ assert_symtype("@foo", :instance?)
+ assert_not_symtype("@", :instance?)
+ assert_not_symtype("@1", :instance?)
+ assert_not_symtype("@@", :instance?)
+ assert_not_symtype("foo", :instance?)
+ assert_not_symtype("Foo", :instance?)
+ assert_not_symtype("@@foo", :instance?)
+ assert_not_symtype("$foo", :instance?)
+ assert_not_symtype("foo=", :instance?)
+ assert_not_symtype("[foo]", :instance?)
+ end
+
+ def test_class
+ assert_symtype("@@foo", :class?)
+ assert_not_symtype("@@", :class?)
+ assert_not_symtype("@", :class?)
+ assert_not_symtype("@@1", :class?)
+ assert_not_symtype("foo", :class?)
+ assert_not_symtype("Foo", :class?)
+ assert_not_symtype("@foo", :class?)
+ assert_not_symtype("$foo", :class?)
+ assert_not_symtype("foo=", :class?)
+ assert_not_symtype("[foo]", :class?)
+ end
+
+ def test_attrset
+ assert_symtype("foo=", :attrset?)
+ assert_symtype("Foo=", :attrset?)
+ assert_symtype("@foo=", :attrset?)
+ assert_symtype("@@foo=", :attrset?)
+ assert_symtype("$foo=", :attrset?)
+ assert_not_symtype("0=", :attrset?)
+ assert_not_symtype("@=", :attrset?)
+ assert_not_symtype("@@=", :attrset?)
+ assert_not_symtype("foo", :attrset?)
+ assert_not_symtype("Foo", :attrset?)
+ assert_not_symtype("@foo", :attrset?)
+ assert_not_symtype("@@foo", :attrset?)
+ assert_not_symtype("$foo", :attrset?)
+ assert_not_symtype("[foo]", :attrset?)
+ end
+ end
+end
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb
index 9b253b3776..f6212f9349 100644
--- a/test/ruby/test_module.rb
+++ b/test/ruby/test_module.rb
@@ -688,6 +688,7 @@ class TestModule < Test::Unit::TestCase
c.class_eval('@@foo = :foo')
assert_equal(:foo, c.class_variable_get(:@@foo))
assert_raise(NameError) { c.class_variable_get(:@@bar) } # c.f. instance_variable_get
+ assert_raise(NameError) { c.class_variable_get(:'@@') }
assert_raise(NameError) { c.class_variable_get('@@') }
assert_raise(NameError) { c.class_variable_get(:foo) }
assert_raise(NameError) { c.class_variable_get("bar") }
@@ -704,6 +705,7 @@ class TestModule < Test::Unit::TestCase
c = Class.new
c.class_variable_set(:@@foo, :foo)
assert_equal(:foo, c.class_eval('@@foo'))
+ assert_raise(NameError) { c.class_variable_set(:'@@', 1) }
assert_raise(NameError) { c.class_variable_set('@@', 1) }
assert_raise(NameError) { c.class_variable_set(:foo, 1) }
assert_raise(NameError) { c.class_variable_set("bar", 1) }
@@ -722,6 +724,8 @@ class TestModule < Test::Unit::TestCase
c.class_eval('@@foo = :foo')
assert_equal(true, c.class_variable_defined?(:@@foo))
assert_equal(false, c.class_variable_defined?(:@@bar))
+ assert_raise(NameError) { c.class_variable_defined?(:'@@') }
+ assert_raise(NameError) { c.class_variable_defined?('@@') }
assert_raise(NameError) { c.class_variable_defined?(:foo) }
assert_raise(NameError) { c.class_variable_defined?("bar") }
assert_raise(TypeError) { c.class_variable_defined?(1) }
diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb
index b46403ad6f..d33884e036 100644
--- a/test/ruby/test_object.rb
+++ b/test/ruby/test_object.rb
@@ -163,6 +163,8 @@ class TestObject < Test::Unit::TestCase
o.instance_eval { @foo = :foo }
assert_equal(:foo, o.instance_variable_get(:@foo))
assert_equal(nil, o.instance_variable_get(:@bar))
+ assert_raise(NameError) { o.instance_variable_get('@') }
+ assert_raise(NameError) { o.instance_variable_get(:'@') }
assert_raise(NameError) { o.instance_variable_get(:foo) }
assert_raise(NameError) { o.instance_variable_get("bar") }
assert_raise(TypeError) { o.instance_variable_get(1) }
@@ -178,6 +180,8 @@ class TestObject < Test::Unit::TestCase
o = Object.new
o.instance_variable_set(:@foo, :foo)
assert_equal(:foo, o.instance_eval { @foo })
+ assert_raise(NameError) { o.instance_variable_set(:'@', 1) }
+ assert_raise(NameError) { o.instance_variable_set('@', 1) }
assert_raise(NameError) { o.instance_variable_set(:foo, 1) }
assert_raise(NameError) { o.instance_variable_set("bar", 1) }
assert_raise(TypeError) { o.instance_variable_set(1, 1) }
@@ -195,6 +199,8 @@ class TestObject < Test::Unit::TestCase
o.instance_eval { @foo = :foo }
assert_equal(true, o.instance_variable_defined?(:@foo))
assert_equal(false, o.instance_variable_defined?(:@bar))
+ assert_raise(NameError) { o.instance_variable_defined?(:'@') }
+ assert_raise(NameError) { o.instance_variable_defined?('@') }
assert_raise(NameError) { o.instance_variable_defined?(:foo) }
assert_raise(NameError) { o.instance_variable_defined?("bar") }
assert_raise(TypeError) { o.instance_variable_defined?(1) }