@@ -107,15 +107,56 @@ func TestResolveWithStringConcatenation(t *testing.T) {
107107 assert .Equal (t , "aba" , getByPath (t , out , "c" ).MustString ())
108108}
109109
110- func TestResolveWithTypeRetentionFailure (t * testing.T ) {
110+ func TestResolveWithTypeInterpolation (t * testing.T ) {
111111 in := dyn .V (map [string ]dyn.Value {
112- "a" : dyn .V (1 ),
113- "b" : dyn .V (2 ),
114- "c" : dyn .V ("${a} ${b}" ),
112+ "a" : dyn .V (1 ),
113+ "b" : dyn .V (2 ),
114+ "c" : dyn .V ("${a} ${b}" ),
115+ "float_val" : dyn .V (3.14 ),
116+ "bool_true" : dyn .V (true ),
117+ "bool_false" : dyn .V (false ),
118+ "time_val" : dyn .V (dyn .MustTime ("2024-01-01" )),
119+ "nil_val" : dyn .NilValue ,
120+ // Test interpolation of different types in string templates
121+ "float_interp" : dyn .V ("Value: ${float_val}" ),
122+ "bool_true_interp" : dyn .V ("Enabled: ${bool_true}" ),
123+ "bool_false_interp" : dyn .V ("Disabled: ${bool_false}" ),
124+ "time_interp" : dyn .V ("Date: ${time_val}" ),
125+ "nil_interp" : dyn .V ("Null: ${nil_val}" ),
115126 })
116127
117- _ , err := dynvar .Resolve (in , dynvar .DefaultLookup (in ))
118- require .ErrorContains (t , err , "cannot interpolate non-string value: ${a}" )
128+ out , err := dynvar .Resolve (in , dynvar .DefaultLookup (in ))
129+ require .NoError (t , err )
130+
131+ // Integer interpolation
132+ assert .EqualValues (t , "1 2" , getByPath (t , out , "c" ).MustString ())
133+
134+ // Float interpolation
135+ assert .EqualValues (t , "Value: 3.14" , getByPath (t , out , "float_interp" ).MustString ())
136+
137+ // Bool interpolation
138+ assert .EqualValues (t , "Enabled: true" , getByPath (t , out , "bool_true_interp" ).MustString ())
139+ assert .EqualValues (t , "Disabled: false" , getByPath (t , out , "bool_false_interp" ).MustString ())
140+
141+ // Time interpolation should convert to string representation of time.Time
142+ // Note: time.Time string representation includes timezone info
143+ timeResult := getByPath (t , out , "time_interp" ).MustString ()
144+ assert .Contains (t , timeResult , "Date: 2024-01-01" )
145+ assert .Contains (t , timeResult , "00:00:00" )
146+
147+ // Nil interpolation
148+ assert .EqualValues (t , "Null: <nil>" , getByPath (t , out , "nil_interp" ).MustString ())
149+ }
150+
151+ func TestResolveWithTypeRetentionFailure (t * testing.T ) {
152+ // Test that mapping interpolation fails with an error
153+ mappingTest := dyn .V (map [string ]dyn.Value {
154+ "mapping" : dyn .V (map [string ]dyn.Value {"key" : dyn .V ("value" )}),
155+ "interp" : dyn .V ("Config: ${mapping}" ),
156+ })
157+ _ , err := dynvar .Resolve (mappingTest , dynvar .DefaultLookup (mappingTest ))
158+ require .Error (t , err )
159+ assert .Equal (t , "cannot interpolate non-primitive value of type map into string" , err .Error ())
119160}
120161
121162func TestResolveWithTypeRetention (t * testing.T ) {
0 commit comments