2011-02-07 02:07:12 -05:00
|
|
|
# coding: utf-8
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
require 'rdoc/test_case'
|
2010-04-10 02:36:13 -04:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
class TestRDocMarkupPreProcess < RDoc::TestCase
|
2010-04-10 02:36:13 -04:00
|
|
|
|
|
|
|
def setup
|
2012-11-26 23:28:14 -05:00
|
|
|
super
|
2010-04-26 23:45:22 -04:00
|
|
|
|
2010-04-10 02:36:13 -04:00
|
|
|
@tempfile = Tempfile.new 'test_rdoc_markup_pre_process'
|
2010-12-19 22:22:49 -05:00
|
|
|
@file_name = File.basename @tempfile.path
|
2010-04-10 02:36:13 -04:00
|
|
|
@dir = File.dirname @tempfile.path
|
|
|
|
|
|
|
|
@pp = RDoc::Markup::PreProcess.new __FILE__, [@dir]
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
2012-11-26 23:28:14 -05:00
|
|
|
super
|
2011-07-30 20:19:00 -04:00
|
|
|
|
2010-04-10 02:36:13 -04:00
|
|
|
@tempfile.close
|
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
def test_class_register
|
|
|
|
RDoc::Markup::PreProcess.register 'for_test' do raise 'fail' end
|
|
|
|
|
|
|
|
assert_equal %w[for_test], RDoc::Markup::PreProcess.registered.keys
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_post_process
|
|
|
|
RDoc::Markup::PreProcess.post_process do end
|
|
|
|
|
|
|
|
assert_equal 1, RDoc::Markup::PreProcess.post_processors.length
|
|
|
|
end
|
|
|
|
|
2010-04-10 02:36:13 -04:00
|
|
|
def test_include_file
|
|
|
|
@tempfile.write <<-INCLUDE
|
|
|
|
# -*- mode: rdoc; coding: utf-8; fill-column: 74; -*-
|
|
|
|
|
|
|
|
Regular expressions (<i>regexp</i>s) are patterns which describe the
|
|
|
|
contents of a string.
|
|
|
|
INCLUDE
|
|
|
|
|
|
|
|
@tempfile.flush
|
|
|
|
@tempfile.rewind
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
content = @pp.include_file @file_name, '', nil
|
2010-04-10 02:36:13 -04:00
|
|
|
|
|
|
|
expected = <<-EXPECTED
|
|
|
|
Regular expressions (<i>regexp</i>s) are patterns which describe the
|
|
|
|
contents of a string.
|
|
|
|
EXPECTED
|
|
|
|
|
|
|
|
assert_equal expected, content
|
|
|
|
end
|
|
|
|
|
2011-02-07 02:07:12 -05:00
|
|
|
def test_include_file_encoding_incompatible
|
|
|
|
skip "Encoding not implemented" unless Object.const_defined? :Encoding
|
|
|
|
|
|
|
|
@tempfile.write <<-INCLUDE
|
|
|
|
# -*- mode: rdoc; coding: utf-8; fill-column: 74; -*-
|
|
|
|
|
|
|
|
π
|
|
|
|
INCLUDE
|
|
|
|
|
|
|
|
@tempfile.flush
|
|
|
|
@tempfile.rewind
|
|
|
|
|
|
|
|
content = @pp.include_file @file_name, '', Encoding::US_ASCII
|
|
|
|
|
|
|
|
expected = "?\n"
|
|
|
|
|
|
|
|
assert_equal expected, content
|
|
|
|
end
|
|
|
|
|
2010-04-26 23:45:22 -04:00
|
|
|
def test_handle
|
2011-07-30 20:19:00 -04:00
|
|
|
text = "# :main: M\n"
|
|
|
|
out = @pp.handle text
|
|
|
|
|
|
|
|
assert_same out, text
|
|
|
|
assert_equal "#\n", text
|
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
def test_handle_comment
|
|
|
|
text = "# :main: M\n"
|
|
|
|
c = comment text
|
|
|
|
|
|
|
|
out = @pp.handle c
|
|
|
|
|
|
|
|
assert_same out, text
|
|
|
|
assert_equal "#\n", text
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_handle_markup
|
|
|
|
c = comment ':markup: rd'
|
|
|
|
|
|
|
|
@pp.handle c
|
|
|
|
|
|
|
|
assert_equal 'rd', c.format
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_handle_markup_empty
|
|
|
|
c = comment ':markup:'
|
|
|
|
|
|
|
|
@pp.handle c
|
|
|
|
|
|
|
|
assert_equal 'rdoc', c.format
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_handle_post_process
|
|
|
|
cd = RDoc::CodeObject.new
|
|
|
|
|
|
|
|
RDoc::Markup::PreProcess.post_process do |text, code_object|
|
|
|
|
code_object.metadata[:stuff] = text
|
|
|
|
|
|
|
|
:junk
|
|
|
|
end
|
|
|
|
|
|
|
|
text = "# a b c\n"
|
|
|
|
|
|
|
|
out = @pp.handle text, cd
|
|
|
|
|
|
|
|
assert_same out, text
|
|
|
|
assert_equal "# a b c\n", text
|
|
|
|
assert_equal "# a b c\n", cd.metadata[:stuff]
|
|
|
|
end
|
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
def test_handle_unregistered
|
2010-04-26 23:45:22 -04:00
|
|
|
text = "# :x: y\n"
|
|
|
|
out = @pp.handle text
|
|
|
|
|
|
|
|
assert_same out, text
|
|
|
|
assert_equal "# :x: y\n", text
|
|
|
|
end
|
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
def test_handle_directive_blankline
|
|
|
|
result = @pp.handle_directive '#', 'arg', 'a, b'
|
|
|
|
|
|
|
|
assert_equal "#\n", result
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_handle_directive_downcase
|
|
|
|
method = RDoc::AnyMethod.new nil, 'm'
|
|
|
|
|
|
|
|
@pp.handle_directive '', 'ARG', 'a, b', method
|
|
|
|
|
|
|
|
assert_equal 'a, b', method.params
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_handle_directive_arg
|
|
|
|
method = RDoc::AnyMethod.new nil, 'm'
|
|
|
|
|
|
|
|
@pp.handle_directive '', 'arg', 'a, b', method
|
|
|
|
|
|
|
|
assert_equal 'a, b', method.params
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_handle_directive_arg_no_context
|
|
|
|
result = @pp.handle_directive '', 'arg', 'a, b', nil
|
|
|
|
|
|
|
|
assert_equal "\n", result
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_handle_directive_args
|
|
|
|
method = RDoc::AnyMethod.new nil, 'm'
|
2010-04-26 23:45:22 -04:00
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
@pp.handle_directive '', 'args', 'a, b', method
|
|
|
|
|
|
|
|
assert_equal 'a, b', method.params
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_handle_directive_block
|
|
|
|
result = @pp.handle_directive '', 'x', 'y' do |directive, param|
|
|
|
|
''
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_empty result
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_handle_directive_block_false
|
|
|
|
result = @pp.handle_directive '', 'x', 'y' do |directive, param|
|
2010-04-26 23:45:22 -04:00
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
assert_equal ":x: y\n", result
|
|
|
|
end
|
2010-04-26 23:45:22 -04:00
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
def test_handle_directive_block_nil
|
|
|
|
result = @pp.handle_directive '', 'x', 'y' do |directive, param|
|
|
|
|
nil
|
2010-04-26 23:45:22 -04:00
|
|
|
end
|
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
assert_equal ":x: y\n", result
|
2010-04-26 23:45:22 -04:00
|
|
|
end
|
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
def test_handle_directive_category
|
2011-06-16 00:59:24 -04:00
|
|
|
context = RDoc::Context.new
|
|
|
|
original_section = context.current_section
|
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
@pp.handle_directive '', 'category', 'other', context
|
2011-06-16 00:59:24 -04:00
|
|
|
|
|
|
|
refute_equal original_section, context.current_section
|
|
|
|
end
|
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
def test_handle_directive_doc
|
|
|
|
code_object = RDoc::CodeObject.new
|
|
|
|
code_object.document_self = false
|
|
|
|
code_object.force_documentation = false
|
2010-04-26 23:45:22 -04:00
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
@pp.handle_directive '', 'doc', nil, code_object
|
|
|
|
|
|
|
|
assert code_object.document_self
|
|
|
|
assert code_object.force_documentation
|
|
|
|
end
|
2010-04-26 23:45:22 -04:00
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
def test_handle_directive_doc_no_context
|
|
|
|
result = @pp.handle_directive '', 'doc', nil
|
2010-04-26 23:45:22 -04:00
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
assert_equal "\n", result
|
2010-04-26 23:45:22 -04:00
|
|
|
end
|
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
def test_handle_directive_enddoc
|
|
|
|
code_object = RDoc::CodeObject.new
|
2010-04-26 23:45:22 -04:00
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
@pp.handle_directive '', 'enddoc', nil, code_object
|
2010-04-26 23:45:22 -04:00
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
assert code_object.done_documenting
|
|
|
|
end
|
2010-04-26 23:45:22 -04:00
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
def test_handle_directive_include
|
|
|
|
@tempfile.write 'included'
|
|
|
|
@tempfile.flush
|
2010-04-26 23:45:22 -04:00
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
result = @pp.handle_directive '', 'include', @file_name
|
2010-04-26 23:45:22 -04:00
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
assert_equal 'included', result
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_handle_directive_main
|
|
|
|
@pp.options = RDoc::Options.new
|
|
|
|
|
|
|
|
@pp.handle_directive '', 'main', 'M'
|
|
|
|
|
|
|
|
assert_equal 'M', @pp.options.main_page
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_handle_directive_notnew
|
|
|
|
m = RDoc::AnyMethod.new nil, 'm'
|
|
|
|
|
|
|
|
@pp.handle_directive '', 'notnew', nil, m
|
|
|
|
|
|
|
|
assert m.dont_rename_initialize
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_handle_directive_not_new
|
|
|
|
m = RDoc::AnyMethod.new nil, 'm'
|
|
|
|
|
|
|
|
@pp.handle_directive '', 'not_new', nil, m
|
|
|
|
|
|
|
|
assert m.dont_rename_initialize
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_handle_directive_not_dash_new
|
|
|
|
m = RDoc::AnyMethod.new nil, 'm'
|
|
|
|
|
|
|
|
@pp.handle_directive '', 'not-new', nil, m
|
|
|
|
|
|
|
|
assert m.dont_rename_initialize
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_handle_directive_nodoc
|
|
|
|
code_object = RDoc::CodeObject.new
|
|
|
|
code_object.document_self = true
|
|
|
|
code_object.document_children = true
|
2010-04-26 23:45:22 -04:00
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
@pp.handle_directive '', 'nodoc', nil, code_object
|
|
|
|
|
|
|
|
refute code_object.document_self
|
|
|
|
assert code_object.document_children
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_handle_directive_nodoc_all
|
|
|
|
code_object = RDoc::CodeObject.new
|
|
|
|
code_object.document_self = true
|
|
|
|
code_object.document_children = true
|
|
|
|
|
|
|
|
@pp.handle_directive '', 'nodoc', 'all', code_object
|
|
|
|
|
|
|
|
refute code_object.document_self
|
|
|
|
refute code_object.document_children
|
2010-04-26 23:45:22 -04:00
|
|
|
end
|
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
def test_handle_directive_nodoc_no_context
|
|
|
|
result = @pp.handle_directive '', 'nodoc', nil
|
|
|
|
|
|
|
|
assert_equal "\n", result
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_handle_directive_registered
|
2010-04-26 23:45:22 -04:00
|
|
|
RDoc::Markup::PreProcess.register 'x'
|
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
result = @pp.handle_directive '', 'x', 'y'
|
2010-04-26 23:45:22 -04:00
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
assert_nil result
|
2010-04-26 23:45:22 -04:00
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
result = @pp.handle_directive '', 'x', 'y' do |directive, param|
|
2010-04-26 23:45:22 -04:00
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
assert_equal ":x: y\n", result
|
2010-04-26 23:45:22 -04:00
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
result = @pp.handle_directive '', 'x', 'y' do |directive, param|
|
2010-04-26 23:45:22 -04:00
|
|
|
''
|
|
|
|
end
|
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
assert_equal '', result
|
2010-04-26 23:45:22 -04:00
|
|
|
end
|
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
def test_handle_directive_registered_block
|
2010-04-26 23:45:22 -04:00
|
|
|
called = nil
|
2011-07-30 20:19:00 -04:00
|
|
|
|
2010-04-26 23:45:22 -04:00
|
|
|
RDoc::Markup::PreProcess.register 'x' do |directive, param|
|
|
|
|
called = [directive, param]
|
|
|
|
'blah'
|
|
|
|
end
|
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
result = @pp.handle_directive '', 'x', 'y'
|
2010-04-26 23:45:22 -04:00
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
assert_equal 'blah', result
|
2010-04-26 23:45:22 -04:00
|
|
|
assert_equal %w[x y], called
|
|
|
|
end
|
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
def test_handle_directive_registered_code_object
|
2010-04-26 23:45:22 -04:00
|
|
|
RDoc::Markup::PreProcess.register 'x'
|
2011-07-30 20:19:00 -04:00
|
|
|
code_object = RDoc::CodeObject.new
|
2010-04-26 23:45:22 -04:00
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
@pp.handle_directive '', 'x', 'y', code_object
|
2010-04-26 23:45:22 -04:00
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
assert_equal 'y', code_object.metadata['x']
|
2010-04-26 23:45:22 -04:00
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
code_object.metadata.clear
|
2010-04-26 23:45:22 -04:00
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
result = @pp.handle_directive '', 'x', 'y' do |directive, param|
|
2010-04-26 23:45:22 -04:00
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
assert_equal ":x: y\n", result
|
|
|
|
assert_empty code_object.metadata
|
2010-04-26 23:45:22 -04:00
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
result = @pp.handle_directive '', 'x', 'y' do |directive, param|
|
|
|
|
''
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal '', result
|
|
|
|
assert_empty code_object.metadata
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_handle_directive_startdoc
|
|
|
|
code_object = RDoc::CodeObject.new
|
|
|
|
code_object.stop_doc
|
|
|
|
code_object.force_documentation = false
|
|
|
|
|
|
|
|
@pp.handle_directive '', 'startdoc', nil, code_object
|
|
|
|
|
|
|
|
assert code_object.document_self
|
|
|
|
assert code_object.document_children
|
|
|
|
assert code_object.force_documentation
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_handle_directive_stopdoc
|
|
|
|
code_object = RDoc::CodeObject.new
|
|
|
|
|
|
|
|
@pp.handle_directive '', 'stopdoc', nil, code_object
|
|
|
|
|
|
|
|
refute code_object.document_self
|
|
|
|
refute code_object.document_children
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_handle_directive_title
|
|
|
|
@pp.options = RDoc::Options.new
|
|
|
|
|
|
|
|
@pp.handle_directive '', 'title', 'T'
|
|
|
|
|
|
|
|
assert_equal 'T', @pp.options.title
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_handle_directive_unhandled
|
|
|
|
code_object = RDoc::CodeObject.new
|
|
|
|
|
|
|
|
@pp.handle_directive '', 'x', 'y', code_object
|
|
|
|
|
|
|
|
assert_equal 'y', code_object.metadata['x']
|
|
|
|
|
|
|
|
code_object.metadata.clear
|
|
|
|
|
|
|
|
@pp.handle_directive '', 'x', '', code_object
|
|
|
|
|
|
|
|
assert_includes code_object.metadata, 'x'
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_handle_directive_unhandled_block
|
|
|
|
code_object = RDoc::CodeObject.new
|
|
|
|
|
|
|
|
@pp.handle_directive '', 'x', 'y', code_object do
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_empty code_object.metadata
|
|
|
|
|
|
|
|
@pp.handle_directive '', 'x', 'y', code_object do
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal 'y', code_object.metadata['x']
|
2010-04-26 23:45:22 -04:00
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
code_object.metadata.clear
|
|
|
|
|
|
|
|
@pp.handle_directive '', 'x', 'y', code_object do
|
2010-04-26 23:45:22 -04:00
|
|
|
''
|
|
|
|
end
|
|
|
|
|
2011-07-30 20:19:00 -04:00
|
|
|
assert_empty code_object.metadata
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_handle_directive_yield
|
|
|
|
method = RDoc::AnyMethod.new nil, 'm'
|
|
|
|
method.params = 'index, &block'
|
|
|
|
|
|
|
|
@pp.handle_directive '', 'yield', 'item', method
|
|
|
|
|
|
|
|
assert_equal 'item', method.block_params
|
|
|
|
assert_equal 'index', method.params
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_handle_directive_yield_block_param
|
|
|
|
method = RDoc::AnyMethod.new nil, 'm'
|
|
|
|
method.params = '&block'
|
|
|
|
|
|
|
|
@pp.handle_directive '', 'yield', 'item', method
|
|
|
|
|
|
|
|
assert_equal 'item', method.block_params
|
|
|
|
assert_empty method.params
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_handle_directive_yield_no_context
|
|
|
|
method = RDoc::AnyMethod.new nil, 'm'
|
|
|
|
|
|
|
|
@pp.handle_directive '', 'yield', 'item', method
|
|
|
|
|
|
|
|
assert_equal 'item', method.block_params
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_handle_directive_yields
|
|
|
|
method = RDoc::AnyMethod.new nil, 'm'
|
|
|
|
|
|
|
|
@pp.handle_directive '', 'yields', 'item', method
|
|
|
|
|
|
|
|
assert_equal 'item', method.block_params
|
2010-04-26 23:45:22 -04:00
|
|
|
end
|
|
|
|
|
2010-04-10 02:36:13 -04:00
|
|
|
end
|
|
|
|
|