-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apply: add unit tests for parse_range and rename parse_range to parse…
…_fragment_range This patchset makes the parse_range function in apply be non-internal linkage in order to expose to the unit testing framework. In so doing, because there is another function called parse_range, I gave this one a more specific name, parse_fragment_range. Other than that, this commit adds several test cases (positive and negative) for the function. Signed-off-by: Philip Peterson <philip.c.peterson@gmail.com>
- Loading branch information
1 parent
186b115
commit 9f88d9c
Showing
4 changed files
with
76 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include "test-lib.h" | ||
#include "apply.h" | ||
|
||
#define FAILURE -1 | ||
|
||
static void setup_static(const char *line, int len, int offset, | ||
const char *expect, int assert_result, | ||
unsigned long assert_p1, | ||
unsigned long assert_p2) | ||
{ | ||
unsigned long p1 = 9999; | ||
unsigned long p2 = 9999; | ||
int result = parse_fragment_range(line, len, offset, expect, &p1, &p2); | ||
check_int(result, ==, assert_result); | ||
check_int(p1, ==, assert_p1); | ||
check_int(p2, ==, assert_p2); | ||
} | ||
|
||
int cmd_main(int argc, const char **argv) | ||
{ | ||
char* text; | ||
int expected_result; | ||
|
||
/* Success */ | ||
text = "@@ -4,4 +"; | ||
expected_result = 9; | ||
TEST(setup_static(text, strlen(text), 4, " +", expected_result, 4, 4), | ||
"well-formed range"); | ||
|
||
text = "@@ -4 +8 @@"; | ||
expected_result = 7; | ||
TEST(setup_static(text, strlen(text), 4, " +", expected_result, 4, 1), | ||
"non-comma range"); | ||
|
||
/* Failure */ | ||
text = "@@ -X,4 +"; | ||
expected_result = FAILURE; | ||
TEST(setup_static(text, strlen(text), 4, " +", expected_result, 9999, 9999), | ||
"non-digit range (first coordinate)"); | ||
|
||
text = "@@ -4,X +"; | ||
expected_result = FAILURE; | ||
TEST(setup_static(text, strlen(text), 4, " +", expected_result, 4, 1), // p2 is 1, a little strange but not catastrophic | ||
"non-digit range (second coordinate)"); | ||
|
||
text = "@@ -4,4 -"; | ||
expected_result = FAILURE; | ||
TEST(setup_static(text, strlen(text), 4, " +", expected_result, 4, 4), | ||
"non-expected trailing text"); | ||
|
||
text = "@@ -4,4"; | ||
expected_result = FAILURE; | ||
TEST(setup_static(text, strlen(text), 4, " +", expected_result, 4, 4), | ||
"not long enough for expected trailing text"); | ||
|
||
text = "@@ -4,4"; | ||
expected_result = FAILURE; | ||
TEST(setup_static(text, strlen(text), 7, " +", expected_result, 9999, 9999), | ||
"not long enough for offset"); | ||
|
||
text = "@@ -4,4"; | ||
expected_result = FAILURE; | ||
TEST(setup_static(text, strlen(text), -1, " +", expected_result, 9999, 9999), | ||
"negative offset"); | ||
|
||
return test_done(); | ||
} |