mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
0a190272cd
* parse.y (ripper_flush_string_content): preserve the dispatched results at tSTRING_CONTENT. [ruby-dev:48714] [Bug #10437] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48674 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
44 lines
1.2 KiB
Ruby
44 lines
1.2 KiB
Ruby
begin
|
|
require 'ripper'
|
|
require 'test/unit'
|
|
ripper_test = true
|
|
module TestRipper; end
|
|
rescue LoadError
|
|
end
|
|
|
|
class TestRipper::Sexp < Test::Unit::TestCase
|
|
def test_compile_error
|
|
assert_nil Ripper.sexp("/")
|
|
assert_nil Ripper.sexp("-")
|
|
assert_nil Ripper.sexp("+")
|
|
assert_nil Ripper.sexp("*")
|
|
assert_nil Ripper.sexp("end")
|
|
assert_nil Ripper.sexp("end 1")
|
|
assert_nil Ripper.sexp("/*")
|
|
assert_nil Ripper.sexp("/*/")
|
|
assert_nil Ripper.sexp("/+/")
|
|
end
|
|
|
|
def test_regexp_content
|
|
sexp = Ripper.sexp('//')
|
|
assert_nil search_sexp(:@tstring_content, search_sexp(:regexp_literal, sexp))
|
|
|
|
sexp = Ripper.sexp('/foo/')
|
|
assert_equal 'foo', search_sexp(:@tstring_content, search_sexp(:regexp_literal, sexp))[1]
|
|
|
|
sexp = Ripper.sexp("/foo\nbar/")
|
|
assert_equal "foo\nbar", search_sexp(:@tstring_content, search_sexp(:regexp_literal, sexp))[1]
|
|
|
|
sexp = Ripper.sexp('/(?<n>a(b|\g<n>))/')
|
|
assert_equal '(?<n>a(b|\g<n>))', search_sexp(:@tstring_content, search_sexp(:regexp_literal, sexp))[1]
|
|
end
|
|
|
|
def search_sexp(sym, sexp)
|
|
return sexp if !sexp or sexp[0] == sym
|
|
sexp.find do |e|
|
|
if Array === e and e = search_sexp(sym, e)
|
|
return e
|
|
end
|
|
end
|
|
end
|
|
end if ripper_test
|