# coding: UTF-8 require 'rdoc/test_case' class TestRDocRubyLex < RDoc::TestCase def setup @TK = RDoc::RubyToken end def mu_pp obj s = '' s = PP.pp obj, s s = s.force_encoding(Encoding.default_external) if defined? Encoding s.chomp end def test_class_tokenize tokens = RDoc::RubyLex.tokenize "def x() end", nil expected = [ @TK::TkDEF .new( 0, 1, 0, "def"), @TK::TkSPACE .new( 3, 1, 3, " "), @TK::TkIDENTIFIER.new( 4, 1, 4, "x"), @TK::TkLPAREN .new( 5, 1, 5, "("), @TK::TkRPAREN .new( 6, 1, 6, ")"), @TK::TkSPACE .new( 7, 1, 7, " "), @TK::TkEND .new( 8, 1, 8, "end"), @TK::TkNL .new(11, 1, 11, "\n"), ] assert_equal expected, tokens end def test_class_tokenize___END__ tokens = RDoc::RubyLex.tokenize '__END__', nil expected = [ @TK::TkEND_OF_SCRIPT.new(0, 1, 0, '__END__'), @TK::TkNL .new(7, 1, 7, "\n"), ] assert_equal expected, tokens end def test_class_tokenize_character_literal tokens = RDoc::RubyLex.tokenize "?\\", nil expected = [ @TK::TkSTRING.new( 0, 1, 0, "\\"), @TK::TkNL .new( 2, 1, 2, "\n"), ] assert_equal expected, tokens end def test_class_tokenize_def_heredoc tokens = RDoc::RubyLex.tokenize <<-'RUBY', nil def x <