@@ -234,11 +234,11 @@ public function testGetOpcodes(array $old, array $new, array $expected): void
234234 }
235235
236236 /**
237- * Data provider for SequenceMatcher::getGroupedOpcodes with "ignoreWhitespaces ".
237+ * Data provider for SequenceMatcher::getGroupedOpcodes with "ignoreWhitespace ".
238238 *
239239 * @return array the data provider
240240 */
241- public static function getGroupedOpcodesIgnoreWhitespacesDataProvider (): array
241+ public static function getGroupedOpcodesIgnoreWhitespaceDataProvider (): array
242242 {
243243 return [
244244 [
@@ -318,8 +318,8 @@ function foo()
318318 ],
319319 ],
320320 [
321- file_get_contents (__DIR__ . '/data/WorkerCommandA .php ' ),
322- file_get_contents (__DIR__ . '/data/WorkerCommandB .php ' ),
321+ file_get_contents (__DIR__ . '/data/ignore_whitespace/old_1 .php ' ),
322+ file_get_contents (__DIR__ . '/data/ignore_whitespace/new_1 .php ' ),
323323 [
324324 [
325325 [SequenceMatcher::OP_DEL , 217 , 222 , 217 , 217 ],
@@ -330,15 +330,42 @@ function foo()
330330 }
331331
332332 /**
333- * Test the SequenceMatcher::getOpcodes with "ignoreWhitespaces".
333+ * Data provider for SequenceMatcher::getGroupedOpcodes with "ignoreLineEnding".
334+ *
335+ * @return array the data provider
336+ */
337+ public static function getGroupedOpcodesIgnoreLineEndingDataProvider (): array
338+ {
339+ return [
340+ [
341+ file_get_contents (__DIR__ . '/data/ignore_line_ending/old_1.txt ' ),
342+ file_get_contents (__DIR__ . '/data/ignore_line_ending/new_1.txt ' ),
343+ [],
344+ true ,
345+ ],
346+ [
347+ file_get_contents (__DIR__ . '/data/ignore_line_ending/old_1.txt ' ),
348+ file_get_contents (__DIR__ . '/data/ignore_line_ending/new_1.txt ' ),
349+ [
350+ [
351+ [SequenceMatcher::OP_REP , 0 , 2 , 0 , 2 ],
352+ ],
353+ ],
354+ false ,
355+ ],
356+ ];
357+ }
358+
359+ /**
360+ * Test the SequenceMatcher::getOpcodes with "ignoreWhitespace".
334361 *
335362 * @covers \Jfcherng\Diff\SequenceMatcher::getOpcodes
336363 *
337364 * @param string $old the old
338365 * @param string $new the new
339366 * @param array $expected the expected
340367 */
341- #[DataProvider('getGroupedOpcodesIgnoreWhitespacesDataProvider ' )]
368+ #[DataProvider('getGroupedOpcodesIgnoreWhitespaceDataProvider ' )]
342369 public function testGetOpcodesIgnoreWhitespaces (string $ old , string $ new , array $ expected ): void
343370 {
344371 $ this ->sm ->setSequences (explode ("\n" , $ old ), explode ("\n" , $ new ));
@@ -347,6 +374,30 @@ public function testGetOpcodesIgnoreWhitespaces(string $old, string $new, array
347374 static ::assertSame ($ expected , $ this ->sm ->getGroupedOpcodes (0 ));
348375 }
349376
377+ /**
378+ * Test the SequenceMatcher::getOpcodes with "ignoreLineEnding".
379+ *
380+ * @covers \Jfcherng\Diff\SequenceMatcher::getOpcodes
381+ *
382+ * @dataProvider getGroupedOpcodesIgnoreLineEndingDataProvider
383+ *
384+ * @param string $old the old
385+ * @param string $new the new
386+ * @param array $expected the expected
387+ * @param array $ignoreLineEnding should ignore line ending
388+ */
389+ public function testGetOpcodesIgnoreLineEnding (
390+ string $ old ,
391+ string $ new ,
392+ array $ expected ,
393+ bool $ ignoreLineEnding
394+ ): void {
395+ $ this ->sm ->setSequences (explode ("\n" , $ old ), explode ("\n" , $ new ));
396+ $ this ->sm ->setOptions (['ignoreLineEnding ' => $ ignoreLineEnding ]);
397+
398+ static ::assertSame ($ expected , $ this ->sm ->getGroupedOpcodes (0 ));
399+ }
400+
350401 /**
351402 * @see https://github.com/jfcherng/php-sequence-matcher/issues/2
352403 */
0 commit comments