github.com/blend/go-sdk@v1.20220411.3/stringutil/replace_any_test.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package stringutil
     9  
    10  import (
    11  	"testing"
    12  
    13  	"github.com/blend/go-sdk/assert"
    14  )
    15  
    16  type replaceAnyTestCase struct {
    17  	expected  string
    18  	corpus    string
    19  	with      rune
    20  	toReplace []rune
    21  }
    22  
    23  func TestReplaceAny(t *testing.T) {
    24  	assert := assert.New(t)
    25  
    26  	testCases := []replaceAnyTestCase{
    27  		{expected: "", corpus: "", with: '_', toReplace: Symbols},
    28  		{expected: "foo", corpus: "foo", with: '_', toReplace: Symbols},
    29  		{expected: "foo_", corpus: "foo$", with: '_', toReplace: Symbols},
    30  		{expected: "_foo_", corpus: "&foo$", with: '_', toReplace: Symbols},
    31  		{expected: "_fo o_", corpus: "&fo o$", with: '_', toReplace: Symbols},
    32  	}
    33  
    34  	for _, testCase := range testCases {
    35  		assert.Equal(testCase.expected, ReplaceAny(testCase.corpus, testCase.with, testCase.toReplace...))
    36  	}
    37  }