Navigation Menu

Skip to content

Commit

Permalink
Add tests for Regexp search for query string
Browse files Browse the repository at this point in the history
  • Loading branch information
Masafumi Yokoyama committed Apr 8, 2015
1 parent 27eb6f9 commit 3dfde2e
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion test/test-expression-builder.rb
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2014 Masafumi Yokoyama <myokoym@gmail.com>
# Copyright (C) 2014-2015 Masafumi Yokoyama <yokoyama@clear-code.com>
# Copyright (C) 2009-2012 Kouhei Sutou <kou@clear-code.com>
#
# This library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -248,6 +248,48 @@ def test_query_string
end
end

class RegexpSearchTest < self
def setup_tables
Groonga::Schema.define do |schema|
schema.create_table("Users",
:type => :hash,
:key_type => "ShortText") do |table|
table.short_text("name")
end

schema.create_table("Terms",
:type => :patricia_trie,
:key_type => "ShortText",
:default_tokenizer => "TokenRegexp",
:normalizer => "NormalizerAuto") do |table|
table.index("Users.name")
end
end

@users = Groonga["Users"]
end

def setup_data
@users.add("sato", :name => "taro sato")
@users.add("suzuki", :name => "Shiro SUZUKI")
@users.add("ito", :name => "Takashi Ito")
end

class QueryStringTest < self
def test_match
result = @users.select("name:~t")
assert_equal(["ito", "sato"],
result.collect {|record| record.key.key}.sort)
end

def test_not_match
result = @users.select("name:~x")
assert_equal([],
result.collect {|record| record.key.key}.sort)
end
end
end

class PrefixSearchTest < self
def setup_tables
Groonga::Schema.define do |schema|
Expand Down

0 comments on commit 3dfde2e

Please sign in to comment.