| 1 |
package dedupe_test |
| 2 |
|
| 3 |
import ( |
| 4 |
"reflect" |
| 5 |
"testing" |
| 6 |
|
| 7 |
"github.com/nicholas-fedor/shoutrrr/internal/dedupe" |
| 8 |
) |
| 9 |
|
| 10 |
func TestRemoveDuplicates(t *testing.T) { |
| 11 |
t.Parallel() |
| 12 |
|
| 13 |
tests := map[string]struct { |
| 14 |
input []string |
| 15 |
want []string |
| 16 |
}{ |
| 17 |
"no duplicates": { |
| 18 |
input: []string{"a", "b", "c"}, |
| 19 |
want: []string{"a", "b", "c"}, |
| 20 |
}, |
| 21 |
"duplicate inside slice": { |
| 22 |
input: []string{"a", "b", "a", "c"}, |
| 23 |
want: []string{"a", "b", "c"}, |
| 24 |
}, |
| 25 |
"duplicate at end of slice": { |
| 26 |
input: []string{"a", "b", "c", "a"}, |
| 27 |
want: []string{"a", "b", "c"}, |
| 28 |
}, |
| 29 |
"duplicate next to each other inside slice": { |
| 30 |
input: []string{"a", "b", "b", "c"}, |
| 31 |
want: []string{"a", "b", "c"}, |
| 32 |
}, |
| 33 |
} |
| 34 |
|
| 35 |
for name, tc := range tests { |
| 36 |
t.Run(name, func(t *testing.T) { |
| 37 |
t.Parallel() |
| 38 |
|
| 39 |
got := dedupe.RemoveDuplicates(tc.input) |
| 40 |
if !reflect.DeepEqual(tc.want, got) { |
| 41 |
t.Fatalf("expected: %#v, got: %#v", tc.want, got) |
| 42 |
} |
| 43 |
}) |
| 44 |
} |
| 45 |
} |