lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject [lucy-commits] [5/9] git commit: refs/heads/clownfish-test-v2 - Port 611-queryparser_syntax.t to C
Date Mon, 18 Feb 2013 19:50:20 GMT
Port 611-queryparser_syntax.t to C


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/66376c0f
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/66376c0f
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/66376c0f

Branch: refs/heads/clownfish-test-v2
Commit: 66376c0f2ab5b882d5dcfb368689702203274977
Parents: c6b07c3
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Mon Feb 18 19:43:31 2013 +0100
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Mon Feb 18 20:14:55 2013 +0100

----------------------------------------------------------------------
 core/Lucy/Test.c                                |    2 +
 core/Lucy/Test/Search/TestQueryParserSyntax.c   |  106 ++++++++++++++++--
 core/Lucy/Test/Search/TestQueryParserSyntax.cfh |   14 ++-
 perl/buildlib/Lucy/Build/Binding/Misc.pm        |   41 -------
 perl/t/611-queryparser_syntax.t                 |   62 ----------
 perl/t/core/611-queryparser_syntax.t            |   23 ++++
 6 files changed, 133 insertions(+), 115 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/66376c0f/core/Lucy/Test.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test.c b/core/Lucy/Test.c
index b4baf9a..ecde899 100644
--- a/core/Lucy/Test.c
+++ b/core/Lucy/Test.c
@@ -66,6 +66,7 @@
 #include "Lucy/Test/Search/TestPhraseQuery.h"
 #include "Lucy/Test/Search/TestPolyQuery.h"
 #include "Lucy/Test/Search/TestQueryParserLogic.h"
+#include "Lucy/Test/Search/TestQueryParserSyntax.h"
 #include "Lucy/Test/Search/TestRangeQuery.h"
 #include "Lucy/Test/Search/TestReqOptQuery.h"
 #include "Lucy/Test/Search/TestSeriesMatcher.h"
@@ -173,6 +174,7 @@ S_all_test_batches() {
     VA_Push(batches, (Obj*)TestSeriesMatcher_new());
     VA_Push(batches, (Obj*)TestORQuery_new());
     VA_Push(batches, (Obj*)TestQPLogic_new());
+    VA_Push(batches, (Obj*)TestQPSyntax_new());
 
     return batches;
 }

http://git-wip-us.apache.org/repos/asf/lucy/blob/66376c0f/core/Lucy/Test/Search/TestQueryParserSyntax.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Search/TestQueryParserSyntax.c b/core/Lucy/Test/Search/TestQueryParserSyntax.c
index 56d8173..13ce638 100644
--- a/core/Lucy/Test/Search/TestQueryParserSyntax.c
+++ b/core/Lucy/Test/Search/TestQueryParserSyntax.c
@@ -23,6 +23,13 @@
 #include "Lucy/Test/Search/TestQueryParserSyntax.h"
 #include "Lucy/Test/Search/TestQueryParser.h"
 #include "Lucy/Test/TestUtils.h"
+#include "Lucy/Analysis/PolyAnalyzer.h"
+#include "Lucy/Analysis/RegexTokenizer.h"
+#include "Lucy/Analysis/SnowballStopFilter.h"
+#include "Lucy/Document/Doc.h"
+#include "Lucy/Index/Indexer.h"
+#include "Lucy/Plan/FullTextType.h"
+#include "Lucy/Plan/Schema.h"
 #include "Lucy/Search/Hits.h"
 #include "Lucy/Search/IndexSearcher.h"
 #include "Lucy/Search/QueryParser.h"
@@ -33,6 +40,7 @@
 #include "Lucy/Search/NOTQuery.h"
 #include "Lucy/Search/ORQuery.h"
 #include "Lucy/Store/Folder.h"
+#include "Lucy/Store/RAMFolder.h"
 
 #define make_term_query   (Query*)lucy_TestUtils_make_term_query
 #define make_phrase_query (Query*)lucy_TestUtils_make_phrase_query
