1//  Copyright (c) 2018 Couchbase, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// 		http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package hu
16
17import (
18	"reflect"
19	"testing"
20
21	"github.com/blevesearch/bleve/analysis"
22	"github.com/blevesearch/bleve/registry"
23)
24
25func TestHungarianAnalyzer(t *testing.T) {
26	tests := []struct {
27		input  []byte
28		output analysis.TokenStream
29	}{
30		// stemming
31		{
32			input: []byte("babakocsi"),
33			output: analysis.TokenStream{
34				&analysis.Token{
35					Term: []byte("babakocs"),
36				},
37			},
38		},
39		{
40			input: []byte("babakocsijáért"),
41			output: analysis.TokenStream{
42				&analysis.Token{
43					Term: []byte("babakocs"),
44				},
45			},
46		},
47		// stop word
48		{
49			input:  []byte("által"),
50			output: analysis.TokenStream{},
51		},
52	}
53
54	cache := registry.NewCache()
55	analyzer, err := cache.AnalyzerNamed(AnalyzerName)
56	if err != nil {
57		t.Fatal(err)
58	}
59	for _, test := range tests {
60		actual := analyzer.Analyze(test.input)
61		if len(actual) != len(test.output) {
62			t.Fatalf("expected length: %d, got %d", len(test.output), len(actual))
63		}
64		for i, tok := range actual {
65			if !reflect.DeepEqual(tok.Term, test.output[i].Term) {
66				t.Errorf("expected term %s (% x) got %s (% x)", test.output[i].Term, test.output[i].Term, tok.Term, tok.Term)
67			}
68		}
69	}
70}
71