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