@@ -49,6 +49,13 @@ func TestWithIndex(t *testing.T) {
4949
5050 g .Expect (d .digests ).To (BeEmpty ())
5151 })
52+
53+ t .Run ("handles nil index" , func (t * testing.T ) {
54+ g := NewWithT (t )
55+ d := & Digester {}
56+ WithIndex (nil )(d )
57+ g .Expect (d .index ).To (BeNil ())
58+ })
5259}
5360
5461func TestNewDigester (t * testing.T ) {
@@ -107,6 +114,13 @@ func TestDigester_Add(t *testing.T) {
107114
108115 g .Expect (d .digests ).To (BeEmpty ())
109116 })
117+
118+ t .Run ("adds empty key and value" , func (t * testing.T ) {
119+ g := NewWithT (t )
120+ d := NewDigester ()
121+ d .Add ("" , "" )
122+ g .Expect (d .index ).To (HaveKeyWithValue ("" , "" ))
123+ })
110124}
111125
112126func TestDigester_Delete (t * testing.T ) {
@@ -138,6 +152,14 @@ func TestDigester_Delete(t *testing.T) {
138152 d .Delete ("foo" )
139153 g .Expect (d .digests ).To (BeEmpty ())
140154 })
155+
156+ t .Run ("deletes non-existent key without error" , func (t * testing.T ) {
157+ g := NewWithT (t )
158+ d := NewDigester ()
159+ d .Delete ("non-existent" )
160+ g .Expect (d .index ).To (BeEmpty ())
161+ g .Expect (d .digests ).To (BeEmpty ())
162+ })
141163}
142164
143165func TestDigester_Get (t * testing.T ) {
@@ -161,17 +183,26 @@ func TestDigester_Has(t *testing.T) {
161183}
162184
163185func TestDigester_Index (t * testing.T ) {
164- g := NewWithT (t )
186+ t .Run ("returns a copy of the index" , func (t * testing.T ) {
187+ g := NewWithT (t )
165188
166- i := map [string ]string {
167- "foo" : "bar" ,
168- "bar" : "baz" ,
169- }
170- d := NewDigester (WithIndex (i ))
189+ i := map [string ]string {
190+ "foo" : "bar" ,
191+ "bar" : "baz" ,
192+ }
193+ d := NewDigester (WithIndex (i ))
171194
172- iCopy := d .Index ()
173- g .Expect (iCopy ).To (Equal (i ))
174- g .Expect (iCopy ).ToNot (BeIdenticalTo (i ))
195+ iCopy := d .Index ()
196+ g .Expect (iCopy ).To (Equal (i ))
197+ g .Expect (iCopy ).ToNot (BeIdenticalTo (i ))
198+ })
199+
200+ t .Run ("returns an empty copy for an empty index" , func (t * testing.T ) {
201+ g := NewWithT (t )
202+ d := NewDigester ()
203+ emptyIndex := d .Index ()
204+ g .Expect (emptyIndex ).To (BeEmpty ())
205+ })
175206}
176207
177208func TestDigester_Len (t * testing.T ) {
@@ -183,6 +214,8 @@ func TestDigester_Len(t *testing.T) {
183214 }))
184215
185216 g .Expect (d .Len ()).To (Equal (2 ))
217+
218+ g .Expect (NewDigester ().Len ()).To (Equal (0 ))
186219}
187220
188221func TestDigester_String (t * testing.T ) {
@@ -196,6 +229,8 @@ func TestDigester_String(t *testing.T) {
196229 g .Expect (d .String ()).To (Equal (`bar baz
197230foo bar
198231` ))
232+
233+ g .Expect (NewDigester ().String ()).To (Equal ("" ))
199234}
200235
201236func TestDigester_WriteTo (t * testing.T ) {
0 commit comments