To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / vendor / gems / coderay-0.9.7 / test / functional / word_list.rb @ 442:753f1380d6bc

History | View | Annotate | Download (2.12 KB)

1
require 'test/unit'
2
require 'coderay'
3

    
4
class WordListTest < Test::Unit::TestCase
5
  
6
  include CodeRay
7
  
8
  # define word arrays
9
  RESERVED_WORDS = %w[
10
    asm break case continue default do else
11
    ...
12
  ]
13
  
14
  PREDEFINED_TYPES = %w[
15
    int long short char void
16
    ...
17
  ]
18
  
19
  PREDEFINED_CONSTANTS = %w[
20
    EOF NULL ...
21
  ]
22
  
23
  # make a WordList
24
  IDENT_KIND = WordList.new(:ident).
25
    add(RESERVED_WORDS, :reserved).
26
    add(PREDEFINED_TYPES, :pre_type).
27
    add(PREDEFINED_CONSTANTS, :pre_constant)
28

    
29
  def test_word_list_example
30
    assert_equal :pre_type, IDENT_KIND['void']
31
    # assert_equal :pre_constant, IDENT_KIND['...']  # not specified
32
  end
33
  
34
  def test_word_list
35
    list = WordList.new(:ident).add(['foobar'], :reserved)
36
    assert_equal :reserved, list['foobar']
37
    assert_equal :ident, list['FooBar']
38
  end
39

    
40
  def test_word_list_cached
41
    list = WordList.new(:ident, true).add(['foobar'], :reserved)
42
    assert_equal :reserved, list['foobar']
43
    assert_equal :ident, list['FooBar']
44
  end
45

    
46
  def test_case_ignoring_word_list
47
    list = CaseIgnoringWordList.new(:ident).add(['foobar'], :reserved)
48
    assert_equal :ident, list['foo']
49
    assert_equal :reserved, list['foobar']
50
    assert_equal :reserved, list['FooBar']
51

    
52
    list = CaseIgnoringWordList.new(:ident).add(['FooBar'], :reserved)
53
    assert_equal :ident, list['foo']
54
    assert_equal :reserved, list['foobar']
55
    assert_equal :reserved, list['FooBar']
56
  end
57

    
58
  def test_case_ignoring_word_list_cached
59
    list = CaseIgnoringWordList.new(:ident, true).add(['foobar'], :reserved)
60
    assert_equal :ident, list['foo']
61
    assert_equal :reserved, list['foobar']
62
    assert_equal :reserved, list['FooBar']
63

    
64
    list = CaseIgnoringWordList.new(:ident, true).add(['FooBar'], :reserved)
65
    assert_equal :ident, list['foo']
66
    assert_equal :reserved, list['foobar']
67
    assert_equal :reserved, list['FooBar']
68
  end
69

    
70
  def test_dup
71
    list = WordList.new(:ident).add(['foobar'], :reserved)
72
    assert_equal :reserved, list['foobar']
73
    list2 = list.dup
74
    list2.add(%w[foobar], :keyword)
75
    assert_equal :keyword, list2['foobar']
76
    assert_equal :reserved, list['foobar']
77
  end
78

    
79
end