# frozen_string_literal: true begin require 'ripper' require 'stringio' 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_state assert_nil @ripper.state end def test_encoding assert_equal Encoding::UTF_8, @ripper.encoding ripper = Ripper.new('# coding: iso-8859-15') ripper.parse assert_equal Encoding::ISO_8859_15, ripper.encoding ripper = Ripper.new('# -*- coding: iso-8859-15 -*-') ripper.parse assert_equal Encoding::ISO_8859_15, ripper.encoding end def test_end_seen_eh @ripper.parse assert_not_predicate @ripper, :end_seen? ripper = Ripper.new('__END__') ripper.parse assert_predicate ripper, :end_seen? end def test_filename assert_equal '(ripper)', @ripper.filename filename = "ripper".dup ripper = Ripper.new("", filename) filename.clear assert_equal "ripper", ripper.filename end def test_lineno assert_nil @ripper.lineno end def test_parse assert_nil @ripper.parse end def test_yydebug assert_not_predicate @ripper, :yydebug end def test_yydebug_equals @ripper.yydebug = true assert_predicate @ripper, :yydebug end def test_yydebug_ident out = StringIO.new ripper = Ripper.new 'test_xxxx' ripper.yydebug = true ripper.debug_output = out ripper.parse assert_include out.string[/.*"local variable or method".*/], 'test_xxxx' end def test_yydebug_string out = StringIO.new ripper = Ripper.new '"woot"' ripper.yydebug = true ripper.debug_output = out ripper.parse assert_include out.string[/.*"literal content".*/], 'woot' end def test_regexp_with_option bug11932 = '[ruby-core:72638] [Bug #11932]' src = '/[\xC0-\xF0]/u'.dup.force_encoding(Encoding::UTF_8) ripper = Ripper.new(src) ripper.parse assert_predicate(ripper, :error?) src = '/[\xC0-\xF0]/n'.dup.force_encoding(Encoding::UTF_8) ripper = Ripper.new(src) ripper.parse assert_not_predicate(ripper, :error?, bug11932) end def test_regexp_enc_error assert_separately(%w[-rripper], "#{<<-"begin;"}\n#{<<-"end;"}") begin; bug12651 = '[ruby-core:76397] [Bug #12651]' src = <<-END <%- @title = '\u{5bff 9650 7121}' -%> <%- content_for :foo, render(partial: 'bar', locals: {baz: 2}) -%>