summaryrefslogtreecommitdiff
path: root/tests/diff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2014-01-27 11:45:06 -0800
committerRussell Belfer <rb@github.com>2014-01-27 11:45:06 -0800
commit082e82dba5b5174756b3a5fc2e385ccc59626164 (patch)
tree9191ea9e222c54163c275e1179600b02ebe264b2 /tests/diff
parent4115987739fb9cc4dd82edd9998db6dbb6bc9d95 (diff)
downloadlibgit2-082e82dba5b5174756b3a5fc2e385ccc59626164.tar.gz
Update Javascript userdiff driver and tests
Writing a sample Javascript driver pointed out some extra whitespace handling that needed to be done in the diff driver. This adds some tests with some sample javascript code that I pulled off of GitHub just to see what would happen. Also, to clean up the userdiff test data, I did a "git gc" and packed up the test objects.
Diffstat (limited to 'tests/diff')
-rw-r--r--tests/diff/drivers.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/tests/diff/drivers.c b/tests/diff/drivers.c
index 1cbf9e211..8b12368ea 100644
--- a/tests/diff/drivers.c
+++ b/tests/diff/drivers.c
@@ -180,22 +180,23 @@ void test_diff_drivers__builtins(void)
git_patch *patch;
git_buf file = GIT_BUF_INIT, actual = GIT_BUF_INIT, expected = GIT_BUF_INIT;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
- int i;
- static const char *files[] = {
- "html",
- NULL
- };
+ git_vector files = GIT_VECTOR_INIT;
+ size_t i;
+ char *path, *extension;
g_repo = cl_git_sandbox_init("userdiff");
+ cl_git_pass(git_path_dirload("userdiff/files", 9, 0, 0, &files));
+
opts.interhunk_lines = 1;
opts.context_lines = 1;
opts.pathspec.count = 1;
- for (i = 0; files[i]; ++i) {
- git_buf_sets(&file, "files/file.");
- git_buf_puts(&file, files[i]);
- opts.pathspec.strings = &file.ptr;
+ git_vector_foreach(&files, i, path) {
+ if (git__prefixcmp(path, "files/file."))
+ continue;
+ extension = path + strlen("files/file.");
+ opts.pathspec.strings = &path;
/* do diff with no special driver */
@@ -205,7 +206,7 @@ void test_diff_drivers__builtins(void)
cl_git_pass(git_patch_to_buf(&actual, patch));
git_buf_sets(&expected, "userdiff/expected/nodriver/diff.");
- git_buf_puts(&expected, files[i]);
+ git_buf_puts(&expected, extension);
cl_git_pass(git_futils_readbuffer(&expected, expected.ptr));
overwrite_filemode(expected.ptr, &actual);
@@ -220,7 +221,7 @@ void test_diff_drivers__builtins(void)
{
FILE *fp = fopen("userdiff/.gitattributes", "w");
- fprintf(fp, "*.%s diff=%s\n", files[i], files[i]);
+ fprintf(fp, "*.%s diff=%s\n", extension, extension);
fclose(fp);
}
@@ -230,7 +231,7 @@ void test_diff_drivers__builtins(void)
cl_git_pass(git_patch_to_buf(&actual, patch));
git_buf_sets(&expected, "userdiff/expected/driver/diff.");
- git_buf_puts(&expected, files[i]);
+ git_buf_puts(&expected, extension);
cl_git_pass(git_futils_readbuffer(&expected, expected.ptr));
overwrite_filemode(expected.ptr, &actual);
@@ -240,9 +241,12 @@ void test_diff_drivers__builtins(void)
git_buf_clear(&actual);
git_patch_free(patch);
git_diff_free(diff);
+
+ git__free(path);
}
git_buf_free(&file);
git_buf_free(&actual);
git_buf_free(&expected);
+ git_vector_free(&files);
}