summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-07-24 18:10:35 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-07-24 18:10:35 +0000
commit91bd6e711db3418baa287e936d4b0fac99927711 (patch)
tree4a605159d1d3f8327ee5775ede377c35d2867723 /test
parent1a5773a8682e685c87652f02df167f697f9413f9 (diff)
* parse.y: added symbols and qsymbols productions for %i and %I
support. %i{ .. } returns a list of symbols without interpolation, %I{ .. } returns a list of symbols with interpolation. Thanks to Josh Susser for inspiration of this feature. [Feature #4985] * ext/ripper/eventids2.c: added ripper events for %i and %I. * test/ripper/test_parser_events.rb: ripper tests * test/ripper/test_scanner_events.rb: ditto * test/ruby/test_array.rb: test for %i and %I behavior git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36524 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ripper/test_parser_events.rb24
-rw-r--r--test/ripper/test_scanner_events.rb22
-rw-r--r--test/ruby/test_array.rb11
3 files changed, 57 insertions, 0 deletions
diff --git a/test/ripper/test_parser_events.rb b/test/ripper/test_parser_events.rb
index 3b4785804d..278b47623a 100644
--- a/test/ripper/test_parser_events.rb
+++ b/test/ripper/test_parser_events.rb
@@ -755,12 +755,36 @@ class TestRipper::ParserEvents < Test::Unit::TestCase
assert_equal true, thru_qwords_add
end
+ def test_qsymbols_add
+ thru_qsymbols_add = false
+ parse('%i[a]', :on_qsymbols_add) {thru_qsymbols_add = true}
+ assert_equal true, thru_qsymbols_add
+ end
+
+ def test_symbols_add
+ thru_symbols_add = false
+ parse('%I[a]', :on_symbols_add) {thru_symbols_add = true}
+ assert_equal true, thru_symbols_add
+ end
+
def test_qwords_new
thru_qwords_new = false
parse('%w[]', :on_qwords_new) {thru_qwords_new = true}
assert_equal true, thru_qwords_new
end
+ def test_qsymbols_new
+ thru_qsymbols_new = false
+ parse('%i[]', :on_qsymbols_new) {thru_qsymbols_new = true}
+ assert_equal true, thru_qsymbols_new
+ end
+
+ def test_symbols_new
+ thru_symbols_new = false
+ parse('%I[]', :on_symbols_new) {thru_symbols_new = true}
+ assert_equal true, thru_symbols_new
+ end
+
def test_redo
thru_redo = false
parse('redo', :on_redo) {thru_redo = true}
diff --git a/test/ripper/test_scanner_events.rb b/test/ripper/test_scanner_events.rb
index 5b58dd8289..bcbbf0192c 100644
--- a/test/ripper/test_scanner_events.rb
+++ b/test/ripper/test_scanner_events.rb
@@ -608,6 +608,28 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase
scan('qwords_beg', '%w( w w w )')
end
+ def test_qsymbols_beg
+ assert_equal [],
+ scan('qsymbols_beg', '')
+ assert_equal ['%i('],
+ scan('qsymbols_beg', '%i()')
+ assert_equal ['%i('],
+ scan('qsymbols_beg', '%i(w w w)')
+ assert_equal ['%i( '],
+ scan('qsymbols_beg', '%i( w w w )')
+ end
+
+ def test_symbols_beg
+ assert_equal [],
+ scan('symbols_beg', '')
+ assert_equal ['%I('],
+ scan('symbols_beg', '%I()')
+ assert_equal ['%I('],
+ scan('symbols_beg', '%I(w w w)')
+ assert_equal ['%I( '],
+ scan('symbols_beg', '%I( w w w )')
+ end
+
# FIXME: Close paren must not present (`words_end' scanner event?).
def test_words_sep
assert_equal [],
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb
index fff55e13ff..4a9a58b723 100644
--- a/test/ruby/test_array.rb
+++ b/test/ruby/test_array.rb
@@ -12,6 +12,17 @@ class TestArray < Test::Unit::TestCase
$VERBOSE = @verbose
end
+ def test_percent_i
+ assert_equal([:foo, :bar], %i[foo bar])
+ assert_equal([:"\"foo"], %i["foo])
+ end
+
+ def test_percent_I
+ x = 10
+ assert_equal([:foo, :b10], %I[foo b#{x}])
+ assert_equal([:"\"foo10"], %I["foo#{x}])
+ end
+
def test_0_literal
assert_equal([1, 2, 3, 4], [1, 2] + [3, 4])
assert_equal([1, 2, 1, 2], [1, 2] * 2)