From ea6ef2204d3567c662b3fca33d27d4b00de30630 Mon Sep 17 00:00:00 2001 From: Ben Langfeld Date: Sun, 29 Sep 2013 15:52:48 -0300 Subject: [PATCH] [BUGFIX] Empty input should always be a potential match --- ext/ruby_speech/ruby_speech.c | 2 +- spec/ruby_speech/grxml/builtins_spec.rb | 3 ++- spec/ruby_speech/grxml/matcher_spec.rb | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ext/ruby_speech/ruby_speech.c b/ext/ruby_speech/ruby_speech.c index 7098323..ceaa818 100644 --- a/ext/ruby_speech/ruby_speech.c +++ b/ext/ruby_speech/ruby_speech.c @@ -82,7 +82,7 @@ static VALUE method_find_match(VALUE self, VALUE buffer) } return rb_funcall(self, rb_intern("match_for_buffer"), 1, buffer); } - if (result == PCRE_ERROR_PARTIAL) { + if (result == PCRE_ERROR_PARTIAL || (int)strlen(input) == 0) { VALUE PotentialMatch = rb_const_get(GRXML, rb_intern("PotentialMatch")); return rb_class_new_instance(0, NULL, PotentialMatch); } diff --git a/spec/ruby_speech/grxml/builtins_spec.rb b/spec/ruby_speech/grxml/builtins_spec.rb index c7e67dc..21dd4c3 100644 --- a/spec/ruby_speech/grxml/builtins_spec.rb +++ b/spec/ruby_speech/grxml/builtins_spec.rb @@ -145,7 +145,8 @@ it { should match('0123*456').and_interpret_as('dtmf-0 dtmf-1 dtmf-2 dtmf-3 dtmf-star dtmf-4 dtmf-5 dtmf-6') } it { should match('0123*456*789').and_interpret_as('dtmf-0 dtmf-1 dtmf-2 dtmf-3 dtmf-star dtmf-4 dtmf-5 dtmf-6 dtmf-star dtmf-7 dtmf-8 dtmf-9') } - it { should not_match('') } + it { should potentially_match('') } + it { should not_match('#') } end diff --git a/spec/ruby_speech/grxml/matcher_spec.rb b/spec/ruby_speech/grxml/matcher_spec.rb index 66c8175..7a54991 100644 --- a/spec/ruby_speech/grxml/matcher_spec.rb +++ b/spec/ruby_speech/grxml/matcher_spec.rb @@ -27,6 +27,10 @@ module GRXML input.should == '6' end + it "should potentially match an empty buffer" do + subject.match('').should == GRXML::PotentialMatch.new + end + %w{1 2 3 4 5 7 8 9 10 66 26 61}.each do |input| it "should not match '#{input}'" do subject.match(input).should == GRXML::NoMatch.new