Test Go bindings for Highlighter.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/ae8f0c1e Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/ae8f0c1e Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/ae8f0c1e Branch: refs/heads/master Commit: ae8f0c1ed32f4e5edc95eec64ca17bd215166294 Parents: a4d63f2 Author: Marvin Humphrey <[email protected]> Authored: Wed Dec 2 18:51:54 2015 -0800 Committer: Marvin Humphrey <[email protected]> Committed: Thu Dec 3 13:45:26 2015 -0800 ---------------------------------------------------------------------- go/lucy/highlight_test.go | 50 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy/blob/ae8f0c1e/go/lucy/highlight_test.go ---------------------------------------------------------------------- diff --git a/go/lucy/highlight_test.go b/go/lucy/highlight_test.go index fa086ed..3b60a8d 100644 --- a/go/lucy/highlight_test.go +++ b/go/lucy/highlight_test.go @@ -17,6 +17,7 @@ package lucy import "testing" +import "strings" func TestHeatMapBasics(t *testing.T) { spans := make([]Span, 2) @@ -42,3 +43,52 @@ func TestHeatMapBasics(t *testing.T) { t.Errorf("flattenSpans: %d", length) } } + +func TestHighlighterBasics(t *testing.T) { + folder := createTestIndex("foo bar baz") + searcher := NewIndexSearcher(folder) + hl := NewHighlighter(searcher, "bar", "content", 200) + found := "<strong>bar</strong>" + if got := hl.Highlight("bar"); got != found { + t.Errorf("Highlight: '%s'", got) + } + doc, _ := searcher.FetchDoc(1) + if got := hl.CreateExcerpt(doc); !strings.Contains(got, found) { + t.Errorf("CreateExcerpt: '%s'", got) + } + phi := "\u03a6"; + encodedPhi := "Φ"; + if got := hl.Encode(phi); got != encodedPhi { + t.Errorf("Encode: '%v'", got) + } +} + +func TestHighlighterAccessors(t *testing.T) { + folder := createTestIndex("foo bar baz") + searcher := NewIndexSearcher(folder) + hl := NewHighlighter(searcher, "bar", "content", 200) + if field := hl.GetField(); field != "content" { + t.Errorf("GetField: %v", field) + } + if _, ok := hl.GetSearcher().(Searcher); !ok { + t.Errorf("GetSearcher") + } + barQuery := NewTermQuery("content", "bar") + if got := hl.GetQuery(); !barQuery.Equals(got) { + t.Errorf("GetQuery: %T %v", got, got) + } + if _, ok := hl.GetCompiler().(Compiler); !ok { + t.Errorf("GetCompiler") + } + if got := hl.GetExcerptLength(); got != 200 { + t.Errorf("GetExcerptLength: %d", got) + } + hl.SetPreTag("<blink>") + if got := hl.GetPreTag(); got != "<blink>" { + t.Errorf("Set/GetPreTag: %s", got) + } + hl.SetPostTag("</blink>") + if got := hl.GetPostTag(); got != "</blink>" { + t.Errorf("Set/GetPostTag: %s", got) + } +}
