2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2011-09-17 10:34:13 -04:00
|
|
|
begin
|
|
|
|
require 'ripper'
|
|
|
|
require 'test/unit'
|
|
|
|
ripper_test = true
|
|
|
|
module TestRipper; end
|
|
|
|
rescue LoadError
|
|
|
|
end
|
|
|
|
|
|
|
|
class TestRipper::Ripper < Test::Unit::TestCase
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@ripper = Ripper.new '1 + 1'
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_column
|
|
|
|
assert_nil @ripper.column
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_encoding
|
2012-11-05 19:49:57 -05:00
|
|
|
assert_equal Encoding::UTF_8, @ripper.encoding
|
2014-09-30 09:25:28 -04:00
|
|
|
ripper = Ripper.new('# coding: iso-8859-15')
|
|
|
|
ripper.parse
|
|
|
|
assert_equal Encoding::ISO_8859_15, ripper.encoding
|
2014-12-01 12:53:02 -05:00
|
|
|
ripper = Ripper.new('# -*- coding: iso-8859-15 -*-')
|
|
|
|
ripper.parse
|
|
|
|
assert_equal Encoding::ISO_8859_15, ripper.encoding
|
2011-09-17 10:34:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_end_seen_eh
|
2014-09-30 09:25:28 -04:00
|
|
|
@ripper.parse
|
|
|
|
assert_not_predicate @ripper, :end_seen?
|
|
|
|
ripper = Ripper.new('__END__')
|
|
|
|
ripper.parse
|
|
|
|
assert_predicate ripper, :end_seen?
|
2011-09-17 10:34:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_filename
|
|
|
|
assert_equal '(ripper)', @ripper.filename
|
2014-03-24 09:19:57 -04:00
|
|
|
filename = "ripper"
|
|
|
|
ripper = Ripper.new("", filename)
|
|
|
|
filename.clear
|
|
|
|
assert_equal "ripper", ripper.filename
|
2011-09-17 10:34:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_lineno
|
|
|
|
assert_nil @ripper.lineno
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_parse
|
2014-09-30 09:25:28 -04:00
|
|
|
assert_nil @ripper.parse
|
2011-09-17 10:34:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_yydebug
|
2014-09-30 09:25:28 -04:00
|
|
|
assert_not_predicate @ripper, :yydebug
|
2011-09-17 10:34:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_yydebug_equals
|
|
|
|
@ripper.yydebug = true
|
|
|
|
|
2014-09-30 09:25:28 -04:00
|
|
|
assert_predicate @ripper, :yydebug
|
2011-09-17 10:34:13 -04:00
|
|
|
end
|
2016-01-04 02:59:55 -05:00
|
|
|
|
|
|
|
def test_regexp_with_option
|
|
|
|
bug11932 = '[ruby-core:72638] [Bug #11932]'
|
|
|
|
src = '/[\xC0-\xF0]/u'.force_encoding(Encoding::UTF_8)
|
|
|
|
ripper = Ripper.new(src)
|
|
|
|
ripper.parse
|
|
|
|
assert_predicate(ripper, :error?)
|
|
|
|
src = '/[\xC0-\xF0]/n'.force_encoding(Encoding::UTF_8)
|
|
|
|
ripper = Ripper.new(src)
|
|
|
|
ripper.parse
|
|
|
|
assert_not_predicate(ripper, :error?, bug11932)
|
|
|
|
end
|
2011-09-17 10:34:13 -04:00
|
|
|
end if ripper_test
|