@@ -40,6 +48,82 @@
 #define make_not_query    (Query*)lucy_TestUtils_make_not_query
 #define make_poly_query   (Query*)lucy_TestUtils_make_poly_query
 
+TestQueryParserSyntax*
+TestQPSyntax_new() {
+    TestQueryParserSyntax *self
+        = (TestQueryParserSyntax*)VTable_Make_Obj(TESTQUERYPARSERSYNTAX);
+    return TestQPSyntax_init(self);
+}
+
+TestQueryParserSyntax*
+TestQPSyntax_init(TestQueryParserSyntax *self) {
+    return (TestQueryParserSyntax*)TestBatch_init((TestBatch*)self, 68);
+}
+
+static Folder*
+build_index() {
+    // Plain type.
+    CharBuf        *pattern   = CB_newf("\\S+");
+    RegexTokenizer *tokenizer = RegexTokenizer_new(pattern);
+    FullTextType   *plain     = FullTextType_new((Analyzer*)tokenizer);
+
+    // Fancy type.
+
+    CharBuf        *word_pattern   = CB_newf("\\w+");
+    RegexTokenizer *word_tokenizer = RegexTokenizer_new(word_pattern);
+
+    Hash *stop_list = Hash_new(0);
+    Hash_Store_Str(stop_list, "x", 1, (Obj*)CFISH_TRUE);
+    SnowballStopFilter *stop_filter = SnowStop_new(NULL, stop_list);
+
+    VArray *analyzers = VA_new(0);
+    VA_Push(analyzers, (Obj*)word_tokenizer);
+    VA_Push(analyzers, (Obj*)stop_filter);
+    PolyAnalyzer *fancy_analyzer = PolyAnalyzer_new(NULL, analyzers);
+
+    FullTextType *fancy = FullTextType_new((Analyzer*)fancy_analyzer);
+
+    // Schema.
+    Schema  *schema   = Schema_new();
+    CharBuf *plain_cb = CB_newf("plain");
+    CharBuf *fancy_cb = CB_newf("fancy");
+    Schema_Spec_Field(schema, plain_cb, (FieldType*)plain);
+    Schema_Spec_Field(schema, fancy_cb, (FieldType*)fancy);
+
+    // Indexer.
+    RAMFolder *folder  = RAMFolder_new(NULL);
+    Indexer   *indexer = Indexer_new(schema, (Obj*)folder, NULL, 0);
+
+    // Index documents.
+    VArray *doc_set = TestUtils_doc_set();
+    for (uint32_t i = 0; i < VA_Get_Size(doc_set); ++i) {
+        CharBuf *content_string = (CharBuf*)VA_Fetch(doc_set, i);
+        Doc *doc = Doc_new(NULL, 0);
+        Doc_Store(doc, plain_cb, (Obj*)content_string);
+        Doc_Store(doc, fancy_cb, (Obj*)content_string);
+        Indexer_Add_Doc(indexer, doc, 1.0);
+        DECREF(doc);
+    }
+    Indexer_Commit(indexer);
+
+    // Clean up.
+    DECREF(doc_set);
+    DECREF(indexer);
+    DECREF(fancy_cb);
+    DECREF(plain_cb);
+    DECREF(schema);
+    DECREF(fancy);
+    DECREF(fancy_analyzer);
+    DECREF(analyzers);
+    DECREF(stop_list);
+    DECREF(word_pattern);
+    DECREF(plain);
+    DECREF(tokenizer);
+    DECREF(pattern);
+
+    return (Folder*)folder;
+}
+
 static TestQueryParser*
 leaf_test_simple_term() {
     Query   *tree     = make_leaf_query(NULL, "a");
@@ -293,16 +377,14 @@ static Lucy_TestQPSyntax_Test_t syntax_test_funcs[] = {
     NULL
 };
 
-void
-TestQPSyntax_run_tests(Folder *index) {
-    TestBatch     *batch      = TestBatch_new(68);
-    IndexSearcher *searcher   = IxSearcher_new((Obj*)index);
-    QueryParser   *qparser    = QParser_new(IxSearcher_Get_Schema(searcher),
-                                            NULL, NULL, NULL);
+static void
+test_query_parser_syntax(TestBatch *batch) {
+    Folder        *index    = build_index();
+    IndexSearcher *searcher = IxSearcher_new((Obj*)index);
+    QueryParser   *qparser  = QParser_new(IxSearcher_Get_Schema(searcher),
+                                          NULL, NULL, NULL);
     QParser_Set_Heed_Colons(qparser, true);
 
-    TestBatch_Plan(batch);
-
     for (uint32_t i = 0; leaf_test_funcs[i] != NULL; i++) {
         Lucy_TestQPSyntax_Test_t test_func = leaf_test_funcs[i];
         TestQueryParser *test_case = test_func();
@@ -341,9 +423,15 @@ TestQPSyntax_run_tests(Folder *index) {
         DECREF(test_case);
     }
 
-    DECREF(batch);
     DECREF(searcher);
     DECREF(qparser);
+    DECREF(index);
+}
+
+void
+TestQPSyntax_run_tests(TestQueryParserSyntax *self) {
+    TestBatch *batch = (TestBatch*)self;
+    test_query_parser_syntax(batch);
 }
 
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/66376c0f/core/Lucy/Test/Search/TestQueryParserSyntax.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Search/TestQueryParserSyntax.cfh b/core/Lucy/Test/Search/TestQueryParserSyntax.cfh
index f6a2a18..098aa80 100644
--- a/core/Lucy/Test/Search/TestQueryParserSyntax.cfh
+++ b/core/Lucy/Test/Search/TestQueryParserSyntax.cfh
@@ -19,9 +19,17 @@ parcel Lucy;
 /** Tests for logical structure of Query objects output by QueryParser.
  */
 
-inert class Lucy::Test::Search::TestQueryParserSyntax cnick TestQPSyntax {
-    inert void
-    run_tests(Folder *index);
+class Lucy::Test::Search::TestQueryParserSyntax cnick TestQPSyntax
+    inherits Lucy::Test::TestBatch {
+
+    inert incremented TestQueryParserSyntax*
+    new();
+
+    inert TestQueryParserSyntax*
+    init(TestQueryParserSyntax *self);
+
+    void
+    Run_Tests(TestQueryParserSyntax *self);
 }
 
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/66376c0f/perl/buildlib/Lucy/Build/Binding/Misc.pm
----------------------------------------------------------------------
diff --git a/perl/buildlib/Lucy/Build/Binding/Misc.pm b/perl/buildlib/Lucy/Build/Binding/Misc.pm
index b9a8ca0..0fb31a8 100644
--- a/perl/buildlib/Lucy/Build/Binding/Misc.pm
+++ b/perl/buildlib/Lucy/Build/Binding/Misc.pm
@@ -23,8 +23,6 @@ sub bind_all {
     my $class = shift;
     $class->bind_lucy;
     $class->bind_test;
-    $class->bind_testutils;
-    $class->bind_testqueryparsersyntax;
     $class->bind_testschema;
     $class->bind_bbsortex;
 }
@@ -107,45 +105,6 @@ END_XS_CODE
     Clownfish::CFC::Binding::Perl::Class->register($binding);
 }
 
-sub bind_testutils {
-    my $xs_code = <<'END_XS_CODE';
-MODULE = Lucy   PACKAGE = Lucy::Test::TestUtils
-
-SV*
-doc_set()
-CODE:
-    RETVAL = CFISH_OBJ_TO_SV_NOINC(lucy_TestUtils_doc_set());
-OUTPUT: RETVAL
-END_XS_CODE
-    my $binding = Clownfish::CFC::Binding::Perl::Class->new(
-        parcel     => "Lucy",
-        class_name => "Lucy::Test::TestUtils",
-    );
-    $binding->append_xs($xs_code);
-
-    Clownfish::CFC::Binding::Perl::Class->register($binding);
-}
-
-sub bind_testqueryparsersyntax {
-    my $xs_code = <<'END_XS_CODE';
-MODULE = Lucy   PACKAGE = Lucy::Test::Search::TestQueryParserSyntax
-
-void
-run_tests(index);
-    lucy_Folder *index;
-PPCODE:
-    lucy_TestQPSyntax_run_tests(index);
-END_XS_CODE
-
-    my $binding = Clownfish::CFC::Binding::Perl::Class->new(
-        parcel     => "Lucy",
-        class_name => "Lucy::Test::Search::TestQueryParserSyntax",
-    );
-    $binding->append_xs($xs_code);
-
-    Clownfish::CFC::Binding::Perl::Class->register($binding);
-}
-
 sub bind_testschema {
     my $binding = Clownfish::CFC::Binding::Perl::Class->new(
         parcel     => "Lucy",

http://git-wip-us.apache.org/repos/asf/lucy/blob/66376c0f/perl/t/611-queryparser_syntax.t
----------------------------------------------------------------------
diff --git a/perl/t/611-queryparser_syntax.t b/perl/t/611-queryparser_syntax.t
deleted file mode 100644
index 2d428b3..0000000
--- a/perl/t/611-queryparser_syntax.t
+++ /dev/null
@@ -1,62 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-use strict;
-use warnings;
-
-use lib 'buildlib';
-use Lucy::Test;
-
-package MySchema;
-use base qw( Lucy::Plan::Schema );
-
-sub new {
-    my $self = shift->SUPER::new(@_);
-    my $tokenizer = Lucy::Analysis::RegexTokenizer->new( pattern => '\S+' );
-    my $wordchar_tokenizer
-        = Lucy::Analysis::RegexTokenizer->new( pattern => '\w+', );
-    my $stopfilter
-        = Lucy::Analysis::SnowballStopFilter->new( stoplist => { x => 1 } );
-    my $fancy_analyzer = Lucy::Analysis::PolyAnalyzer->new(
-        analyzers => [ $wordchar_tokenizer, $stopfilter, ], );
-
-    my $plain = Lucy::Plan::FullTextType->new( analyzer => $tokenizer );
-    my $fancy = Lucy::Plan::FullTextType->new( analyzer => $fancy_analyzer );
-    $self->spec_field( name => 'plain', type => $plain );
-    $self->spec_field( name => 'fancy', type => $fancy );
-    return $self;
-}
-
-package main;
-
-# Build index.
-my $doc_set = Lucy::Test::TestUtils::doc_set()->to_perl;
-my $folder  = Lucy::Store::RAMFolder->new;
-my $schema  = MySchema->new;
-my $indexer = Lucy::Index::Indexer->new(
-    schema => $schema,
-    index  => $folder,
-);
-for my $content_string (@$doc_set) {
-    $indexer->add_doc(
-        {   plain => $content_string,
-            fancy => $content_string,
-        }
-    );
-}
-$indexer->commit;
-
-Lucy::Test::Search::TestQueryParserSyntax::run_tests($folder);
-

http://git-wip-us.apache.org/repos/asf/lucy/blob/66376c0f/perl/t/core/611-queryparser_syntax.t
----------------------------------------------------------------------
diff --git a/perl/t/core/611-queryparser_syntax.t b/perl/t/core/611-queryparser_syntax.t
new file mode 100644
index 0000000..c82d160
--- /dev/null
+++ b/perl/t/core/611-queryparser_syntax.t
@@ -0,0 +1,23 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+use strict;
+use warnings;
+
+use Lucy::Test;
+my $success = Lucy::Test::run_tests("Lucy::Test::Search::TestQueryParserSyntax");
+
+exit($success ? 0 : 1);
+


Mime
View raw message