github.com/maresnic/mr-kong@v1.0.0/interpolate_test.go (about)

     1  package kong
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/alecthomas/assert/v2"
     7  )
     8  
     9  func TestInterpolate(t *testing.T) {
    10  	vars := map[string]string{
    11  		"age":  "35",
    12  		"city": "Melbourne",
    13  	}
    14  	updatedVars := map[string]string{
    15  		"height": "180",
    16  	}
    17  	actual, err := interpolate("${name=Bobby Brown} is ${age} years old, ${height} cm tall, lives in ${city=<unknown>}, and likes $${AUD}", vars, updatedVars)
    18  	assert.NoError(t, err)
    19  	assert.Equal(t, `Bobby Brown is 35 years old, 180 cm tall, lives in Melbourne, and likes ${AUD}`, actual)
    20  }
    21  
    22  func TestHasInterpolatedVar(t *testing.T) {
    23  	for _, tag := range []string{"name", "age", "height", "city"} {
    24  		assert.True(t, HasInterpolatedVar("${name=Bobby Brown} is ${age} years old, ${height} cm tall, lives in ${city=<unknown>}, and likes $${AUD}", tag), tag)
    25  	}
    26  
    27  	for _, tag := range []string{"name", "age", "height", "AUD"} {
    28  		assert.False(t, HasInterpolatedVar("$name $$age {height} $${AUD}", tag), tag)
    29  	}
    30  }