2012-12-02 17:52:57 -05:00
|
|
|
# -*- coding: us-ascii -*-
|
2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2012-12-02 17:52:57 -05:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
require 'rdoc/test_case'
|
2008-09-24 22:43:03 -04:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
class TestRDocParser < RDoc::TestCase
|
2008-09-24 22:43:03 -04:00
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
def setup
|
2012-11-26 23:28:14 -05:00
|
|
|
super
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
@RP = RDoc::Parser
|
|
|
|
@binary_dat = File.expand_path '../binary.dat', __FILE__
|
2012-11-26 23:28:14 -05:00
|
|
|
|
|
|
|
@fn = 'file.rb'
|
|
|
|
@top_level = RDoc::TopLevel.new @fn
|
|
|
|
@options = RDoc::Options.new
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
2014-09-04 21:41:25 -04:00
|
|
|
def test_class_binary_eh_ISO_2022_JP
|
|
|
|
iso_2022_jp = File.join Dir.tmpdir, "test_rdoc_parser_#{$$}.rd"
|
|
|
|
|
|
|
|
open iso_2022_jp, 'wb' do |io|
|
|
|
|
io.write "# coding: ISO-2022-JP\n"
|
|
|
|
io.write ":\e$B%3%^%s%I\e(B:\n"
|
|
|
|
end
|
|
|
|
|
|
|
|
refute @RP.binary? iso_2022_jp
|
|
|
|
ensure
|
|
|
|
File.unlink iso_2022_jp
|
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
def test_class_binary_eh_marshal
|
|
|
|
marshal = File.join Dir.tmpdir, "test_rdoc_parser_#{$$}.marshal"
|
|
|
|
open marshal, 'wb' do |io|
|
|
|
|
io.write Marshal.dump('')
|
|
|
|
io.write 'lots of text ' * 500
|
|
|
|
end
|
|
|
|
|
|
|
|
assert @RP.binary?(marshal)
|
|
|
|
ensure
|
|
|
|
File.unlink marshal
|
|
|
|
end
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
def test_class_binary_japanese_text
|
|
|
|
file_name = File.expand_path '../test.ja.txt', __FILE__
|
|
|
|
refute @RP.binary?(file_name)
|
|
|
|
end
|
|
|
|
|
2010-12-28 17:08:56 -05:00
|
|
|
def test_class_binary_large_japanese_rdoc
|
2013-01-04 01:16:13 -05:00
|
|
|
capture_io do
|
|
|
|
begin
|
|
|
|
extenc, Encoding.default_external =
|
|
|
|
Encoding.default_external, Encoding::US_ASCII
|
|
|
|
file_name = File.expand_path '../test.ja.largedoc', __FILE__
|
|
|
|
assert !@RP.binary?(file_name)
|
|
|
|
ensure
|
|
|
|
Encoding.default_external = extenc
|
|
|
|
end
|
|
|
|
end
|
2010-12-28 17:08:56 -05:00
|
|
|
end
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
def test_class_binary_japanese_rdoc
|
|
|
|
file_name = File.expand_path '../test.ja.rdoc', __FILE__
|
|
|
|
refute @RP.binary?(file_name)
|
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
def test_class_can_parse
|
|
|
|
assert_equal @RP.can_parse(__FILE__), @RP::Ruby
|
|
|
|
|
|
|
|
readme_file_name = File.expand_path '../test.txt', __FILE__
|
2008-09-24 22:43:03 -04:00
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
assert_equal @RP::Simple, @RP.can_parse(readme_file_name)
|
|
|
|
|
2013-01-04 01:16:13 -05:00
|
|
|
assert_equal @RP::Simple, @RP.can_parse(@binary_dat)
|
2010-04-01 03:45:16 -04:00
|
|
|
|
|
|
|
jtest_file_name = File.expand_path '../test.ja.txt', __FILE__
|
|
|
|
assert_equal @RP::Simple, @RP.can_parse(jtest_file_name)
|
|
|
|
|
|
|
|
jtest_rdoc_file_name = File.expand_path '../test.ja.rdoc', __FILE__
|
2010-04-10 02:36:13 -04:00
|
|
|
assert_equal @RP::Simple, @RP.can_parse(jtest_rdoc_file_name)
|
|
|
|
|
|
|
|
readme_file_name = File.expand_path '../README', __FILE__
|
|
|
|
assert_equal @RP::Simple, @RP.can_parse(readme_file_name)
|
2012-05-03 12:33:22 -04:00
|
|
|
|
2013-01-04 01:16:13 -05:00
|
|
|
jtest_largerdoc_file_name = File.expand_path '../test.ja.largedoc', __FILE__
|
|
|
|
assert_equal @RP::Simple, @RP.can_parse(jtest_largerdoc_file_name)
|
2012-05-03 12:33:22 -04:00
|
|
|
|
2013-01-04 01:16:13 -05:00
|
|
|
@RP.alias_extension 'rdoc', 'largedoc'
|
|
|
|
assert_equal @RP::Simple, @RP.can_parse(jtest_largerdoc_file_name)
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
2012-12-18 03:24:57 -05:00
|
|
|
def test_class_for_executable
|
|
|
|
temp_dir do
|
|
|
|
content = "#!/usr/bin/env ruby -w\n"
|
|
|
|
open 'app', 'w' do |io| io.write content end
|
|
|
|
app = @store.add_file 'app'
|
2013-01-04 01:16:13 -05:00
|
|
|
|
2012-12-18 03:24:57 -05:00
|
|
|
parser = @RP.for app, 'app', content, @options, :stats
|
|
|
|
|
|
|
|
assert_kind_of RDoc::Parser::Ruby, parser
|
|
|
|
|
|
|
|
assert_equal 'app', parser.file_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-04 01:16:13 -05:00
|
|
|
def test_class_for_forbidden
|
|
|
|
skip 'chmod not supported' if Gem.win_platform?
|
|
|
|
|
2014-09-04 21:41:25 -04:00
|
|
|
tf = Tempfile.open 'forbidden' do |io|
|
2013-01-04 01:16:13 -05:00
|
|
|
begin
|
|
|
|
File.chmod 0000, io.path
|
|
|
|
forbidden = @store.add_file io.path
|
|
|
|
|
|
|
|
parser = @RP.for forbidden, 'forbidden', '', @options, :stats
|
|
|
|
|
|
|
|
assert_nil parser
|
|
|
|
ensure
|
|
|
|
File.chmod 0400, io.path
|
|
|
|
end
|
2014-09-04 21:41:25 -04:00
|
|
|
io
|
2013-01-04 01:16:13 -05:00
|
|
|
end
|
2014-09-04 21:41:25 -04:00
|
|
|
tf.close! if tf.respond_to? :close!
|
2013-01-04 01:16:13 -05:00
|
|
|
end
|
|
|
|
|
2013-09-18 19:33:36 -04:00
|
|
|
def test_class_for_modeline
|
|
|
|
temp_dir do
|
|
|
|
content = "# -*- rdoc -*-\n= NEWS\n"
|
|
|
|
|
|
|
|
open 'NEWS', 'w' do |io| io.write content end
|
|
|
|
app = @store.add_file 'NEWS'
|
|
|
|
|
|
|
|
parser = @RP.for app, 'NEWS', content, @options, :stats
|
|
|
|
|
|
|
|
assert_kind_of RDoc::Parser::Simple, parser
|
|
|
|
|
|
|
|
assert_equal "= NEWS\n", parser.content
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-01 17:24:53 -05:00
|
|
|
def test_can_parse_modeline
|
|
|
|
readme_ext = File.join Dir.tmpdir, "README.EXT.#{$$}"
|
|
|
|
|
|
|
|
open readme_ext, 'w' do |io|
|
|
|
|
io.puts "# README.EXT - -*- rdoc -*- created at: Mon Aug 7 16:45:54 JST 1995"
|
|
|
|
io.puts
|
|
|
|
io.puts "This document explains how to make extension libraries for Ruby."
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal RDoc::Parser::Simple, @RP.can_parse(readme_ext)
|
|
|
|
ensure
|
|
|
|
File.unlink readme_ext
|
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
##
|
|
|
|
# Selenium hides a .jar file using a .txt extension.
|
|
|
|
|
|
|
|
def test_class_can_parse_zip
|
|
|
|
hidden_zip = File.expand_path '../hidden.zip.txt', __FILE__
|
|
|
|
assert_nil @RP.can_parse(hidden_zip)
|
2008-09-24 22:43:03 -04:00
|
|
|
end
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2012-12-01 17:24:53 -05:00
|
|
|
def test_check_modeline
|
|
|
|
readme_ext = File.join Dir.tmpdir, "README.EXT.#{$$}"
|
|
|
|
|
|
|
|
open readme_ext, 'w' do |io|
|
|
|
|
io.puts "# README.EXT - -*- RDoc -*- created at: Mon Aug 7 16:45:54 JST 1995"
|
|
|
|
io.puts
|
|
|
|
io.puts "This document explains how to make extension libraries for Ruby."
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal 'rdoc', @RP.check_modeline(readme_ext)
|
|
|
|
ensure
|
|
|
|
File.unlink readme_ext
|
|
|
|
end
|
|
|
|
|
2013-01-04 01:16:13 -05:00
|
|
|
def test_check_modeline_coding
|
|
|
|
readme_ext = File.join Dir.tmpdir, "README.EXT.#{$$}"
|
|
|
|
|
|
|
|
open readme_ext, 'w' do |io|
|
|
|
|
io.puts "# -*- coding: utf-8 -*-"
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_nil @RP.check_modeline readme_ext
|
|
|
|
ensure
|
|
|
|
File.unlink readme_ext
|
|
|
|
end
|
|
|
|
|
2012-12-02 17:52:57 -05:00
|
|
|
def test_check_modeline_with_other
|
|
|
|
readme_ext = File.join Dir.tmpdir, "README.EXT.#{$$}"
|
|
|
|
|
|
|
|
open readme_ext, 'w' do |io|
|
|
|
|
io.puts "# README.EXT - -*- mode: RDoc; indent-tabs-mode: nil -*-"
|
|
|
|
io.puts
|
|
|
|
io.puts "This document explains how to make extension libraries for Ruby."
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal 'rdoc', @RP.check_modeline(readme_ext)
|
|
|
|
ensure
|
|
|
|
File.unlink readme_ext
|
|
|
|
end
|
|
|
|
|
2012-12-01 17:24:53 -05:00
|
|
|
def test_check_modeline_no_modeline
|
|
|
|
readme_ext = File.join Dir.tmpdir, "README.EXT.#{$$}"
|
|
|
|
|
|
|
|
open readme_ext, 'w' do |io|
|
|
|
|
io.puts "This document explains how to make extension libraries for Ruby."
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_nil @RP.check_modeline(readme_ext)
|
|
|
|
ensure
|
|
|
|
File.unlink readme_ext
|
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
def test_class_for_binary
|
|
|
|
rp = @RP.dup
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
class << rp
|
|
|
|
alias old_can_parse can_parse
|
|
|
|
end
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
def rp.can_parse(*args) nil end
|
|
|
|
|
|
|
|
assert_nil @RP.for(nil, @binary_dat, nil, nil, nil)
|
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
def test_class_for_markup
|
|
|
|
content = <<-CONTENT
|
|
|
|
# coding: utf-8 markup: rd
|
|
|
|
CONTENT
|
|
|
|
|
|
|
|
parser = @RP.for @top_level, __FILE__, content, @options, nil
|
|
|
|
|
|
|
|
assert_kind_of @RP::RD, parser
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_use_markup
|
|
|
|
content = <<-CONTENT
|
|
|
|
# coding: utf-8 markup: rd
|
|
|
|
CONTENT
|
|
|
|
|
|
|
|
parser = @RP.use_markup content
|
|
|
|
|
|
|
|
assert_equal @RP::RD, parser
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_use_markup_markdown
|
|
|
|
content = <<-CONTENT
|
|
|
|
# coding: utf-8 markup: markdown
|
|
|
|
CONTENT
|
|
|
|
|
|
|
|
parser = @RP.use_markup content
|
|
|
|
|
|
|
|
assert_equal @RP::Ruby, parser
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_use_markup_modeline
|
|
|
|
content = <<-CONTENT
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# markup: rd
|
|
|
|
CONTENT
|
|
|
|
|
|
|
|
parser = @RP.use_markup content
|
|
|
|
|
|
|
|
assert_equal @RP::RD, parser
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_use_markup_modeline_shebang
|
|
|
|
content = <<-CONTENT
|
|
|
|
#!/bin/sh
|
|
|
|
/* -*- coding: utf-8 -*-
|
|
|
|
* markup: rd
|
|
|
|
*/
|
|
|
|
CONTENT
|
|
|
|
|
|
|
|
parser = @RP.use_markup content
|
|
|
|
|
|
|
|
assert_equal @RP::RD, parser
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_use_markup_shebang
|
|
|
|
content = <<-CONTENT
|
|
|
|
#!/usr/bin/env ruby
|
|
|
|
# coding: utf-8 markup: rd
|
|
|
|
CONTENT
|
|
|
|
|
|
|
|
parser = @RP.use_markup content
|
|
|
|
|
|
|
|
assert_equal @RP::RD, parser
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_use_markup_tomdoc
|
|
|
|
content = <<-CONTENT
|
|
|
|
# coding: utf-8 markup: tomdoc
|
|
|
|
CONTENT
|
|
|
|
|
|
|
|
parser = @RP.use_markup content
|
|
|
|
|
|
|
|
assert_equal @RP::Ruby, parser
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_use_markup_none
|
|
|
|
parser = @RP.use_markup ''
|
|
|
|
|
|
|
|
assert_nil parser
|
|
|
|
end
|
|
|
|
|
2013-12-02 19:42:49 -05:00
|
|
|
def test_class_use_markup_unknown
|
|
|
|
content = <<-CONTENT
|
|
|
|
# :markup: RDoc
|
|
|
|
CONTENT
|
|
|
|
|
|
|
|
parser = @RP.use_markup content
|
|
|
|
|
|
|
|
assert_nil parser
|
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
def test_initialize
|
|
|
|
@RP.new @top_level, @fn, '', @options, nil
|
|
|
|
|
|
|
|
assert_equal @RP, @top_level.parser
|
|
|
|
end
|
|
|
|
|
2008-09-24 22:43:03 -04:00
|
|
|
end
|