Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
126 lines (118 loc) · 2.54 KB

File metadata and controls

126 lines (118 loc) · 2.54 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package maps_test
import (
"strconv"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/coder/coder/v2/coderd/util/maps"
)
func TestSortedKeys(t *testing.T) {
t.Parallel()
for idx, tc := range []struct {
name string
input map[string]int
expected []string
}{
{
name: "SortsAlphabetically",
input: map[string]int{
"banana": 1,
"apple": 2,
"cherry": 3,
},
expected: []string{"apple", "banana", "cherry"},
},
{
name: "AlreadySorted",
input: map[string]int{
"alpha": 1,
"mango": 2,
"zebra": 3,
},
expected: []string{"alpha", "mango", "zebra"},
},
{
name: "EmptyMap",
input: map[string]int{},
expected: nil,
},
} {
t.Run("#"+strconv.Itoa(idx)+"_"+tc.name, func(t *testing.T) {
t.Parallel()
got := maps.SortedKeys(tc.input)
if diff := cmp.Diff(tc.expected, got); diff != "" {
t.Fatalf("unexpected result (-want +got):\n%s", diff)
}
})
}
}
func TestSubset(t *testing.T) {
t.Parallel()
for idx, tc := range []struct {
a map[string]string
b map[string]string
// expected value from Subset
expected bool
}{
{
a: nil,
b: nil,
expected: true,
},
{
a: map[string]string{},
b: map[string]string{},
expected: true,
},
{
a: map[string]string{"a": "1", "b": "2"},
b: map[string]string{"a": "1", "b": "2"},
expected: true,
},
{
a: map[string]string{"a": "1", "b": "2"},
b: map[string]string{"a": "1"},
expected: false,
},
{
a: map[string]string{"a": "1"},
b: map[string]string{"a": "1", "b": "2"},
expected: true,
},
{
a: map[string]string{"a": "1", "b": "2"},
b: map[string]string{},
expected: false,
},
{
a: map[string]string{"a": "1", "b": "2"},
b: map[string]string{"a": "1", "b": "3"},
expected: false,
},
// Zero value
{
a: map[string]string{"a": "1", "b": ""},
b: map[string]string{"a": "1", "b": "3"},
expected: true,
},
// Zero value, but the other way round
{
a: map[string]string{"a": "1", "b": "3"},
b: map[string]string{"a": "1", "b": ""},
expected: false,
},
// Both zero values
{
a: map[string]string{"a": "1", "b": ""},
b: map[string]string{"a": "1", "b": ""},
expected: true,
},
} {
t.Run("#"+strconv.Itoa(idx), func(t *testing.T) {
t.Parallel()
actual := maps.Subset(tc.a, tc.b)
if actual != tc.expected {
t.Errorf("expected %v, got %v", tc.expected, actual)
}
})
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.