summaryrefslogtreecommitdiff
path: root/test/unit/word_list.rb
diff options
context:
space:
mode:
authormurphy <murphy@rubychan.de>2010-06-29 06:32:30 +0000
committermurphy <murphy@rubychan.de>2010-06-29 06:32:30 +0000
commit93dfad17309f46d00d1043592efdb282d13963fe (patch)
tree60cbfc2fbc3497f95f5d02de1e9ec8c7b10515ff /test/unit/word_list.rb
parent87764c224cc8c808688e83d7c1f93c8dbbbd9b4f (diff)
downloadcoderay-93dfad17309f46d00d1043592efdb282d13963fe.tar.gz
Added lots of unit tests.
Theses actually come from the library files; now they are included. Also, rake test and test:all don't test the scanners now; you have to start them using rake test:scanners.
Diffstat (limited to 'test/unit/word_list.rb')
-rw-r--r--test/unit/word_list.rb79
1 files changed, 79 insertions, 0 deletions
diff --git a/test/unit/word_list.rb b/test/unit/word_list.rb
new file mode 100644
index 0000000..449c9dc
--- /dev/null
+++ b/test/unit/word_list.rb
@@ -0,0 +1,79 @@
+require 'test/unit'
+require 'coderay/helpers/word_list'
+
+class WordListTest < Test::Unit::TestCase
+
+ include CodeRay
+
+ # 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 :ident, list['foo']
+ assert_equal :reserved, list['foobar']
+ assert_equal :reserved, list['FooBar']
+
+ list = CaseIgnoringWordList.new(:ident).add(['FooBar'], :reserved)
+ assert_equal :ident, list['foo']
+ 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 :ident, list['foo']
+ assert_equal :reserved, list['foobar']
+ assert_equal :reserved, list['FooBar']
+
+ list = CaseIgnoringWordList.new(:ident, true).add(['FooBar'], :reserved)
+ assert_equal :ident, list['foo']
+ assert_equal :reserved, list['foobar']
+ assert_equal :reserved, list['FooBar']
+ end
+
+ def test_dup
+ list = WordList.new(:ident).add(['foobar'], :reserved)
+ assert_equal :reserved, list['foobar']
+ list2 = list.dup
+ list2.add(%w[foobar], :keyword)
+ assert_equal :keyword, list2['foobar']
+ assert_equal :reserved, list['foobar']
+ end
+
+end \ No newline at end of file