github.com/haalcala/mattermost-server-change-repo@v0.0.0-20210713015153-16753fbeee5f/services/searchengine/utils_test.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See LICENSE.txt for license information.
     3  
     4  package searchengine
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func TestElasticsearchGetSuggestionsSplitBy(t *testing.T) {
    13  	testCases := []struct {
    14  		Name     string
    15  		Term     string
    16  		SplitStr string ``
    17  		Expected []string
    18  	}{
    19  		{
    20  			Name:     "Single string",
    21  			Term:     "string",
    22  			SplitStr: " ",
    23  			Expected: []string{"string"},
    24  		},
    25  		{
    26  			Name:     "String with spaces",
    27  			Term:     "String with spaces",
    28  			SplitStr: " ",
    29  			Expected: []string{"string with spaces", "with spaces", "spaces"},
    30  		},
    31  		{
    32  			Name:     "Username split by a dot",
    33  			Term:     "name.surname",
    34  			SplitStr: ".",
    35  			Expected: []string{"name.surname", ".surname", "surname"},
    36  		},
    37  		{
    38  			Name:     "String split by several dashes",
    39  			Term:     "one-two-three",
    40  			SplitStr: "-",
    41  			Expected: []string{"one-two-three", "-two-three", "two-three", "-three", "three"},
    42  		},
    43  	}
    44  
    45  	for _, tc := range testCases {
    46  		t.Run(tc.Name, func(t *testing.T) {
    47  			res := GetSuggestionInputsSplitBy(tc.Term, tc.SplitStr)
    48  			assert.ElementsMatch(t, res, tc.Expected)
    49  		})
    50  	}
    51  }
    52  
    53  func TestElasticsearchGetSuggestionsSplitByMultiple(t *testing.T) {
    54  	r1 := GetSuggestionInputsSplitByMultiple("String with user.name", []string{" ", "."})
    55  	expectedR1 := []string{"string with user.name", "with user.name", "user.name", ".name", "name"}
    56  	assert.ElementsMatch(t, r1, expectedR1)
    57  }