Closed Mido-sys closed 1 year ago
@Mido-sys, this is great! Could we add a test case that checks when the map has a key type of a non-empty interface?
@paganotoni, I think I covered it in this test:
func Test_Render_Hash_Key_Interface(t *testing.T) {
r := require.New(t)
input := `<%= m["first"]%>`
s, err := Render(input, NewContextWith(map[string]interface{}{
"m": map[interface{}]bool{"first": true},
}))
r.NoError(err)
r.Equal("true", s)
}
Yes. you're right @Mido-sys! Thanks for pointing it out.
What is being done in this PR?
Fixes issue#176
What are the main choices made to get to this solution?
If the map key is not of
interface{}
type then the index and map key type should be the same. If not then an error will be returned"line 1: cannot use first (string constant) as int value in map index"
List the manual test cases you've covered before sending this PR:
Created two new tests under
hashes_test.go
.Test_Render_Hash_Key_Interface
: This test should pass as the map key type is of a typeinterface{}
Test_Render_Hash_Key_Int_With_String_Index
: This test should return an error because the map key type is int and accessing it with a string.