Skip to content

Commit

Permalink
add tests for normalize
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanfkeepers committed Nov 5, 2024
1 parent 74d3e25 commit 120354d
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions internal/stringify/fmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,77 @@ func TestFmt(t *testing.T) {
})
}
}

func TestNormalize(t *testing.T) {
table := []struct {
name string
input []any
expect map[string]any
}{
{
name: "nil",
input: nil,
expect: map[string]any{},
},
{
name: "any is nil",
input: []any{nil},
expect: map[string]any{"": nil},
},
{
name: "string",
input: []any{"fisher flannigan", "fitzbog"},
expect: map[string]any{"fisher flannigan": "fitzbog"},
},
{
name: "number",
input: []any{-1.2345, 54321},
expect: map[string]any{"-1.2345": "54321"},
},
{
name: "slice",
input: []any{[]int{1, 2, 3, 4, 5}, []string{"a", "b"}},
expect: map[string]any{"[1 2 3 4 5]": "[a b]"},
},
{
name: "map",
input: []any{
map[string]struct{}{
"fisher flannigan fitzbog": struct{}{},
},
map[int]int{},
},
expect: map[string]any{`map[fisher flannigan fitzbog:{}]`: "map[]"},
},
{
name: "concealer",
input: []any{aConcealer{"fisher flannigan fitzbog"}},
expect: map[string]any{"***": nil},
},
{
name: "stringer",
input: []any{aStringer{"I have seen the fnords."}},
expect: map[string]any{"I have seen the fnords.": nil},
},
{
name: "not a stringer",
input: []any{notAStringer{"I have seen the fnords."}},
expect: map[string]any{"{v:I have seen the fnords.}": nil},
},
{
name: "many values",
input: []any{1, "a", true, aStringer{"smarf"}},
expect: map[string]any{
"1": "a",
"true": "smarf",
},
},
}

for _, test := range table {
t.Run(test.name, func(t *testing.T) {
result := Normalize(test.input...)
assert.Equal(t, test.expect, result)
})
}
}

0 comments on commit 120354d

Please sign in to comment.