github.com/avicd/go-utilx@v0.1.0/tokx/pair_test.go (about)

     1  package tokx
     2  
     3  import (
     4  	"github.com/stretchr/testify/assert"
     5  	"reflect"
     6  	"testing"
     7  )
     8  
     9  func TestHasPair(t *testing.T) {
    10  	pair := NewPair("#{", "}")
    11  	assert.Equal(t, true, pair.Match("#{}"))
    12  	assert.Equal(t, false, pair.Match("\\#{}"))
    13  	assert.Equal(t, false, pair.Match("#{\\}"))
    14  }
    15  
    16  func TestPairToken_Map(t *testing.T) {
    17  	pair := NewPair("#{", "}")
    18  	sql := "INSERT INTO USER(name,age,height) VALUES(#{name},#{age},#{height})"
    19  	var list []string
    20  	val := pair.Map(sql, func(s string) string {
    21  		list = append(list, s)
    22  		return "?"
    23  	})
    24  	assert.Equal(t, val, "INSERT INTO USER(name,age,height) VALUES(?,?,?)")
    25  	assert.Equal(t, true, reflect.DeepEqual(list, []string{"name", "age", "height"}))
    26  }