Denny Vrandecic has submitted this change and it was merged. Change subject: Improved ListPatcherTest ......................................................................
Improved ListPatcherTest Change-Id: Ie4be97512dd2831ffd5d88f7da5e859fcc5ac37c --- M tests/phpunit/patcher/ListPatcherTest.php 1 file changed, 82 insertions(+), 18 deletions(-) Approvals: Denny Vrandecic: Looks good to me, approved jenkins-bot: Verified diff --git a/tests/phpunit/patcher/ListPatcherTest.php b/tests/phpunit/patcher/ListPatcherTest.php index 32bfaa4..8234c01 100644 --- a/tests/phpunit/patcher/ListPatcherTest.php +++ b/tests/phpunit/patcher/ListPatcherTest.php @@ -5,6 +5,7 @@ use Diff\Diff; use Diff\DiffOpAdd; use Diff\DiffOpRemove; +use Diff\ListPatcher; use Diff\MapPatcher; use Diff\Patcher; @@ -42,14 +43,77 @@ public function patchProvider() { $argLists = array(); - $patcher = new \Diff\ListPatcher(); + $patcher = new ListPatcher(); $base = array(); $diff = new Diff(); $expected = array(); $argLists[] = array( $patcher, $base, $diff, $expected ); - // TODO + + $patcher = new ListPatcher(); + $base = array( 4, 2 ); + $diff = new Diff(); + $expected = array( 4, 2 ); + + $argLists[] = array( $patcher, $base, $diff, $expected ); + + + $patcher = new ListPatcher(); + $base = array(); + $diff = new Diff( array( + new DiffOpAdd( 9001 ) + ) ); + $expected = array( 9001 ); + + $argLists[] = array( $patcher, $base, $diff, $expected ); + + + $patcher = new ListPatcher(); + $base = array( 4, 2 ); + $diff = new Diff( array( + new DiffOpAdd( 9001 ) + ) ); + $expected = array( 4, 2, 9001 ); + + $argLists[] = array( $patcher, $base, $diff, $expected ); + + + $patcher = new ListPatcher(); + $base = array( 4, 2 ); + $diff = new Diff( array( + new DiffOpAdd( 9001 ), + new DiffOpAdd( 9002 ), + new DiffOpAdd( 2 ) + ) ); + $expected = array( 4, 2, 9001, 9002, 2 ); + + $argLists[] = array( $patcher, $base, $diff, $expected ); + + + $patcher = new ListPatcher(); + $base = array( 0, 1, 2, 3, 4 ); + $diff = new Diff( array( + new DiffOpRemove( 2 ), + new DiffOpRemove( 3 ), + ) ); + $expected = array( 0, 1, 4 ); + + $argLists[] = array( $patcher, $base, $diff, $expected ); + + + $patcher = new ListPatcher(); + $base = array( 0, 1, 2, 2, 2, 3, 4 ); + $diff = new Diff( array( + new DiffOpRemove( 2 ), + new DiffOpRemove( 3 ), + new DiffOpAdd( 6 ), + new DiffOpRemove( 2 ), + ) ); + $expected = array( 0, 1, 2, 4, 6 ); + + $argLists[] = array( $patcher, $base, $diff, $expected ); + return $argLists; } @@ -65,7 +129,22 @@ public function testPatch( Patcher $patcher, array $base, Diff $diff, array $expected ) { $actual = $patcher->patch( $base, $diff ); - $this->assertArrayEquals( $actual, $expected ); + $this->assertArrayEquals( $expected, $actual ); + } + + /** + * @dataProvider getApplicableDiffProvider + * + * @param Diff $diff + * @param array $currentObject + * @param Diff $expected + * @param string|null $message + */ + public function testGetApplicableDiff( Diff $diff, array $currentObject, Diff $expected, $message = null ) { + $patcher = new MapPatcher(); + $actual = $patcher->getApplicableDiff( $currentObject, $diff ); + + $this->assertEquals( $expected->getOperations(), $actual->getOperations(), $message ); } public function getApplicableDiffProvider() { @@ -152,21 +231,6 @@ $argLists[] = array( $diff, $currentObject, $expected, 'list diffs containing only remove ops should be retained when present in the base' ); return $argLists; - } - - /** - * @dataProvider getApplicableDiffProvider - * - * @param Diff $diff - * @param array $currentObject - * @param Diff $expected - * @param string|null $message - */ - public function testGetApplicableDiff( Diff $diff, array $currentObject, Diff $expected, $message = null ) { - $patcher = new MapPatcher(); - $actual = $patcher->getApplicableDiff( $currentObject, $diff ); - - $this->assertEquals( $expected->getOperations(), $actual->getOperations(), $message ); } } -- To view, visit https://gerrit.wikimedia.org/r/64803 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ie4be97512dd2831ffd5d88f7da5e859fcc5ac37c Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Diff Gerrit-Branch: master Gerrit-Owner: Jeroen De Dauw <jeroended...@gmail.com> Gerrit-Reviewer: Denny Vrandecic <denny.vrande...@wikimedia.de> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits