Created
March 20, 2012 22:34
-
-
Save arrbee/2141997 to your computer and use it in GitHub Desktop.
Sample libgit2 test of commit header parsing
This file contains hidden or 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
#include "clar_libgit2.h" | |
#include "repository.h" | |
#include "signature.h" | |
typedef struct { | |
const char *line; | |
const char *header; | |
} parse_test_case; | |
static parse_test_case header_passing_tests[] = { | |
{ "parent 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "parent " }, | |
{ "tree 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree " }, | |
{ "random_heading 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "random_heading " }, | |
{ "stuck_heading05452d6349abcd67aa396dfb28660d765d8b2a36\n", "stuck_heading" }, | |
{ "tree 5F4BEFFC0759261D015AA63A3A85613FF2F235DE\n", "tree " }, | |
{ "tree 1A669B8AB81B5EB7D9DB69562D34952A38A9B504\n", "tree " }, | |
{ "tree 5B20DCC6110FCC75D31C6CEDEBD7F43ECA65B503\n", "tree " }, | |
{ "tree 173E7BF00EA5C33447E99E6C1255954A13026BE4\n", "tree " }, | |
{ NULL, NULL } | |
}; | |
static parse_test_case header_failing_tests[] = { | |
{ "parent 05452d6349abcd67aa396dfb28660d765d8b2a36", "parent " }, | |
{ "05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree " }, | |
{ "parent05452d6349abcd67aa396dfb28660d765d8b2a6a\n", "parent " }, | |
{ "parent 05452d6349abcd67aa396dfb280d765d8b2a6\n", "parent " }, | |
{ "tree 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree " }, | |
{ "parent 0545xd6349abcd67aa396dfb28660d765d8b2a36\n", "parent " }, | |
{ "parent 0545xd6349abcd67aa396dfb28660d765d8b2a36FF\n", "parent " }, | |
{ "", "tree " }, | |
{ "", "" }, | |
{ NULL, NULL } | |
}; | |
void test_commit_parse__header(void) | |
{ | |
git_oid oid; | |
const char *line, *line_end; | |
parse_test_case *scan; | |
for (scan = header_passing_tests; scan->line != NULL; scan++) { | |
line = scan->line; | |
line_end = line + strlen(line); | |
cl_git_pass(git_oid__parse(&oid, &line, line_end, scan->header)); | |
cl_assert(line == line_end); | |
} | |
for (scan = header_failing_tests; scan->line != NULL; scan++) { | |
line = scan->line; | |
line_end = line + strlen(line); | |
cl_git_fail(git_oid__parse(&oid, &line, line_end, scan->header)); | |
cl_assert(line == scan->line); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment