summaryrefslogtreecommitdiff
path: root/test/functional/word_list.rb
diff options
context:
space:
mode:
authormurphy <murphy@rubychan.de>2006-10-20 07:06:40 +0000
committermurphy <murphy@rubychan.de>2006-10-20 07:06:40 +0000
commit95a9f131d9359258f0eda8371b7d0373c3ef0b21 (patch)
tree3bb4f31816f06767d263870f9f04922e668f6ad4 /test/functional/word_list.rb
parentb29f1786692e0416a6dc71474859f60af471ed42 (diff)
downloadcoderay-95a9f131d9359258f0eda8371b7d0373c3ef0b21.tar.gz
Added WordList tests. Renamed Basic to BasicTest.
Diffstat (limited to 'test/functional/word_list.rb')
-rw-r--r--test/functional/word_list.rb64
1 files changed, 64 insertions, 0 deletions
diff --git a/test/functional/word_list.rb b/test/functional/word_list.rb
new file mode 100644
index 0000000..c710d77
--- /dev/null
+++ b/test/functional/word_list.rb
@@ -0,0 +1,64 @@
+require "test/unit"
+require "coderay"
+
+class WordListTest < Test::Unit::TestCase
+
+ # define word arrays
+ RESERVED_WORDS = %w[
+ asm break case continue default do else
+ ...
+ ]
+
+ PREDEFINED_TYPES = %w[
+ int long short char void
+ ...
+ ]
+
+ PREDEFINED_CONSTANTS = %w[
+ EOF NULL ...
+ ]
+
+ # make a WordList
+ IDENT_KIND = WordList.new(:ident).
+ add(RESERVED_WORDS, :reserved).
+ add(PREDEFINED_TYPES, :pre_type).
+ add(PREDEFINED_CONSTANTS, :pre_constant)
+
+ def test_word_list_example
+ assert_equal :pre_type, IDENT_KIND['void']
+ # assert_equal :pre_constant, IDENT_KIND['...'] # not specified
+ end
+
+ def test_word_list
+ list = WordList.new(:ident).add(['foobar'], :reserved)
+ assert_equal :reserved, list['foobar']
+ assert_equal :ident, list['FooBar']
+ end
+
+ def test_word_list_cached
+ list = WordList.new(:ident, true).add(['foobar'], :reserved)
+ assert_equal :reserved, list['foobar']
+ assert_equal :ident, list['FooBar']
+ end
+
+ def test_case_ignoring_word_list
+ list = CaseIgnoringWordList.new(:ident).add(['foobar'], :reserved)
+ assert_equal :reserved, list['foobar']
+ assert_equal :reserved, list['FooBar']
+
+ list = CaseIgnoringWordList.new(:ident).add(['FooBar'], :reserved)
+ assert_equal :reserved, list['foobar']
+ assert_equal :reserved, list['FooBar']
+ end
+
+ def test_case_ignoring_word_list_cached
+ list = CaseIgnoringWordList.new(:ident, true).add(['foobar'], :reserved)
+ assert_equal :reserved, list['foobar']
+ assert_equal :reserved, list['FooBar']
+
+ list = CaseIgnoringWordList.new(:ident, true).add(['FooBar'], :reserved)
+ assert_equal :reserved, list['foobar']
+ assert_equal :reserved, list['FooBar']
+ end
+
+end \ No newline at end of file