From 08bf50f63a1ebf484c6e29d978a832fdbc873fac Mon Sep 17 00:00:00 2001 From: Evan Weaver Date: Fri, 2 Dec 2011 17:30:05 -0800 Subject: [PATCH] Enforce argument types better. --- CHANGELOG | 2 ++ ext/raspell.c | 12 +++++++----- test/simple_test.rb | 18 +++++++++++++----- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index af07e78..e3020cf 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +v1.3. Enforce argument types better (raskhadafi). + v1.2.2. Support for some changes from Ruby 1.9.1 to 1.9.2 (dmarkow). v1.2. Ruby 1.9 compatibility (ph7). diff --git a/ext/raspell.c b/ext/raspell.c index 52812b6..0682796 100644 --- a/ext/raspell.c +++ b/ext/raspell.c @@ -43,7 +43,7 @@ static VALUE dictinfo_size_str(VALUE self) { void Init_dictinfo() { //CLASS DEFINITION========================================================= cDictInfo = rb_define_class("AspellDictInfo", rb_cObject); - + //CLASS METHODS============================================================ rb_define_singleton_method(cDictInfo, "new", dictinfo_s_new, 0); @@ -289,7 +289,7 @@ static VALUE aspell_s_list_dicts(VALUE klass) { } /** - * @see set_option. + * @see set_option. */ static VALUE aspell_set_option(VALUE self, VALUE option, VALUE value) { AspellSpeller *speller = get_speller(self); @@ -400,7 +400,7 @@ static VALUE aspell_add_to_session(VALUE self, VALUE word) { /** * Retrieve the value of a specific option. - * The options are listed inside + * The options are listed inside * Aspell::[DictionaryOptions|CheckerOptions|FilterOptions|RunTogetherOptions|MiscOptions|UtilityOptions] * @param word the option as string. */ @@ -489,7 +489,7 @@ static VALUE aspell_check(VALUE self, VALUE word) { * This method needs a block to work proper. Each misspelled word is yielded, * a correct word as result from the block is assumed. * Common use: - * + * * a = Aspell.new(...) * text = ... * a.correct_lines(text) { |badword| @@ -497,7 +497,7 @@ static VALUE aspell_check(VALUE self, VALUE word) { * puts a.suggest(badword).join(" | ") * gets #the input is returned as right word * } - * + * * @param ary the array of strings to check. * @result an array holding all lines with corrected words. */ @@ -601,6 +601,7 @@ static VALUE aspell_correct_file(VALUE self, VALUE filename) { * @return array of strings: words that are misspelled. */ static VALUE aspell_list_misspelled(VALUE self, VALUE ary) { + Check_Type(ary, T_ARRAY); VALUE result = rb_hash_new(); //create checker AspellSpeller *speller = get_speller(self); @@ -613,6 +614,7 @@ static VALUE aspell_list_misspelled(VALUE self, VALUE ary) { while(c is wrong on the . And it was not the Apollo."], - @aspell.correct_lines(@text) { |word| "" }) + @aspell.correct_lines(@text) { |word| "" }) end def test_list_mispelled misspelled = @aspell.list_misspelled(@text).sort assert_equal(3, misspelled.length) end - + def test_suggest suggestions = @aspell.suggest("spel") - assert_equal [], + assert_equal [], ["spell", "spiel", "spew", "Opel", "spec", "sped"] - suggestions end @@ -30,7 +30,15 @@ def test_check assert_equal(false, @aspell.check("spel")) assert(@aspell.check("spell")) end - + + def test_argument_checking + assert_raises TypeError do + @aspell.list_misspelled "Not an array" + end + assert_raises TypeError do + @aspell.list_misspelled [123] + end + end end