Skip to content

Commit 08bf50f

Browse files
committed
Enforce argument types better.
1 parent c94d6bf commit 08bf50f

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

CHANGELOG

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
v1.3. Enforce argument types better (raskhadafi).
2+
13
v1.2.2. Support for some changes from Ruby 1.9.1 to 1.9.2 (dmarkow).
24

35
v1.2. Ruby 1.9 compatibility (ph7).

ext/raspell.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static VALUE dictinfo_size_str(VALUE self) {
4343
void Init_dictinfo() {
4444
//CLASS DEFINITION=========================================================
4545
cDictInfo = rb_define_class("AspellDictInfo", rb_cObject);
46-
46+
4747
//CLASS METHODS============================================================
4848
rb_define_singleton_method(cDictInfo, "new", dictinfo_s_new, 0);
4949

@@ -289,7 +289,7 @@ static VALUE aspell_s_list_dicts(VALUE klass) {
289289
}
290290

291291
/**
292-
* @see set_option.
292+
* @see set_option.
293293
*/
294294
static VALUE aspell_set_option(VALUE self, VALUE option, VALUE value) {
295295
AspellSpeller *speller = get_speller(self);
@@ -400,7 +400,7 @@ static VALUE aspell_add_to_session(VALUE self, VALUE word) {
400400

401401
/**
402402
* Retrieve the value of a specific option.
403-
* The options are listed inside
403+
* The options are listed inside
404404
* Aspell::[DictionaryOptions|CheckerOptions|FilterOptions|RunTogetherOptions|MiscOptions|UtilityOptions]
405405
* @param word the option as string.
406406
*/
@@ -489,15 +489,15 @@ static VALUE aspell_check(VALUE self, VALUE word) {
489489
* This method needs a block to work proper. Each misspelled word is yielded,
490490
* a correct word as result from the block is assumed.
491491
* Common use:
492-
*
492+
*
493493
* a = Aspell.new(...)
494494
* text = ...
495495
* a.correct_lines(text) { |badword|
496496
* puts "Error: #{badword}\n"
497497
* puts a.suggest(badword).join(" | ")
498498
* gets #the input is returned as right word
499499
* }
500-
*
500+
*
501501
* @param ary the array of strings to check.
502502
* @result an array holding all lines with corrected words.
503503
*/
@@ -601,6 +601,7 @@ static VALUE aspell_correct_file(VALUE self, VALUE filename) {
601601
* @return array of strings: words that are misspelled.
602602
*/
603603
static VALUE aspell_list_misspelled(VALUE self, VALUE ary) {
604+
Check_Type(ary, T_ARRAY);
604605
VALUE result = rb_hash_new();
605606
//create checker
606607
AspellSpeller *speller = get_speller(self);
@@ -613,6 +614,7 @@ static VALUE aspell_list_misspelled(VALUE self, VALUE ary) {
613614
while(c<count) {
614615
//process line
615616
vline = RARRAY_PTR(ary)[c];
617+
Check_Type(vline, T_STRING);
616618
aspell_document_checker_process(checker, StringValuePtr(vline), -1);
617619
//iterate over all misspelled words
618620
while (token = aspell_document_checker_next_misspelling(checker), token.len != 0) {

test/simple_test.rb

+13-5
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,36 @@ def setup
99
@aspell = Aspell.new
1010
@text = ["Hiere is somthing wrong on the planett. And it was not the Apollo."]
1111
end
12-
12+
1313
def test_correct_lines
1414
assert_equal(["<wrong word> is <wrong word> wrong on the <wrong word>. And it was not the Apollo."],
15-
@aspell.correct_lines(@text) { |word| "<wrong word>" })
15+
@aspell.correct_lines(@text) { |word| "<wrong word>" })
1616
end
1717

1818
def test_list_mispelled
1919
misspelled = @aspell.list_misspelled(@text).sort
2020
assert_equal(3, misspelled.length)
2121
end
22-
22+
2323
def test_suggest
2424
suggestions = @aspell.suggest("spel")
25-
assert_equal [],
25+
assert_equal [],
2626
["spell", "spiel", "spew", "Opel", "spec", "sped"] - suggestions
2727
end
2828

2929
def test_check
3030
assert_equal(false, @aspell.check("spel"))
3131
assert(@aspell.check("spell"))
3232
end
33-
33+
34+
def test_argument_checking
35+
assert_raises TypeError do
36+
@aspell.list_misspelled "Not an array"
37+
end
38+
assert_raises TypeError do
39+
@aspell.list_misspelled [123]
40+
end
41+
end
3442
end
3543

3644

0 commit comments

Comments
 (0)