Skip to content

Commit

Permalink
added test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
kanodia-parag committed Nov 26, 2024
1 parent 28b6caf commit e5ce419
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions codegen/templates/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,49 @@ func TestRenderFS(t *testing.T) {
// don't look at last character since it's \n on Linux and \r\n on Windows
assert.Equal(t, expectedString, actualContentsStr[:len(expectedString)])
}

func TestDict(t *testing.T) {
tests := []struct {
name string
input []any
expected map[string]any
expectErr bool
}{
{
name: "valid key-value pairs",
input: []any{"key1", "value1", "key2", "value2"},
expected: map[string]any{"key1": "value1", "key2": "value2"},
expectErr: false,
},
{
name: "odd number of arguments",
input: []any{"key1", "value1", "key2"},
expected: nil,
expectErr: true,
},
{
name: "non-string key",
input: []any{"key1", "value1", 123, "value2"},
expected: nil,
expectErr: true,
},
{
name: "empty input",
input: []any{},
expected: map[string]any{},
expectErr: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result, err := dict(tt.input...)
if tt.expectErr {
require.Error(t, err)
} else {
require.NoError(t, err)
assert.Equal(t, tt.expected, result)
}
})
}
}

0 comments on commit e5ce419

Please sign in to comment.