Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
allow the :delim to hold an array of delimiters to be OR'd together
  • Loading branch information
dj2 committed Jan 4, 2010
1 parent 1f98cdb commit f9143c9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/textquery/textquery.rb
Expand Up @@ -72,8 +72,7 @@ def terminal_failures
private

def update_options(options)
@options = {:delim => ' '}.merge options
@options[:delim] = Regexp.escape @options[:delim]
@options = {:delim => ' '}.merge(options)
@options[:delim] = "(#{[@options[:delim]].flatten.map { |opt| Regexp.escape(opt) }.join("|")})"
end

end
25 changes: 25 additions & 0 deletions spec/textquery_spec.rb
Expand Up @@ -199,4 +199,29 @@ def parse(input)
TextQuery.new("a AND CD", :ignorecase => false).match?("A b cD").should be_false
end

context 'delimiters' do
it 'should default to space delimiter' do
TextQuery.new("a").match?("a b").should be_true
TextQuery.new("a").match?("a*b").should be_false
end

it 'should accept a string delimiter' do
TextQuery.new("a", :delim => "*").match?("a*b").should be_true
TextQuery.new("a", :delim => "*").match?("a b").should be_false
end

it 'should accept an array of delimiters' do
TextQuery.new("a", :delim => ["*"]).match?("a*b").should be_true
end

it 'should OR delimiters together when provided as an array' do
TextQuery.new("a", :delim => ["*", "|"]).match?("a|b").should be_true
TextQuery.new("a", :delim => ["*", "|"]).match?("a*b").should be_true
TextQuery.new("a", :delim => ["*", "|"]).match?("a b").should be_false
end

it 'should not match just the delimiter' do
TextQuery.new("a*b", :delim => ["*", "<"]).match?("over<under").should be_false
end
end
end

0 comments on commit f9143c9

Please sign in to comment.