2008-10-24 19:05:28 -04:00
|
|
|
require 'rubygems'
|
2010-04-01 03:45:16 -04:00
|
|
|
require 'minitest/autorun'
|
2008-09-24 22:43:03 -04:00
|
|
|
require 'rdoc/parser'
|
2008-10-24 19:05:28 -04:00
|
|
|
require 'rdoc/parser/ruby'
|
2010-04-01 03:45:16 -04:00
|
|
|
require 'tmpdir'
|
2008-09-24 22:43:03 -04:00
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
class TestRDocParser < MiniTest::Unit::TestCase
|
2008-09-24 22:43:03 -04:00
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
def setup
|
|
|
|
@RP = RDoc::Parser
|
|
|
|
@binary_dat = File.expand_path '../binary.dat', __FILE__
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
2012-05-03 18:20:26 -04:00
|
|
|
extenc, Encoding.default_external = Encoding.default_external, Encoding::US_ASCII
|
2012-05-03 12:31:25 -04:00
|
|
|
file_name = File.expand_path '../test.ja.largedoc', __FILE__
|
2010-12-28 17:08:56 -05:00
|
|
|
assert !@RP.binary?(file_name)
|
2012-05-03 18:20:26 -04:00
|
|
|
ensure
|
|
|
|
Encoding.default_external = extenc
|
2010-12-28 17:08:56 -05:00
|
|
|
end
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
def test_class_binary_japanese_rdoc
|
|
|
|
skip "Encoding not implemented" unless Object.const_defined? :Encoding
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
assert_nil @RP.can_parse(@binary_dat)
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
jtest_largerdoc_file_name = File.expand_path '../test.ja.largedoc', __FILE__
|
|
|
|
assert_nil @RP.can_parse(jtest_largerdoc_file_name)
|
|
|
|
|
|
|
|
@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
|
|
|
|
|
|
|
|
##
|
|
|
|
# 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
|
|
|
|
|
|
|
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
|
|
|
|
|
2008-09-24 22:43:03 -04:00
|
|
|
end
|
2008-10-24 19:05:28 -04:00
|
|
|
|