summaryrefslogtreecommitdiff
path: root/android/util_test.go
diff options
context:
space:
mode:
author Cole Faust <colefaust@google.com> 2023-02-28 16:02:16 -0800
committer Cole Faust <colefaust@google.com> 2023-02-28 16:51:32 -0800
commit18994c73f11db00371be747c8dca6da1c01fa2ef (patch)
tree76516067d92eb71defdcb276a6dc910cb50bd266 /android/util_test.go
parent20eed826fd037d27f87631bd6e64e0ea651621e7 (diff)
Replace SortedStringKeys with SortedKeys
Now that we have generics. Bug: 193460475 Test: presubmits Change-Id: I1594fd8feb505175d5c09c03ef397e5ffd5b09cb
Diffstat (limited to 'android/util_test.go')
-rw-r--r--android/util_test.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/android/util_test.go b/android/util_test.go
index 9b9253b49..51d8e328c 100644
--- a/android/util_test.go
+++ b/android/util_test.go
@@ -641,6 +641,36 @@ func BenchmarkFirstUniqueStrings(b *testing.B) {
}
}
+func testSortedKeysHelper[K Ordered, V any](t *testing.T, name string, input map[K]V, expected []K) {
+ t.Helper()
+ t.Run(name, func(t *testing.T) {
+ actual := SortedKeys(input)
+ if !reflect.DeepEqual(actual, expected) {
+ t.Errorf("expected %q, got %q", expected, actual)
+ }
+ })
+}
+
+func TestSortedKeys(t *testing.T) {
+ testSortedKeysHelper(t, "simple", map[string]string{
+ "b": "bar",
+ "a": "foo",
+ }, []string{
+ "a",
+ "b",
+ })
+ testSortedKeysHelper(t, "ints", map[int]interface{}{
+ 10: nil,
+ 5: nil,
+ }, []int{
+ 5,
+ 10,
+ })
+
+ testSortedKeysHelper(t, "nil", map[string]string(nil), nil)
+ testSortedKeysHelper(t, "empty", map[string]string{}, nil)
+}
+
func TestSortedStringKeys(t *testing.T) {
testCases := []struct {
name string