2012-11-26 23:28:14 -05:00
|
|
|
require 'rdoc/test_case'
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
class TestRDocParserSimple < RDoc::TestCase
|
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
|
|
|
@tempfile = Tempfile.new self.class.name
|
|
|
|
filename = @tempfile.path
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
@top_level = @store.add_file filename
|
2010-04-01 03:45:16 -04:00
|
|
|
@fn = filename
|
|
|
|
@options = RDoc::Options.new
|
2012-11-26 23:28:14 -05:00
|
|
|
@stats = RDoc::Stats.new @store, 0
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
2012-11-26 23:28:14 -05:00
|
|
|
super
|
|
|
|
|
2014-05-26 09:33:01 -04:00
|
|
|
@tempfile.close!
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
2010-04-22 22:32:20 -04:00
|
|
|
def test_initialize_metadata
|
2010-04-26 23:45:22 -04:00
|
|
|
parser = util_parser ":unhandled: \n"
|
2010-04-22 22:32:20 -04:00
|
|
|
|
2010-04-26 23:45:22 -04:00
|
|
|
assert_includes @top_level.metadata, 'unhandled'
|
2010-04-22 22:32:20 -04:00
|
|
|
|
2010-04-26 23:45:22 -04:00
|
|
|
assert_equal ":unhandled: \n", parser.content
|
2010-04-22 22:32:20 -04:00
|
|
|
end
|
|
|
|
|
2010-04-10 02:36:13 -04:00
|
|
|
def test_remove_coding_comment
|
|
|
|
parser = util_parser <<-TEXT
|
|
|
|
# -*- mode: rdoc; coding: utf-8; fill-column: 74; -*-
|
|
|
|
|
|
|
|
Regular expressions (<i>regexp</i>s) are patterns which describe the
|
|
|
|
contents of a string.
|
|
|
|
TEXT
|
|
|
|
|
|
|
|
parser.scan
|
|
|
|
|
|
|
|
expected = <<-TEXT.strip
|
|
|
|
Regular expressions (<i>regexp</i>s) are patterns which describe the
|
|
|
|
contents of a string.
|
|
|
|
TEXT
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
assert_equal expected, @top_level.comment.text
|
2010-04-10 02:36:13 -04:00
|
|
|
end
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
# RDoc stops processing comments if it finds a comment line CONTAINING
|
|
|
|
# '<tt>#--</tt>'. This can be used to separate external from internal
|
|
|
|
# comments, or to stop a comment being associated with a method,
|
|
|
|
# class, or module. Commenting CAN be turned back on with
|
|
|
|
# a line that STARTS '<tt>#++</tt>'.
|
|
|
|
#
|
|
|
|
# I've seen guys that comment their code like this:
|
|
|
|
# # This method....
|
|
|
|
# #-----------------
|
|
|
|
# def method
|
|
|
|
#
|
|
|
|
# => either we do it only in ruby code, or we require the leading #
|
|
|
|
# (to avoid conflict with rules).
|
|
|
|
#
|
|
|
|
# TODO: require the leading #, to provide the feature in simple text files.
|
|
|
|
# Note: in ruby & C code, we require '#--' & '#++' or '*--' & '*++',
|
|
|
|
# to allow rules:
|
|
|
|
#
|
|
|
|
# # this is a comment
|
|
|
|
# #---
|
|
|
|
# # private text
|
|
|
|
# #+++
|
|
|
|
# # this is a rule:
|
|
|
|
# # ---
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
def test_remove_private_comments
|
2012-11-26 23:28:14 -05:00
|
|
|
parser = util_parser "foo\n\n--\nbar\n++\n\nbaz\n"
|
|
|
|
|
|
|
|
parser.scan
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
expected = "foo\n\n\nbaz"
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
assert_equal expected, @top_level.comment.text
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_remove_private_comments_rule
|
|
|
|
parser = util_parser "foo\n---\nbar"
|
|
|
|
|
|
|
|
parser.scan
|
|
|
|
|
|
|
|
expected = "foo\n---\nbar"
|
|
|
|
|
|
|
|
assert_equal expected, @top_level.comment.text
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_remove_private_comments_star
|
2012-11-26 23:28:14 -05:00
|
|
|
parser = util_parser "* foo\n* bar\n"
|
|
|
|
|
|
|
|
parser.scan
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
assert_equal "* foo\n* bar", @top_level.comment.text
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_scan
|
|
|
|
parser = util_parser 'it *really* works'
|
|
|
|
|
|
|
|
parser.scan
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
assert_equal 'it *really* works', @top_level.comment.text
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def util_parser(content)
|
|
|
|
RDoc::Parser::Simple.new @top_level, @fn, content, @options, @stats
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|