Skip to content

Commit

Permalink
Enforce argument types better.
Browse files Browse the repository at this point in the history
  • Loading branch information
evan committed Dec 3, 2011
1 parent c94d6bf commit 08bf50f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
2 changes: 2 additions & 0 deletions 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).
Expand Down
12 changes: 7 additions & 5 deletions ext/raspell.c
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -489,15 +489,15 @@ 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|
* puts "Error: #{badword}\n"
* 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.
*/
Expand Down Expand Up @@ -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);
Expand All @@ -613,6 +614,7 @@ static VALUE aspell_list_misspelled(VALUE self, VALUE ary) {
while(c<count) {
//process line
vline = RARRAY_PTR(ary)[c];
Check_Type(vline, T_STRING);
aspell_document_checker_process(checker, StringValuePtr(vline), -1);
//iterate over all misspelled words
while (token = aspell_document_checker_next_misspelling(checker), token.len != 0) {
Expand Down
18 changes: 13 additions & 5 deletions test/simple_test.rb
Expand Up @@ -9,28 +9,36 @@ def setup
@aspell = Aspell.new
@text = ["Hiere is somthing wrong on the planett. And it was not the Apollo."]
end

def test_correct_lines
assert_equal(["<wrong word> is <wrong word> wrong on the <wrong word>. And it was not the Apollo."],
@aspell.correct_lines(@text) { |word| "<wrong word>" })
@aspell.correct_lines(@text) { |word| "<wrong 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

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


0 comments on commit 08bf50f

Please sign in to comment.