@@ -140,6 +140,79 @@ public function test_diff_to_side_by_side_html()
140140 );
141141 }
142142
143+ /**
144+ * @test
145+ */
146+ public function it_can_return_the_diff_statistics ()
147+ {
148+ $ old = new Version (['contents ' => ['title ' => 'example title ' , 'content ' => 'example content ' ]]);
149+
150+ // we are modifying everything
151+ $ new = new Version (['contents ' => ['title ' => 'changing the title ' , 'content ' => 'changing the content ' ]]);
152+
153+ $ stats = (new Diff ($ new , $ old ))->getStatistics ();
154+
155+ $ this ->assertIsArray ($ stats );
156+ $ this ->assertArrayHasKey ('inserted ' , $ stats );
157+ $ this ->assertArrayHasKey ('deleted ' , $ stats );
158+ $ this ->assertArrayHasKey ('unmodified ' , $ stats );
159+
160+ $ this ->assertEquals (2 , $ stats ['inserted ' ]); // two new lines inserted
161+ $ this ->assertEquals (2 , $ stats ['deleted ' ]); // two lines deleted
162+ $ this ->assertEquals (0 , $ stats ['unmodified ' ]); // modified everything
163+ }
164+
165+ /**
166+ * @test
167+ */
168+ public function it_can_return_correct_statistics_for_new_line_insertions ()
169+ {
170+ $ old = new Version (['contents ' => ['title ' => 'example title ' , 'content ' => 'example content ' ]]);
171+
172+ // we are adding two new lines
173+ $ new = new Version (['contents ' => ['content ' => "example content \n adding new line \n another new line " ]]);
174+
175+ $ stats = (new Diff ($ new , $ old ))->getStatistics ();
176+
177+ $ this ->assertEquals (2 , $ stats ['inserted ' ]); // two new lines inserted
178+ $ this ->assertEquals (0 , $ stats ['deleted ' ]); // no deletions
179+ $ this ->assertEquals (1 , $ stats ['unmodified ' ]); // one line unmodified
180+ }
181+
182+ /**
183+ * @test
184+ */
185+ public function it_can_return_correct_statistics_for_deleted_lines ()
186+ {
187+ $ old = new Version (['contents ' => ['title ' => 'example title ' , 'content ' => "example content \n adding new line \n another new line " ]]);
188+
189+ // we are removing last two lines
190+ $ new = new Version (['contents ' => ['content ' => 'example content ' ]]);
191+
192+ $ stats = (new Diff ($ new , $ old ))->getStatistics ();
193+
194+ $ this ->assertEquals (0 , $ stats ['inserted ' ]); // no insertions
195+ $ this ->assertEquals (2 , $ stats ['deleted ' ]); // two lines deleted
196+ $ this ->assertEquals (1 , $ stats ['unmodified ' ]); // one line unmodified
197+ }
198+
199+ /**
200+ * @test
201+ */
202+ public function it_can_return_correct_statistics_for_unmodified_lines ()
203+ {
204+ $ old = new Version (['contents ' => ['title ' => 'example title ' , 'content ' => "example content \n adding new line \n another new line " ]]);
205+
206+ // we are just removing the last line
207+ $ new = new Version (['contents ' => ['content ' => "example content \n adding new line " ]]);
208+
209+ $ stats = (new Diff ($ new , $ old ))->getStatistics ();
210+
211+ $ this ->assertEquals (0 , $ stats ['inserted ' ]); // no insertions
212+ $ this ->assertEquals (1 , $ stats ['deleted ' ]); // one line deleted
213+ $ this ->assertEquals (2 , $ stats ['unmodified ' ]); // two lines unmodified
214+ }
215+
143216 public function test_diff_nested_array_to_array ()
144217 {
145218 $ oldContent = [
0 commit comments