~ubuntu-branches/debian/sid/golang-github-blevesearch-bleve/sid

« back to all changes in this revision

Viewing changes to analysis/token/keyword/keyword_test.go

  • Committer: Package Import Robot
  • Author(s): Michael Lustfield
  • Date: 2017-03-30 16:06:03 UTC
  • Revision ID: package-import@ubuntu.com-20170330160603-0oogmb960l7918jx
Tags: upstream-0.5.0+git20170324.202.4702785f
ImportĀ upstreamĀ versionĀ 0.5.0+git20170324.202.4702785f

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  Copyright (c) 2014 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
 
 
15
package keyword
 
16
 
 
17
import (
 
18
        "reflect"
 
19
        "testing"
 
20
 
 
21
        "github.com/blevesearch/bleve/analysis"
 
22
)
 
23
 
 
24
func TestKeyWordMarkerFilter(t *testing.T) {
 
25
 
 
26
        inputTokenStream := analysis.TokenStream{
 
27
                &analysis.Token{
 
28
                        Term: []byte("a"),
 
29
                },
 
30
                &analysis.Token{
 
31
                        Term: []byte("walk"),
 
32
                },
 
33
                &analysis.Token{
 
34
                        Term: []byte("in"),
 
35
                },
 
36
                &analysis.Token{
 
37
                        Term: []byte("the"),
 
38
                },
 
39
                &analysis.Token{
 
40
                        Term: []byte("park"),
 
41
                },
 
42
        }
 
43
 
 
44
        expectedTokenStream := analysis.TokenStream{
 
45
                &analysis.Token{
 
46
                        Term: []byte("a"),
 
47
                },
 
48
                &analysis.Token{
 
49
                        Term:    []byte("walk"),
 
50
                        KeyWord: true,
 
51
                },
 
52
                &analysis.Token{
 
53
                        Term: []byte("in"),
 
54
                },
 
55
                &analysis.Token{
 
56
                        Term: []byte("the"),
 
57
                },
 
58
                &analysis.Token{
 
59
                        Term:    []byte("park"),
 
60
                        KeyWord: true,
 
61
                },
 
62
        }
 
63
 
 
64
        keyWordsMap := analysis.NewTokenMap()
 
65
        keyWordsMap.AddToken("walk")
 
66
        keyWordsMap.AddToken("park")
 
67
 
 
68
        filter := NewKeyWordMarkerFilter(keyWordsMap)
 
69
        ouputTokenStream := filter.Filter(inputTokenStream)
 
70
        if !reflect.DeepEqual(ouputTokenStream, expectedTokenStream) {
 
71
                t.Errorf("expected %#v got %#v", expectedTokenStream[0].KeyWord, ouputTokenStream[0].KeyWord)
 
72
        }
 
73
}