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 ru 16 17import ( 18 "reflect" 19 "testing" 20 21 "github.com/blevesearch/bleve/analysis" 22 "github.com/blevesearch/bleve/registry" 23) 24 25func TestSnowballRussianStemmer(t *testing.T) { 26 tests := []struct { 27 input analysis.TokenStream 28 output analysis.TokenStream 29 }{ 30 { 31 input: analysis.TokenStream{ 32 &analysis.Token{ 33 Term: []byte("актеров"), 34 }, 35 }, 36 output: analysis.TokenStream{ 37 &analysis.Token{ 38 Term: []byte("актер"), 39 }, 40 }, 41 }, 42 { 43 input: analysis.TokenStream{ 44 &analysis.Token{ 45 Term: []byte("километров"), 46 }, 47 }, 48 output: analysis.TokenStream{ 49 &analysis.Token{ 50 Term: []byte("километр"), 51 }, 52 }, 53 }, 54 } 55 56 cache := registry.NewCache() 57 filter, err := cache.TokenFilterNamed(SnowballStemmerName) 58 if err != nil { 59 t.Fatal(err) 60 } 61 for _, test := range tests { 62 actual := filter.Filter(test.input) 63 if !reflect.DeepEqual(actual, test.output) { 64 t.Errorf("expected %s, got %s", test.output[0].Term, actual[0].Term) 65 } 66 } 67} 68