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
|
|
|
|
|
|
|
|
end if ripper_test
|