mirror of
https://git.proxmox.com/git/libgit2
synced 2026-01-04 03:14:41 +00:00
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.
This commit is contained in:
parent
4115987739
commit
082e82dba5
@ -437,6 +437,7 @@ static int diff_context_line__pattern_match(
|
||||
i = (pmatch[1].rm_so >= 0) ? 1 : 0;
|
||||
git_buf_consume(line, git_buf_cstr(line) + pmatch[i].rm_so);
|
||||
git_buf_truncate(line, pmatch[i].rm_eo - pmatch[i].rm_so);
|
||||
git_buf_rtrim(line);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -193,9 +193,9 @@ PATTERNS("php",
|
||||
"|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"),
|
||||
|
||||
PATTERNS("javascript",
|
||||
"^[ \t]*(\(?function[ \t].*)$\n"
|
||||
"^[ \t]*(var[ \t]+[a-zA-Z_][a-zA-Z0-9_]*[ \t]*=[ \t]*function[ \t\(].*)$\n"
|
||||
"^[ \t]*([a-zA-Z_][a-zA-Z0-9_]*[ \t]*:[ \t]*function[ \t\(].*)$",
|
||||
"^[ \t]*(function[ \t][a-zA-Z_][^\{]*)\n"
|
||||
"^[ \t]*(var[ \t]+[a-zA-Z_][a-zA-Z0-9_]*[ \t]*=[ \t]*function[ \t\(][^\{]*)\n"
|
||||
"^[ \t]*([a-zA-Z_][a-zA-Z0-9_]*[ \t]*:[ \t]*function[ \t\(][^\{]*)",
|
||||
/* -- */
|
||||
"[a-zA-Z_][a-zA-Z0-9_]*"
|
||||
"|[-+0-9.e]+[fFlL]?|0[xX]?[0-9a-fA-F]+[lL]?"
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Binary file not shown.
BIN
tests/resources/userdiff/.gitted/info/refs
Normal file
BIN
tests/resources/userdiff/.gitted/info/refs
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
tests/resources/userdiff/.gitted/objects/info/packs
Normal file
BIN
tests/resources/userdiff/.gitted/objects/info/packs
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
tests/resources/userdiff/.gitted/packed-refs
Normal file
BIN
tests/resources/userdiff/.gitted/packed-refs
Normal file
Binary file not shown.
Binary file not shown.
BIN
tests/resources/userdiff/after/file.javascript
Normal file
BIN
tests/resources/userdiff/after/file.javascript
Normal file
Binary file not shown.
BIN
tests/resources/userdiff/before/file.javascript
Normal file
BIN
tests/resources/userdiff/before/file.javascript
Normal file
Binary file not shown.
BIN
tests/resources/userdiff/expected/driver/diff.javascript
Normal file
BIN
tests/resources/userdiff/expected/driver/diff.javascript
Normal file
Binary file not shown.
BIN
tests/resources/userdiff/expected/nodriver/diff.javascript
Normal file
BIN
tests/resources/userdiff/expected/nodriver/diff.javascript
Normal file
Binary file not shown.
BIN
tests/resources/userdiff/files/file.javascript
Normal file
BIN
tests/resources/userdiff/files/file.javascript
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user