Skip to content

Commit cc200ff

Browse files
committed
test: replace constructor value tests with one table test
The previous commit added a separate 177-line test file for the constructor fix. Parts of it pass without the fix, and TestConstructedValuesDefaultStorage asserted that changing the caller's slice after NewStringSlice(defaults...) shows up in Value(), which is not something we want to promise. Test Set on one constructor per value type in flag_test.go instead, next to the other constructor tests. Each case panics without the fix. Reference: eddb896 ("fix: initialize parsers in collection value constructors") Assisted-by: claude:claude-opus-5-5 Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
1 parent eddb896 commit cc200ff

2 files changed

Lines changed: 21 additions & 177 deletions

File tree

‎constructor_values_test.go‎

Lines changed: 0 additions & 177 deletions
This file was deleted.

‎flag_test.go‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2580,6 +2580,27 @@ func TestStringMap_Serialized_Set(t *testing.T) {
25802580
require.Equal(t, m0.String(), m1.String(), "pre and post serialization do not match")
25812581
}
25822582

2583+
func TestSliceAndMapConstructorsSet(t *testing.T) {
2584+
tests := []struct {
2585+
name string
2586+
value Value
2587+
input string
2588+
want any
2589+
}{
2590+
{"string slice", NewStringSlice("old"), "a,b", []string{"a", "b"}},
2591+
{"int slice", NewIntSlice(1), "2,3", []int{2, 3}},
2592+
{"uint slice", NewUintSlice(1), "2,3", []uint{2, 3}},
2593+
{"float slice", NewFloatSlice(1), "2.5,3.5", []float64{2.5, 3.5}},
2594+
{"string map", NewStringMap(map[string]string{"old": "v"}), "k=v", map[string]string{"k": "v"}},
2595+
}
2596+
for _, tt := range tests {
2597+
t.Run(tt.name, func(t *testing.T) {
2598+
require.NoError(t, tt.value.Set(tt.input))
2599+
require.Equal(t, tt.want, tt.value.Get())
2600+
})
2601+
}
2602+
}
2603+
25832604
var timestampFlagTests = []struct {
25842605
name string
25852606
aliases []string

0 commit comments

Comments
 (0)