summaryrefslogtreecommitdiff
path: root/test/rdoc/test_attribute_manager.rb
blob: ee45c0596f1d9faf2f4a39db20ed63755e56f64b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
require 'rubygems'
require 'minitest/unit'
require 'rdoc/markup/attribute_manager'

class TestAttributeManager < MiniTest::Unit::TestCase

  def setup
    @am = RDoc::Markup::AttributeManager.new
    @klass = RDoc::Markup::AttributeManager
  end

  def teardown
    silently do
      @klass.const_set(:MATCHING_WORD_PAIRS, {})
      @klass.const_set(:WORD_PAIR_MAP, {})
      @klass.const_set(:HTML_TAGS, {})
    end
  end

  def test_initial_word_pairs
    word_pairs = @klass::MATCHING_WORD_PAIRS
    assert word_pairs.is_a?(Hash)
    assert_equal(3, word_pairs.size)
  end

  def test_initial_html
    html_tags = @klass::HTML_TAGS
    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)
    word_pairs = @klass::MATCHING_WORD_PAIRS
    assert_equal(4,word_pairs.size)
    assert(word_pairs.has_key?("x"))
  end

  def test_add_invalid_word_pair
    assert_raises ArgumentError do
      @am.add_word_pair("<", "<", :TEST)
    end
  end

  def test_add_word_pair_map
    @am.add_word_pair("x", "y", :TEST)
    word_pair_map = @klass::WORD_PAIR_MAP
    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)
    tags = @klass::HTML_TAGS
    assert_equal(6, tags.size)
    assert(tags.has_key?("test"))
  end

  def test_add_special
    @am.add_special("WikiWord", :WIKIWORD)
    specials = @klass::SPECIAL
    assert_equal(1,specials.size)
    assert(specials.has_key?("WikiWord"))
  end

  def silently(&block)
    warn_level = $VERBOSE
    $VERBOSE = nil
    result = block.call
    $VERBOSE = warn_level
    result
  end

end

MiniTest::Unit.autorun