* Expand the value of math and reduce expressions in annotations and labels
This commit makes it possible to use the values of reduce and math
expressions in annotations and labels via their RefIDs. It uses the
Stringer interface to ensure that "{{ $values.A }}" still prints the
value in decimal format while also making the labels for each RefID
available with "{{ $values.A.Labels }}" and the float64 value with
"{{ $values.A.Value }}"
35 lines
753 B
Go
35 lines
753 B
Go
package state
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
ptr "github.com/xorcare/pointer"
|
|
)
|
|
|
|
func TestTemplateCaptureValueStringer(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
value templateCaptureValue
|
|
expected string
|
|
}{{
|
|
name: "nil value returns null",
|
|
value: templateCaptureValue{Value: nil},
|
|
expected: "null",
|
|
}, {
|
|
name: "1.0 is returned as integer value",
|
|
value: templateCaptureValue{Value: ptr.Float64(1.0)},
|
|
expected: "1",
|
|
}, {
|
|
name: "1.1 is returned as decimal value",
|
|
value: templateCaptureValue{Value: ptr.Float64(1.1)},
|
|
expected: "1.1",
|
|
}}
|
|
|
|
for _, c := range cases {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
assert.Equal(t, c.expected, c.value.String())
|
|
})
|
|
}
|
|
}
|