@@ -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 ) {
@@ -72,6 +79,14 @@ func TestNewDigester(t *testing.T) {
7279		g .Expect (d .index ).To (Equal (i ))
7380		g .Expect (d .digests ).ToNot (BeNil ())
7481	})
82+ 
83+ 	t .Run ("handles multiple WithIndex options, applying last one" , func (t  * testing.T ) {
84+ 		g  :=  NewWithT (t )
85+ 		firstIndex  :=  map [string ]string {"a" : "b" }
86+ 		secondIndex  :=  map [string ]string {"c" : "d" }
87+ 		d  :=  NewDigester (WithIndex (firstIndex ), WithIndex (secondIndex ))
88+ 		g .Expect (d .index ).To (Equal (secondIndex ))
89+ 	})
7590}
7691
7792func  TestDigester_Add (t  * testing.T ) {
@@ -107,6 +122,13 @@ func TestDigester_Add(t *testing.T) {
107122
108123		g .Expect (d .digests ).To (BeEmpty ())
109124	})
125+ 
126+ 	t .Run ("adds empty key and value" , func (t  * testing.T ) {
127+ 		g  :=  NewWithT (t )
128+ 		d  :=  NewDigester ()
129+ 		d .Add ("" , "" )
130+ 		g .Expect (d .index ).To (HaveKeyWithValue ("" , "" ))
131+ 	})
110132}
111133
112134func  TestDigester_Delete (t  * testing.T ) {
@@ -138,6 +160,14 @@ func TestDigester_Delete(t *testing.T) {
138160		d .Delete ("foo" )
139161		g .Expect (d .digests ).To (BeEmpty ())
140162	})
163+ 
164+ 	t .Run ("deletes non-existent key without error" , func (t  * testing.T ) {
165+ 		g  :=  NewWithT (t )
166+ 		d  :=  NewDigester ()
167+ 		d .Delete ("non-existent" )
168+ 		g .Expect (d .index ).To (BeEmpty ())   // Index should remain empty 
169+ 		g .Expect (d .digests ).To (BeEmpty ()) // Digests should remain empty as no change 
170+ 	})
141171}
142172
143173func  TestDigester_Get (t  * testing.T ) {
@@ -161,17 +191,26 @@ func TestDigester_Has(t *testing.T) {
161191}
162192
163193func  TestDigester_Index (t  * testing.T ) {
164- 	g  :=  NewWithT (t )
194+ 	t .Run ("returns a copy of the index" , func (t  * testing.T ) {
195+ 		g  :=  NewWithT (t )
165196
166- 	i  :=  map [string ]string {
167- 		"foo" : "bar" ,
168- 		"bar" : "baz" ,
169- 	}
170- 	d  :=  NewDigester (WithIndex (i ))
197+ 		 i  :=  map [string ]string {
198+ 			 "foo" : "bar" ,
199+ 			 "bar" : "baz" ,
200+ 		 }
201+ 		 d  :=  NewDigester (WithIndex (i ))
171202
172- 	iCopy  :=  d .Index ()
173- 	g .Expect (iCopy ).To (Equal (i ))
174- 	g .Expect (iCopy ).ToNot (BeIdenticalTo (i ))
203+ 		iCopy  :=  d .Index ()
204+ 		g .Expect (iCopy ).To (Equal (i ))
205+ 		g .Expect (iCopy ).ToNot (BeIdenticalTo (i ))
206+ 	})
207+ 
208+ 	t .Run ("returns an empty copy for an empty index" , func (t  * testing.T ) {
209+ 		g  :=  NewWithT (t )
210+ 		d  :=  NewDigester ()
211+ 		emptyIndex  :=  d .Index ()
212+ 		g .Expect (emptyIndex ).To (BeEmpty ())
213+ 	})
175214}
176215
177216func  TestDigester_Len (t  * testing.T ) {
@@ -183,6 +222,8 @@ func TestDigester_Len(t *testing.T) {
183222	}))
184223
185224	g .Expect (d .Len ()).To (Equal (2 ))
225+ 
226+ 	g .Expect (NewDigester ().Len ()).To (Equal (0 ))
186227}
187228
188229func  TestDigester_String (t  * testing.T ) {
@@ -196,6 +237,8 @@ func TestDigester_String(t *testing.T) {
196237	g .Expect (d .String ()).To (Equal (`bar baz 
197238foo bar 
198239` ))
240+ 
241+ 	g .Expect (NewDigester ().String ()).To (Equal ("" ))
199242}
200243
201244func  TestDigester_WriteTo (t  * testing.T ) {
0 commit comments