github.com/blend/go-sdk@v1.20220411.3/stringutil/tokenize_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 tokenizeTestCase struct { 17 corpus string 18 tokens map[string]string 19 expected string 20 message string 21 } 22 23 func TestStringTokenize(t *testing.T) { 24 assert := assert.New(t) 25 26 testCases := []tokenizeTestCase{ 27 {corpus: "", expected: "", message: "should handle the empty input case"}, 28 {corpus: "ff", expected: "ff", message: "should handle the (nearly) empty input case"}, 29 {corpus: "foo/${bar}/baz", expected: "foo/example-string/baz", tokens: map[string]string{"bar": "example-string"}, message: "should handle escaping a single variable"}, 30 {corpus: "foo/${what}/baz", expected: "foo/${what}/baz", tokens: map[string]string{"bar": "example-string"}, message: "should handle unknown variables"}, 31 {corpus: "foo/${bar}/baz/${buzz}", expected: "foo/example-string/baz/dog", tokens: map[string]string{"bar": "example-string", "buzz": "dog"}, message: "should handle escaping multiple variables"}, 32 {corpus: "foo/${bar${buzz}foo}/bar", expected: "foo/${bar${buzz}foo}/bar", tokens: map[string]string{"bar": "example-string", "buzz": "dog"}, message: "nesting variables should produce a weird key"}, 33 } 34 35 for _, testCase := range testCases { 36 assert.Equal(testCase.expected, Tokenize(testCase.corpus, testCase.tokens), testCase.message) 37 } 38 }