Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add behat tests for DiffChunkLines

  • Loading branch information...
commit 9c03ecc832646242d279a7258f24d7e8ec315ce9 1 parent 37db8cf
@maff maff authored
Showing with 58 additions and 7 deletions.
  1. +25 −4 features/bootstrap/DiffContext.php
  2. +33 −3 features/diff.feature
View
29 features/bootstrap/DiffContext.php
@@ -23,7 +23,9 @@
GitElephant\Objects\Diff\Diff,
GitElephant\Objects\Diff\DiffObject,
GitElephant\Objects\Diff\DiffChunk,
- GitElephant\Objects\Diff\DiffChunkLine;
+ GitElephant\Objects\Diff\DiffChunkLine,
+ GitElephant\Objects\Diff\DiffChunkLineChanged,
+ GitElephant\Objects\Diff\DiffChunkLineUnchanged;
require_once 'PHPUnit/Autoload.php';
require_once 'PHPUnit/Framework/Assert/Functions.php';
@@ -101,7 +103,6 @@ public function iAddAFileNamedToTheRepositoryWithoutContent($name)
touch($filename);
}
-
/**
* @Given /^I stage and commit$/
*/
@@ -128,7 +129,6 @@ public function theLastCommitShouldBeRoot()
assertTrue($this->repository->getCommit()->isRoot());
}
-
/**
* @Then /^the diff should have "([^"]*)" object of mode "([^"]*)"$/
*/
@@ -164,7 +164,7 @@ public function theDiffobjectInPositionShouldHaveDiffchunk($num, $num_chunks)
public function theDiffobjectInPositionShouldBeARenameFromTo($num, $from, $to)
{
/* @var $diffObject \GitElephant\Objects\Diff\DiffObject */
- $diffObject = $diffObject = $this->diffObjects[$num-1];
+ $diffObject = $this->diffObjects[$num-1];
assertTrue($diffObject->hasPathChanged());
assertEquals($from, $diffObject->getOriginalPath());
@@ -209,7 +209,28 @@ public function theDiffchunklineInPositionShouldBe($pos, $type)
*/
public function theDiffchunklineInPositionShouldHaveLineNumber($pos, $num)
{
+ /* @var $diffChunkLine DiffChunkLineChanged */
$diffChunkLine = $this->diffChunkLines[$pos-1];
assertEquals($diffChunkLine->getNumber(), (int)$num);
}
+
+ /**
+ * @Given /^the diffChunkLine in position "([^"]*)" should have origin line number (\d+)$/
+ */
+ public function theDiffchunklineInPositionShouldHaveOriginLineNumber($pos, $num)
+ {
+ /* @var $diffChunkLine DiffChunkLineUnchanged */
+ $diffChunkLine = $this->diffChunkLines[$pos-1];
+ assertEquals($num, $diffChunkLine->getOriginNumber());
+ }
+
+ /**
+ * @Given /^the diffChunkLine in position "([^"]*)" should have destination line number (\d+)$/
+ */
+ public function theDiffchunklineInPositionShouldHaveDestinationLineNumber($pos, $num)
+ {
+ /* @var $diffChunkLine DiffChunkLineUnchanged */
+ $diffChunkLine = $this->diffChunkLines[$pos-1];
+ assertEquals($num, $diffChunkLine->getDestNumber());
+ }
}
View
36 features/diff.feature
@@ -3,6 +3,7 @@ Feature: Diff Class
As an API user
I need to be able to interact with the git repository and retrieve the diffs
+@finddiffs
Scenario: find diffs in a repository
Given I start a repository for diff
And I add a file named "test-file" to the repository with content
@@ -28,7 +29,7 @@ Scenario: find diffs in a repository
And I stage and commit
Then the diff should have "1" object of mode "index"
And the diffObject in position "1" should have "1" diffChunk
- And the diffChunk in position "1" should have "2" diffChunkLine
+ And the diffChunk in position "1" should have "3" diffChunkLine
And the diffChunkLine in position "1" should be "\GitElephant\Objects\Diff\DiffChunkLineUnchanged"
And the diffChunkLine in position "2" should be "\GitElephant\Objects\Diff\DiffChunkLineAdded"
Then I add a file named "test-file2" to the repository with content
@@ -38,7 +39,7 @@ Scenario: find diffs in a repository
And I stage and commit
Then the diff should have "1" object of mode "index"
And the diffObject in position "1" should have "1" diffChunk
- And the diffChunk in position "1" should have "2" diffChunkLine
+ And the diffChunk in position "1" should have "3" diffChunkLine
And the diffChunkLine in position "1" should be "\GitElephant\Objects\Diff\DiffChunkLineUnchanged"
And the diffChunkLine in position "2" should be "\GitElephant\Objects\Diff\DiffChunkLineDeleted"
Then I add a file named "test-file2" to the repository with content
@@ -86,11 +87,40 @@ Scenario: find diffs in a repository
And the diffChunkLine in position "3" should have line number 3
And the diffChunkLine in position "4" should be "\GitElephant\Objects\Diff\DiffChunkLineAdded"
And the diffChunkLine in position "4" should have line number 3
- And the diffChunk in position "2" should have "7" diffChunkLine
+ And the diffChunk in position "2" should have "8" diffChunkLine
And the diffChunkLine in position "4" should be "\GitElephant\Objects\Diff\DiffChunkLineDeleted"
And the diffChunkLine in position "4" should have line number 13
And the diffChunkLine in position "5" should be "\GitElephant\Objects\Diff\DiffChunkLineAdded"
And the diffChunkLine in position "5" should have line number 13
+ Then I add a file named "test-file2" to the repository with content
+ """
+ first line
+ 2
+ 3 changed
+ 4
+ 5
+ 6
+ 7
+ 7a
+ 7b
+ 8
+ 9
+ 10
+ 11
+ 12
+ 13 changed
+ 14
+ 15
+ """
+ And I stage and commit
+ Then the diff should have "1" object of mode "index"
+ And the diffObject in position "1" should have "1" diffChunk
+ And the diffChunk in position "1" should have "9" diffChunkLine
+ And the diffChunkLine in position "4" should be "\GitElephant\Objects\Diff\DiffChunkLineAdded"
+ And the diffChunkLine in position "5" should be "\GitElephant\Objects\Diff\DiffChunkLineAdded"
+ And the diffChunkLine in position "6" should be "\GitElephant\Objects\Diff\DiffChunkLineUnchanged"
+ And the diffChunkLine in position "6" should have origin line number 8
+ And the diffChunkLine in position "6" should have destination line number 10
Scenario: handle diff renames
Given I start a repository for diff
Please sign in to comment.
Something went wrong with that request. Please try again.