2016-06-10 19:08:50 +02:00
|
|
|
// Copyright (c) 2016 Couchbase, Inc.
|
2016-10-02 16:13:14 +02:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2016-06-10 19:08:50 +02:00
|
|
|
|
2016-09-30 17:18:39 +02:00
|
|
|
package camelcase
|
2016-06-03 17:04:21 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/blevesearch/bleve/analysis"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCamelCaseFilter(t *testing.T) {
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
input analysis.TokenStream
|
|
|
|
output analysis.TokenStream
|
|
|
|
}{
|
|
|
|
{
|
2017-06-23 00:56:28 +02:00
|
|
|
input: tokenStream(""),
|
|
|
|
output: tokenStream(""),
|
2016-06-03 17:04:21 +02:00
|
|
|
},
|
|
|
|
{
|
2017-06-23 00:56:28 +02:00
|
|
|
input: tokenStream("a"),
|
|
|
|
output: tokenStream("a"),
|
2016-06-03 17:04:21 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2017-06-23 00:56:28 +02:00
|
|
|
input: tokenStream("...aMACMac123macILoveGolang"),
|
|
|
|
output: tokenStream("...", "a", "MAC", "Mac", "123", "mac", "I", "Love", "Golang"),
|
2016-06-03 17:04:21 +02:00
|
|
|
},
|
|
|
|
{
|
2017-06-23 00:56:28 +02:00
|
|
|
input: tokenStream("Lang"),
|
|
|
|
output: tokenStream("Lang"),
|
2016-06-03 17:04:21 +02:00
|
|
|
},
|
|
|
|
{
|
2017-06-23 00:56:28 +02:00
|
|
|
input: tokenStream("GLang"),
|
|
|
|
output: tokenStream("G", "Lang"),
|
2016-06-03 17:04:21 +02:00
|
|
|
},
|
|
|
|
{
|
2017-06-23 00:56:28 +02:00
|
|
|
input: tokenStream("GOLang"),
|
|
|
|
output: tokenStream("GO", "Lang"),
|
2016-06-03 17:04:21 +02:00
|
|
|
},
|
|
|
|
{
|
2017-06-23 00:56:28 +02:00
|
|
|
input: tokenStream("GOOLang"),
|
|
|
|
output: tokenStream("GOO", "Lang"),
|
2016-06-03 17:04:21 +02:00
|
|
|
},
|
|
|
|
{
|
2017-06-23 00:56:28 +02:00
|
|
|
input: tokenStream("1234"),
|
|
|
|
output: tokenStream("1234"),
|
2016-06-03 17:04:21 +02:00
|
|
|
},
|
|
|
|
{
|
2017-06-23 00:56:28 +02:00
|
|
|
input: tokenStream("starbucks"),
|
|
|
|
output: tokenStream("starbucks"),
|
2016-06-03 17:04:21 +02:00
|
|
|
},
|
|
|
|
{
|
2017-06-23 00:56:28 +02:00
|
|
|
input: tokenStream("Starbucks TVSamsungIsGREAT000"),
|
|
|
|
output: tokenStream("Starbucks", " ", "TV", "Samsung", "Is", "GREAT", "000"),
|
2016-06-03 17:04:21 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
ccFilter := NewCamelCaseFilter()
|
|
|
|
actual := ccFilter.Filter(test.input)
|
|
|
|
if !reflect.DeepEqual(actual, test.output) {
|
|
|
|
t.Errorf("expected %s \n\n got %s", test.output, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-23 00:56:28 +02:00
|
|
|
|
|
|
|
func tokenStream(termStrs ...string) analysis.TokenStream {
|
|
|
|
tokenStream := make([]*analysis.Token, len(termStrs))
|
|
|
|
index := 0
|
|
|
|
for i, termStr := range termStrs {
|
|
|
|
tokenStream[i] = &analysis.Token{
|
|
|
|
Term: []byte(termStr),
|
|
|
|
Position: i + 1,
|
|
|
|
Start: index,
|
|
|
|
End: index + len(termStr),
|
|
|
|
}
|
|
|
|
index += len(termStr)
|
|
|
|
}
|
|
|
|
return analysis.TokenStream(tokenStream)
|
|
|
|
}
|