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 TestAttributeManager < RDoc::TestCase # HACK fix test name
|
2008-09-24 22:43:03 -04:00
|
|
|
|
|
|
|
def setup
|
2012-11-26 23:28:14 -05:00
|
|
|
super
|
|
|
|
|
|
|
|
@options = RDoc::Options.new
|
|
|
|
|
2008-09-24 22:43:03 -04:00
|
|
|
@am = RDoc::Markup::AttributeManager.new
|
|
|
|
@klass = RDoc::Markup::AttributeManager
|
2012-11-26 23:28:14 -05:00
|
|
|
@formatter = RDoc::Markup::Formatter.new @options
|
2010-12-19 22:22:49 -05:00
|
|
|
@formatter.add_tag :BOLD, '<B>', '</B>'
|
|
|
|
@formatter.add_tag :EM, '<EM>', '</EM>'
|
2012-11-26 23:28:14 -05:00
|
|
|
@formatter.add_tag :TT, '<CODE>', '</CODE>'
|
2008-09-24 22:43:03 -04:00
|
|
|
end
|
2008-10-24 19:05:28 -04:00
|
|
|
|
2010-07-14 17:13:41 -04:00
|
|
|
def test_convert_attrs_ignores_code
|
2012-11-26 23:28:14 -05:00
|
|
|
assert_equal 'foo <CODE>__send__</CODE> bar', output('foo <code>__send__</code> bar')
|
2010-07-14 17:13:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_convert_attrs_ignores_tt
|
2012-11-26 23:28:14 -05:00
|
|
|
assert_equal 'foo <CODE>__send__</CODE> bar', output('foo <tt>__send__</tt> bar')
|
2010-12-19 22:22:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_convert_attrs_preserves_double
|
|
|
|
assert_equal 'foo.__send__ :bar', output('foo.__send__ :bar')
|
|
|
|
assert_equal 'use __FILE__ to', output('use __FILE__ to')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_convert_attrs_does_not_ignore_after_tt
|
2012-11-26 23:28:14 -05:00
|
|
|
assert_equal 'the <CODE>IF:</CODE><EM>key</EM> directive', output('the <tt>IF:</tt>_key_ directive')
|
2010-07-14 17:13:41 -04:00
|
|
|
end
|
|
|
|
|
2008-09-24 22:43:03 -04:00
|
|
|
def test_initial_word_pairs
|
2010-04-01 03:45:16 -04:00
|
|
|
word_pairs = @am.matching_word_pairs
|
2008-09-24 22:43:03 -04:00
|
|
|
assert word_pairs.is_a?(Hash)
|
|
|
|
assert_equal(3, word_pairs.size)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_initial_html
|
2010-04-01 03:45:16 -04:00
|
|
|
html_tags = @am.html_tags
|
2008-09-24 22:43:03 -04:00
|
|
|
assert html_tags.is_a?(Hash)
|
|
|
|
assert_equal(5, html_tags.size)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_add_matching_word_pair
|
|
|
|
@am.add_word_pair("x","x", :TEST)
|
2010-04-01 03:45:16 -04:00
|
|
|
word_pairs = @am.matching_word_pairs
|
2008-09-24 22:43:03 -04:00
|
|
|
assert_equal(4,word_pairs.size)
|
|
|
|
assert(word_pairs.has_key?("x"))
|
|
|
|
end
|
2008-10-24 19:05:28 -04:00
|
|
|
|
2008-09-24 22:43:03 -04:00
|
|
|
def test_add_invalid_word_pair
|
2008-10-24 19:05:28 -04:00
|
|
|
assert_raises ArgumentError do
|
2008-09-24 22:43:03 -04:00
|
|
|
@am.add_word_pair("<", "<", :TEST)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_add_word_pair_map
|
|
|
|
@am.add_word_pair("x", "y", :TEST)
|
2010-04-01 03:45:16 -04:00
|
|
|
word_pair_map = @am.word_pair_map
|
2008-09-24 22:43:03 -04:00
|
|
|
assert_equal(1,word_pair_map.size)
|
|
|
|
assert_equal(word_pair_map. keys.first.source, "(x)(\\S+)(y)")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_add_html_tag
|
|
|
|
@am.add_html("Test", :TEST)
|
2010-04-01 03:45:16 -04:00
|
|
|
tags = @am.html_tags
|
2008-09-24 22:43:03 -04:00
|
|
|
assert_equal(6, tags.size)
|
|
|
|
assert(tags.has_key?("test"))
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_add_special
|
2012-11-26 23:28:14 -05:00
|
|
|
@am.add_special "WikiWord", :WIKIWORD
|
2010-04-01 03:45:16 -04:00
|
|
|
specials = @am.special
|
2012-11-26 23:28:14 -05:00
|
|
|
|
|
|
|
assert_equal 1, specials.size
|
|
|
|
assert specials.assoc "WikiWord"
|
2008-09-24 22:43:03 -04:00
|
|
|
end
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
def test_escapes
|
2012-11-26 23:28:14 -05:00
|
|
|
assert_equal '<CODE>text</CODE>', output('<tt>text</tt>')
|
|
|
|
assert_equal '<tt>text</tt>', output('\\<tt>text</tt>')
|
|
|
|
assert_equal '<tt>', output('\\<tt>')
|
|
|
|
assert_equal '<CODE><tt></CODE>', output('<tt>\\<tt></tt>')
|
|
|
|
assert_equal '<CODE>\\<tt></CODE>', output('<tt>\\\\<tt></tt>')
|
|
|
|
assert_equal '<B>text</B>', output('*text*')
|
|
|
|
assert_equal '*text*', output('\\*text*')
|
|
|
|
assert_equal '\\', output('\\')
|
|
|
|
assert_equal '\\text', output('\\text')
|
|
|
|
assert_equal '\\\\text', output('\\\\text')
|
|
|
|
assert_equal 'text \\ text', output('text \\ text')
|
|
|
|
|
|
|
|
assert_equal 'and <CODE>\\s</CODE> matches space',
|
2010-12-19 22:22:49 -05:00
|
|
|
output('and <tt>\\s</tt> matches space')
|
2012-11-26 23:28:14 -05:00
|
|
|
assert_equal 'use <CODE><tt>text</CODE></tt> for code',
|
2010-12-19 22:22:49 -05:00
|
|
|
output('use <tt>\\<tt>text</tt></tt> for code')
|
2012-11-26 23:28:14 -05:00
|
|
|
assert_equal 'use <CODE><tt>text</tt></CODE> for code',
|
2010-12-19 22:22:49 -05:00
|
|
|
output('use <tt>\\<tt>text\\</tt></tt> for code')
|
|
|
|
assert_equal 'use <tt><tt>text</tt></tt> for code',
|
|
|
|
output('use \\<tt>\\<tt>text</tt></tt> for code')
|
2012-11-26 23:28:14 -05:00
|
|
|
assert_equal 'use <tt><CODE>text</CODE></tt> for code',
|
2010-12-19 22:22:49 -05:00
|
|
|
output('use \\<tt><tt>text</tt></tt> for code')
|
2012-11-26 23:28:14 -05:00
|
|
|
assert_equal 'use <CODE>+text+</CODE> for code',
|
2010-12-19 22:22:49 -05:00
|
|
|
output('use <tt>\\+text+</tt> for code')
|
2012-11-26 23:28:14 -05:00
|
|
|
assert_equal 'use <tt><CODE>text</CODE></tt> for code',
|
2010-12-19 22:22:49 -05:00
|
|
|
output('use \\<tt>+text+</tt> for code')
|
|
|
|
assert_equal 'illegal <tag>not</tag> changed',
|
|
|
|
output('illegal <tag>not</tag> changed')
|
|
|
|
assert_equal 'unhandled <p>tag</p> unchanged',
|
|
|
|
output('unhandled <p>tag</p> unchanged')
|
|
|
|
end
|
|
|
|
|
|
|
|
def output str
|
|
|
|
@formatter.convert_flow @am.flow str
|
2008-09-24 22:43:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2008-10-24 19:05:28 -04:00
|
|
|
|