File: interpolate_test.go

package info (click to toggle)
golang-github-alecthomas-kong 0.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 832 kB
  • sloc: sh: 32; makefile: 2
file content (30 lines) | stat: -rw-r--r-- 945 bytes parent folder | download | duplicates (3)
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)
	}
}