Navigation Menu

Skip to content

Commit

Permalink
Add Table#type_symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Apr 11, 2014
1 parent 8928fc5 commit e2256dc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/droonga/catalog/schema.rb
Expand Up @@ -171,6 +171,19 @@ def type
@data["type"] || "Hash"
end

def type_symbol
case type
when "Array"
:array
when "Hash"
:hash
when "PatriciaTrie"
:patricia_trie
when "DoubleArrayTrie"
:double_array_trie
end
end

def key_type
@data["keyType"]
end
Expand Down
25 changes: 25 additions & 0 deletions test/unit/catalog/test_schema.rb
Expand Up @@ -114,6 +114,31 @@ def test_array
end
end

class TypeSymbolTest < self
def type_symbol(type)
data = {
"type" => type,
}
create_table("table_name", data).type_symbol
end

def test_array
assert_equal(:array, type_symbol("Array"))
end

def test_hash
assert_equal(:hash, type_symbol("Hash"))
end

def test_patricia_trie
assert_equal(:patricia_trie, type_symbol("PatriciaTrie"))
end

def test_double_array_trie
assert_equal(:double_array_trie, type_symbol("DoubleArrayTrie"))
end
end

def test_flags
assert_equal(["TABLE_HASH_KEY"],
create_table("table_name",
Expand Down

0 comments on commit e2256dc

Please sign in to comment.