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

« back to all changes in this revision

Viewing changes to analysis/lang/fa/persian_normalize_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 fa
 
16
 
 
17
import (
 
18
        "reflect"
 
19
        "testing"
 
20
 
 
21
        "github.com/blevesearch/bleve/analysis"
 
22
)
 
23
 
 
24
func TestPersianNormalizeFilter(t *testing.T) {
 
25
        tests := []struct {
 
26
                input  analysis.TokenStream
 
27
                output analysis.TokenStream
 
28
        }{
 
29
                // FarsiYeh
 
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
                // YehBarree
 
43
                {
 
44
                        input: analysis.TokenStream{
 
45
                                &analysis.Token{
 
46
                                        Term: []byte("هاے"),
 
47
                                },
 
48
                        },
 
49
                        output: analysis.TokenStream{
 
50
                                &analysis.Token{
 
51
                                        Term: []byte("هاي"),
 
52
                                },
 
53
                        },
 
54
                },
 
55
                // Keheh
 
56
                {
 
57
                        input: analysis.TokenStream{
 
58
                                &analysis.Token{
 
59
                                        Term: []byte("کشاندن"),
 
60
                                },
 
61
                        },
 
62
                        output: analysis.TokenStream{
 
63
                                &analysis.Token{
 
64
                                        Term: []byte("كشاندن"),
 
65
                                },
 
66
                        },
 
67
                },
 
68
                // HehYeh
 
69
                {
 
70
                        input: analysis.TokenStream{
 
71
                                &analysis.Token{
 
72
                                        Term: []byte("كتابۀ"),
 
73
                                },
 
74
                        },
 
75
                        output: analysis.TokenStream{
 
76
                                &analysis.Token{
 
77
                                        Term: []byte("كتابه"),
 
78
                                },
 
79
                        },
 
80
                },
 
81
                // HehHamzaAbove
 
82
                {
 
83
                        input: analysis.TokenStream{
 
84
                                &analysis.Token{
 
85
                                        Term: []byte("كتابهٔ"),
 
86
                                },
 
87
                        },
 
88
                        output: analysis.TokenStream{
 
89
                                &analysis.Token{
 
90
                                        Term: []byte("كتابه"),
 
91
                                },
 
92
                        },
 
93
                },
 
94
                // HehGoal
 
95
                {
 
96
                        input: analysis.TokenStream{
 
97
                                &analysis.Token{
 
98
                                        Term: []byte("زادہ"),
 
99
                                },
 
100
                        },
 
101
                        output: analysis.TokenStream{
 
102
                                &analysis.Token{
 
103
                                        Term: []byte("زاده"),
 
104
                                },
 
105
                        },
 
106
                },
 
107
                // empty
 
108
                {
 
109
                        input: analysis.TokenStream{
 
110
                                &analysis.Token{
 
111
                                        Term: []byte(""),
 
112
                                },
 
113
                        },
 
114
                        output: analysis.TokenStream{
 
115
                                &analysis.Token{
 
116
                                        Term: []byte(""),
 
117
                                },
 
118
                        },
 
119
                },
 
120
        }
 
121
 
 
122
        persianNormalizeFilter := NewPersianNormalizeFilter()
 
123
        for _, test := range tests {
 
124
                actual := persianNormalizeFilter.Filter(test.input)
 
125
                if !reflect.DeepEqual(actual, test.output) {
 
126
                        t.Errorf("expected %#v, got %#v", test.output, actual)
 
127
                        t.Errorf("expected % x, got % x", test.output[0].Term, actual[0].Term)
 
128
                }
 
129
        }
 
130
}