Tests for Schema Go bindings.

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

Branch: refs/heads/master
Commit: f162847839fc3835cbe504a96301a85346491085
Parents: 43addb0
Author: Marvin Humphrey <[email protected]>
Authored: Mon Oct 5 16:15:51 2015 -0700
Committer: Marvin Humphrey <[email protected]>
Committed: Mon Oct 5 19:06:48 2015 -0700

----------------------------------------------------------------------
 go/lucy/plan_test.go | 117 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 117 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/f1628478/go/lucy/plan_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/plan_test.go b/go/lucy/plan_test.go
new file mode 100644
index 0000000..f16c0f6
--- /dev/null
+++ b/go/lucy/plan_test.go
@@ -0,0 +1,117 @@
+/* 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.
+ */
+
+package lucy
+
+import "testing"
+import "reflect"
+
+func TestSchemaSpecField(t *testing.T) {
+       schema := NewSchema()
+       fieldType := NewStringType()
+       schema.SpecField("foo", fieldType)
+       if got, ok := schema.FetchType("foo").(FieldType); !ok {
+               t.Errorf("SpecField failed, type is %T", got)
+       }
+}
+
+func TestSchemaFetchType(t *testing.T) {
+       schema := createTestSchema()
+       fieldType := schema.FetchType("content")
+       if _, ok := fieldType.(FullTextType); !ok {
+               t.Errorf("Unexpected result for FetchType: %T", fieldType)
+       }
+       if got := schema.FetchType(""); got != nil {
+               t.Errorf("Expected nil from FetchType, got %T %v", got, got)
+       }
+}
+
+func TestSchemaFetchAnalyzer(t *testing.T) {
+       schema := createTestSchema()
+       analyzer := schema.FetchAnalyzer("content")
+       if _, ok := analyzer.(StandardTokenizer); !ok {
+               t.Errorf("Unexpected result for FetchAnalyzer: %T", analyzer)
+       }
+       if got := schema.FetchAnalyzer(""); got != nil {
+               t.Errorf("Expected nil from FetchAnalyzer, got %T %v", got, got)
+       }
+}
+
+func TestSchemaFetchSim(t *testing.T) {
+       schema := createTestSchema()
+       sim := schema.FetchSim("content")
+       if _, ok := sim.(Similarity); !ok {
+               t.Errorf("Unexpected result for FetchSim: %T", sim)
+       }
+       if got := schema.FetchSim(""); got != nil {
+               t.Errorf("Expected nil from FetchSim, got %T %v", got, got)
+       }
+}
+
+func TestSchemaNumFields(t *testing.T) {
+       num := createTestSchema().NumFields()
+       if num != 1 {
+               t.Errorf("Unexpected NumFields result: %d", num)
+       }
+}
+
+func TestSchemaAllFields(t *testing.T) {
+       schema := createTestSchema()
+       got := schema.AllFields()
+       expected := []string{"content"}
+       if !reflect.DeepEqual(got, expected) {
+               t.Errorf("Invalid AllFields(): %v", got)
+       }
+}
+
+func TestSchemaArchitecture(t *testing.T) {
+       schema := createTestSchema()
+       if arch, ok := schema.Architecture().(Architecture); !ok {
+               t.Errorf("Unexpected result for Architecture(): %T", arch)
+       }
+}
+
+func TestSchemaAccessors(t *testing.T) {
+       schema := createTestSchema()
+       if sim, ok := schema.GetSimilarity().(Similarity); !ok {
+               t.Errorf("Unexpected result for GetSimilarity(): %T", sim)
+       }
+       if arch, ok := schema.GetArchitecture().(Architecture); !ok {
+               t.Errorf("Unexpected result for GetArchitecture(): %T", arch)
+       }
+}
+
+func TestSchemaDumpLoad(t *testing.T) {
+       schema := createTestSchema()
+       dupe := schema.Load(schema.Dump())
+       if _, ok := dupe.(Schema); !ok {
+               t.Errorf("Failed Dump/Load round trip produced a %T", dupe)
+       }
+}
+
+func TestSchemaWrite(t *testing.T) {
+       schema := createTestSchema()
+       folder := NewRAMFolder("")
+       schema.Write(folder, "serialized_schema.json")
+}
+
+func TestSchemaEat(t *testing.T) {
+       cannibal := NewSchema()
+       cannibal.Eat(createTestSchema())
+       if _, ok := cannibal.FetchType("content").(FieldType); !ok {
+               t.Error("Failed to Eat other Schema")
+       }
+}

Reply via email to