mirror of
https://github.com/ruby/ruby.git
synced 2025-08-24 13:34:17 +02:00
[ruby/rdoc] Drop unnecessary file_name
parameter from Parser.for
method.
(https://github.com/ruby/rdoc/pull/1135)
* Unify top_level creation in tests
* Remove unnecessary file_name param from Parser.for
It should be always the same as the top_level's absolute_name, so there's
no point of taking it as a separate parameter.
97c497dfbb
This commit is contained in:
parent
12a5400a88
commit
27c22f822a
3 changed files with 38 additions and 40 deletions
|
@ -166,7 +166,8 @@ class RDoc::Parser
|
||||||
# Finds and instantiates the correct parser for the given +file_name+ and
|
# Finds and instantiates the correct parser for the given +file_name+ and
|
||||||
# +content+.
|
# +content+.
|
||||||
|
|
||||||
def self.for top_level, file_name, content, options, stats
|
def self.for top_level, content, options, stats
|
||||||
|
file_name = top_level.absolute_name
|
||||||
return if binary? file_name
|
return if binary? file_name
|
||||||
|
|
||||||
parser = use_markup content
|
parser = use_markup content
|
||||||
|
|
|
@ -356,7 +356,7 @@ option)
|
||||||
|
|
||||||
top_level = @store.add_file filename, relative_name: relative_path.to_s
|
top_level = @store.add_file filename, relative_name: relative_path.to_s
|
||||||
|
|
||||||
parser = RDoc::Parser.for top_level, filename, content, @options, @stats
|
parser = RDoc::Parser.for top_level, content, @options, @stats
|
||||||
|
|
||||||
return unless parser
|
return unless parser
|
||||||
|
|
||||||
|
|
|
@ -3,16 +3,12 @@
|
||||||
|
|
||||||
require_relative 'helper'
|
require_relative 'helper'
|
||||||
|
|
||||||
class TestRDocParser < RDoc::TestCase
|
class RDocParserTest < RDoc::TestCase
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
|
|
||||||
@RP = RDoc::Parser
|
@RP = RDoc::Parser
|
||||||
@binary_dat = File.expand_path '../binary.dat', __FILE__
|
@binary_dat_fixture_path = File.expand_path '../binary.dat', __FILE__
|
||||||
|
|
||||||
@fn = 'file.rb'
|
|
||||||
@top_level = RDoc::TopLevel.new @fn
|
|
||||||
@options = RDoc::Options.new
|
@options = RDoc::Options.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -71,7 +67,7 @@ class TestRDocParser < RDoc::TestCase
|
||||||
|
|
||||||
assert_equal @RP::Simple, @RP.can_parse(readme_file_name)
|
assert_equal @RP::Simple, @RP.can_parse(readme_file_name)
|
||||||
|
|
||||||
assert_equal @RP::Simple, @RP.can_parse(@binary_dat)
|
assert_equal @RP::Simple, @RP.can_parse(@binary_dat_fixture_path)
|
||||||
|
|
||||||
jtest_file_name = File.expand_path '../test.ja.txt', __FILE__
|
jtest_file_name = File.expand_path '../test.ja.txt', __FILE__
|
||||||
assert_equal @RP::Simple, @RP.can_parse(jtest_file_name)
|
assert_equal @RP::Simple, @RP.can_parse(jtest_file_name)
|
||||||
|
@ -90,16 +86,12 @@ class TestRDocParser < RDoc::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_class_for_executable
|
def test_class_for_executable
|
||||||
temp_dir do
|
with_top_level("app", "#!/usr/bin/env ruby -w\n") do |top_level, content|
|
||||||
content = "#!/usr/bin/env ruby -w\n"
|
parser = @RP.for top_level, content, @options, :stats
|
||||||
File.open 'app', 'w' do |io| io.write content end
|
|
||||||
app = @store.add_file 'app'
|
|
||||||
|
|
||||||
parser = @RP.for app, 'app', content, @options, :stats
|
|
||||||
|
|
||||||
assert_kind_of RDoc::Parser::Ruby, parser
|
assert_kind_of RDoc::Parser::Ruby, parser
|
||||||
|
|
||||||
assert_equal 'app', parser.file_name
|
assert_equal top_level.absolute_name, parser.file_name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -111,7 +103,7 @@ class TestRDocParser < RDoc::TestCase
|
||||||
File.chmod 0000, io.path
|
File.chmod 0000, io.path
|
||||||
forbidden = @store.add_file io.path
|
forbidden = @store.add_file io.path
|
||||||
|
|
||||||
parser = @RP.for forbidden, 'forbidden', '', @options, :stats
|
parser = @RP.for forbidden, '', @options, :stats
|
||||||
|
|
||||||
assert_nil parser
|
assert_nil parser
|
||||||
ensure
|
ensure
|
||||||
|
@ -123,13 +115,8 @@ class TestRDocParser < RDoc::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_class_for_modeline
|
def test_class_for_modeline
|
||||||
temp_dir do
|
with_top_level("NEWS", "# -*- rdoc -*-\n= NEWS\n") do |top_level, content|
|
||||||
content = "# -*- rdoc -*-\n= NEWS\n"
|
parser = @RP.for top_level, content, @options, :stats
|
||||||
|
|
||||||
File.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_kind_of RDoc::Parser::Simple, parser
|
||||||
|
|
||||||
|
@ -226,25 +213,18 @@ class TestRDocParser < RDoc::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_class_for_binary
|
def test_class_for_binary
|
||||||
rp = @RP.dup
|
dat_fixture = File.read(@binary_dat_fixture_path)
|
||||||
|
with_top_level("binary.dat", dat_fixture) do |top_level, content|
|
||||||
class << rp
|
assert_nil @RP.for(top_level, content, @options, nil)
|
||||||
alias old_can_parse can_parse
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def rp.can_parse(*args) nil end
|
|
||||||
|
|
||||||
assert_nil @RP.for(nil, @binary_dat, nil, nil, nil)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_class_for_markup
|
def test_class_for_markup
|
||||||
content = <<-CONTENT
|
with_top_level("file.rb", "# coding: utf-8 markup: rd") do |top_level, content|
|
||||||
# coding: utf-8 markup: rd
|
parser = @RP.for top_level, content, @options, nil
|
||||||
CONTENT
|
|
||||||
|
|
||||||
parser = @RP.for @top_level, __FILE__, content, @options, nil
|
assert_kind_of @RP::RD, parser
|
||||||
|
end
|
||||||
assert_kind_of @RP::RD, parser
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_class_use_markup
|
def test_class_use_markup
|
||||||
|
@ -329,9 +309,26 @@ class TestRDocParser < RDoc::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_initialize
|
def test_initialize
|
||||||
@RP.new @top_level, @fn, '', @options, nil
|
with_top_level("file.rb", "") do |top_level, content|
|
||||||
|
@RP.new top_level, top_level.absolute_name, content, @options, nil
|
||||||
|
|
||||||
assert_equal @RP, @top_level.parser
|
assert_equal @RP, top_level.parser
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def with_top_level(filename, content, &block)
|
||||||
|
absoluate_filename = File.join Dir.tmpdir, filename
|
||||||
|
File.open absoluate_filename, 'w' do |io|
|
||||||
|
io.write content
|
||||||
|
end
|
||||||
|
|
||||||
|
top_level = RDoc::TopLevel.new absoluate_filename
|
||||||
|
|
||||||
|
yield(top_level, content)
|
||||||
|
ensure
|
||||||
|
File.unlink absoluate_filename
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue