lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [5/6] lucy git commit: Test Go bindings for various Analyzers.
Date Thu, 15 Oct 2015 21:43:04 GMT
Test Go bindings for various Analyzers.


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

Branch: refs/heads/master
Commit: 51029f8f6b5ad7c0d848e20db900cac5339c0bdb
Parents: 094b76e
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Tue Oct 6 18:42:58 2015 -0700
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Tue Oct 6 18:44:17 2015 -0700

----------------------------------------------------------------------
 go/lucy/analysis_test.go | 44 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/51029f8f/go/lucy/analysis_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/analysis_test.go b/go/lucy/analysis_test.go
index 65a8403..5a068a6 100644
--- a/go/lucy/analysis_test.go
+++ b/go/lucy/analysis_test.go
@@ -63,6 +63,50 @@ func TestInversionBasics(t *testing.T) {
 	}
 }
 
+func runAnalyzerTests(t *testing.T, a Analyzer) {
+	input := "foo bar baz"
+	fromSplit := a.Split(input)
+	fromTransform := make([]string, 0)
+	fromTransformText := make([]string, 0)
+	invFromTransform := a.Transform(NewInversion(NewToken(input)))
+	invFromTransformText := a.TransformText(input)
+	for i := 0; true; i++ {
+		token := invFromTransform.Next()
+		if token == nil {
+			break;
+		}
+		fromTransform = append(fromTransform, token.GetText())
+	}
+	for i := 0; true; i++ {
+		token := invFromTransformText.Next()
+		if token == nil {
+			break;
+		}
+		fromTransformText = append(fromTransformText, token.GetText())
+	}
+	if !reflect.DeepEqual(fromSplit, fromTransform) {
+		t.Errorf("Split and Transform not the same: %v, %v", fromSplit, fromTransform)
+	}
+	if !reflect.DeepEqual(fromSplit, fromTransformText) {
+		t.Errorf("Split and TransformText not the same: %v, %v", fromSplit, fromTransformText)
+	}
+
+	dupe := a.Load(a.Dump())
+	if !a.Equals(dupe) {
+		t.Errorf("Round-trip through Dump/Load failed: %v", dupe)
+	}
+}
+
+func TestCoreAnalyzers(t *testing.T) {
+	runAnalyzerTests(t, NewCaseFolder())
+	runAnalyzerTests(t, NewEasyAnalyzer("en"))
+	runAnalyzerTests(t, NewNormalizer("NFKC", true, false))
+	runAnalyzerTests(t, NewRegexTokenizer("\\S+"))
+	runAnalyzerTests(t, NewSnowballStemmer("en"))
+	runAnalyzerTests(t, NewSnowballStopFilter("en", nil))
+	runAnalyzerTests(t, NewStandardTokenizer())
+}
+
 func TestRegexTokenizerSplit(t *testing.T) {
 	tokenizer := NewRegexTokenizer("\\S+")
 	expected := []string{"foo", "bar", "baz"}


Mime
View raw message