Yasuhiro Horimoto 2019-06-13 06:06:00 +0900 (Thu, 13 Jun 2019) Revision: 16fdcb0103ca017abbe0c91acc6e5111a36b3542 https://github.com/ranguba/rroonga/commit/16fdcb0103ca017abbe0c91acc6e5111a36b3542 Message: Add Object#lexicon? (#153) * Add Object#lexicon? * test: use power-assert * test: Add a "lexicon? -> true" test case * test: split assertions Modified files: ext/groonga/rb-grn-object.c test/test-index-column.rb Modified: ext/groonga/rb-grn-object.c (+22 -0) =================================================================== --- ext/groonga/rb-grn-object.c 2019-05-11 17:35:36 +0900 (b3b6854b) +++ ext/groonga/rb-grn-object.c 2019-06-13 06:06:00 +0900 (a66cabc1) @@ -2,6 +2,7 @@ /* Copyright (C) 2009-2018 Kouhei Sutou <kou****@clear*****> Copyright (C) 2014-2016 Masafumi Yokoyama <yokoy****@clear*****> + Copyright (C) 2019 Yasuhiro Horimoto <horim****@clear*****> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -1990,6 +1991,25 @@ rb_grn_object_corrupt_p (VALUE self) } /* + * @overload lexicon? + * @return [Boolean] `true` if the object is lexicon, `false` otherwise. + * + * @since 9.0.4 + */ +static VALUE +rb_grn_object_lexicon_p (VALUE self) +{ + grn_ctx *context; + grn_obj *object; + grn_bool is_lexicon; + + rb_grn_object_deconstruct(SELF(self), &object, &context, + NULL, NULL, NULL, NULL); + is_lexicon = grn_obj_is_lexicon(context, object); + return CBOOL2RVAL(is_lexicon); +} + +/* * @overload disk_usage * @return [Integer] The number of bytes used by this object in disk. * @@ -2072,6 +2092,8 @@ rb_grn_init_object (VALUE mGrn) rb_grn_object_dirty_p, 0); rb_define_method(rb_cGrnObject, "corrupt?", rb_grn_object_corrupt_p, 0); + rb_define_method(rb_cGrnObject, "lexicon?", + rb_grn_object_lexicon_p, 0); rb_define_method(rb_cGrnObject, "disk_usage", rb_grn_object_get_disk_usage, 0); Modified: test/test-index-column.rb (+19 -5) =================================================================== --- test/test-index-column.rb 2019-05-11 17:35:36 +0900 (ffa4fb29) +++ test/test-index-column.rb 2019-06-13 06:06:00 +0900 (2d5cab64) @@ -33,11 +33,11 @@ class IndexColumnTest < Test::Unit::TestCase articles = Groonga::Array.create(:name => "Articles") articles.define_column("content", "Text") - terms = Groonga::Hash.create(:name => "Terms", - :key_type => "ShortText", - :default_tokenizer => "TokenBigram") - @index = terms.define_index_column("content", articles, - :with_section => true) + @terms = Groonga::Hash.create(:name => "Terms", + :key_type => "ShortText", + :default_tokenizer => "TokenBigram") + @index =****@terms*****_index_column("content", articles, + :with_section => true) end def test_index? @@ -63,6 +63,20 @@ class IndexColumnTest < Test::Unit::TestCase not****@index*****? end end + + sub_test_case("#lexicon?") do + def test_true + assert do + @terms.lexicon? + end + end + + def test_false + assert do + not****@index*****? + end + end + end end class CRUDTest < self -------------- next part -------------- An HTML attachment was scrubbed... URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20190613/ee194e6d/attachment-0001.html>