summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorVicent Marti <vicent@github.com>2014-01-27 15:35:39 -0800
committerVicent Marti <vicent@github.com>2014-01-27 15:35:39 -0800
commita1a9d0bd484edb26c579820190d8f5fda24276ef (patch)
tree81730a60f8589c592c5786c98be0b1408c2b75a2 /tests
parent93954245e081ff803028431c5da2c8a073512643 (diff)
parentdaebb598690c47600cf033be77acaad1ae8c4a70 (diff)
downloadlibgit2-a1a9d0bd484edb26c579820190d8f5fda24276ef.tar.gz
Merge pull request #2066 from libgit2/rb/builtin-diff-drivers
Add built in diff drivers
Diffstat (limited to 'tests')
-rw-r--r--tests/diff/blob.c8
-rw-r--r--tests/diff/drivers.c140
-rw-r--r--tests/resources/userdiff/.gitted/HEAD1
-rw-r--r--tests/resources/userdiff/.gitted/config7
-rw-r--r--tests/resources/userdiff/.gitted/description1
-rw-r--r--tests/resources/userdiff/.gitted/indexbin0 -> 1336 bytes
-rw-r--r--tests/resources/userdiff/.gitted/info/refs1
-rw-r--r--tests/resources/userdiff/.gitted/objects/info/packs2
-rw-r--r--tests/resources/userdiff/.gitted/objects/pack/pack-1652578900ac63564f2a24b9714529821276ceb9.idxbin0 -> 2500 bytes
-rw-r--r--tests/resources/userdiff/.gitted/objects/pack/pack-1652578900ac63564f2a24b9714529821276ceb9.packbin0 -> 7102 bytes
-rw-r--r--tests/resources/userdiff/.gitted/packed-refs2
-rw-r--r--tests/resources/userdiff/.gitted/refs/dummy-marker.txt0
-rw-r--r--tests/resources/userdiff/after/file.html41
-rw-r--r--tests/resources/userdiff/after/file.javascript108
-rw-r--r--tests/resources/userdiff/after/file.php50
-rw-r--r--tests/resources/userdiff/before/file.html41
-rw-r--r--tests/resources/userdiff/before/file.javascript109
-rw-r--r--tests/resources/userdiff/before/file.php49
-rw-r--r--tests/resources/userdiff/expected/driver/diff.html26
-rw-r--r--tests/resources/userdiff/expected/driver/diff.javascript40
-rw-r--r--tests/resources/userdiff/expected/driver/diff.php26
-rw-r--r--tests/resources/userdiff/expected/nodriver/diff.html26
-rw-r--r--tests/resources/userdiff/expected/nodriver/diff.javascript40
-rw-r--r--tests/resources/userdiff/expected/nodriver/diff.php26
-rw-r--r--tests/resources/userdiff/files/file.html41
-rw-r--r--tests/resources/userdiff/files/file.javascript108
-rw-r--r--tests/resources/userdiff/files/file.php50
27 files changed, 914 insertions, 29 deletions
diff --git a/tests/diff/blob.c b/tests/diff/blob.c
index 17f64c915..74df3cf85 100644
--- a/tests/diff/blob.c
+++ b/tests/diff/blob.c
@@ -861,15 +861,15 @@ void test_diff_blob__using_path_and_attributes(void)
cl_git_pass(git_config_set_bool(cfg, "diff.iam_binary.binary", 1));
cl_git_pass(git_config_set_bool(cfg, "diff.iam_text.binary", 0));
cl_git_pass(git_config_set_string(
- cfg, "diff.iam_alphactx.xfuncname", "^[A-Za-z]"));
+ cfg, "diff.iam_alphactx.xfuncname", "^[A-Za-z].*$"));
cl_git_pass(git_config_set_bool(cfg, "diff.iam_textalpha.binary", 0));
cl_git_pass(git_config_set_string(
- cfg, "diff.iam_textalpha.xfuncname", "^[A-Za-z]"));
+ cfg, "diff.iam_textalpha.xfuncname", "^[A-Za-z].*$"));
cl_git_pass(git_config_set_string(
- cfg, "diff.iam_numctx.funcname", "^[0-9]"));
+ cfg, "diff.iam_numctx.funcname", "^[0-9][0-9]*"));
cl_git_pass(git_config_set_bool(cfg, "diff.iam_textnum.binary", 0));
cl_git_pass(git_config_set_string(
- cfg, "diff.iam_textnum.funcname", "^[0-9]"));
+ cfg, "diff.iam_textnum.funcname", "^[0-9][0-9]*"));
git_config_free(cfg);
cl_git_append2file(
diff --git a/tests/diff/drivers.c b/tests/diff/drivers.c
index c80fad4c2..8b12368ea 100644
--- a/tests/diff/drivers.c
+++ b/tests/diff/drivers.c
@@ -15,6 +15,23 @@ void test_diff_drivers__cleanup(void)
g_repo = NULL;
}
+static void overwrite_filemode(const char *expected, git_buf *actual)
+{
+ size_t offset;
+ char *found;
+
+ found = strstr(expected, "100644");
+ if (!found)
+ return;
+
+ offset = ((const char *)found) - expected;
+ if (actual->size < offset + 6)
+ return;
+
+ if (memcmp(&actual->ptr[offset], "100644", 6) != 0)
+ memcpy(&actual->ptr[offset], "100644", 6);
+}
+
void test_diff_drivers__patterns(void)
{
git_config *cfg;
@@ -22,7 +39,7 @@ void test_diff_drivers__patterns(void)
git_tree *one;
git_diff *diff;
git_patch *patch;
- git_buf buf = GIT_BUF_INIT;
+ git_buf actual = GIT_BUF_INIT;
const char *expected0 = "diff --git a/untimely.txt b/untimely.txt\nindex 9a69d96..57fd0cf 100644\n--- a/untimely.txt\n+++ b/untimely.txt\n@@ -22,3 +22,5 @@ Comes through the blood of the vanguards who\n dreamed--too soon--it had sounded.\r\n \r\n -- Rudyard Kipling\r\n+\r\n+Some new stuff\r\n";
const char *expected1 = "diff --git a/untimely.txt b/untimely.txt\nindex 9a69d96..57fd0cf 100644\nBinary files a/untimely.txt and b/untimely.txt differ\n";
const char *expected2 = "diff --git a/untimely.txt b/untimely.txt\nindex 9a69d96..57fd0cf 100644\n--- a/untimely.txt\n+++ b/untimely.txt\n@@ -22,3 +22,5 @@ Heaven delivers on earth the Hour that cannot be\n dreamed--too soon--it had sounded.\r\n \r\n -- Rudyard Kipling\r\n+\r\n+Some new stuff\r\n";
@@ -45,10 +62,10 @@ void test_diff_drivers__patterns(void)
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
- cl_git_pass(git_patch_to_buf(&buf, patch));
- cl_assert_equal_s(expected0, buf.ptr);
+ cl_git_pass(git_patch_to_buf(&actual, patch));
+ cl_assert_equal_s(expected0, actual.ptr);
- git_buf_free(&buf);
+ git_buf_free(&actual);
git_patch_free(patch);
git_diff_free(diff);
@@ -60,10 +77,10 @@ void test_diff_drivers__patterns(void)
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
- cl_git_pass(git_patch_to_buf(&buf, patch));
- cl_assert_equal_s(expected1, buf.ptr);
+ cl_git_pass(git_patch_to_buf(&actual, patch));
+ cl_assert_equal_s(expected1, actual.ptr);
- git_buf_free(&buf);
+ git_buf_free(&actual);
git_patch_free(patch);
git_diff_free(diff);
@@ -75,10 +92,10 @@ void test_diff_drivers__patterns(void)
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
- cl_git_pass(git_patch_to_buf(&buf, patch));
- cl_assert_equal_s(expected0, buf.ptr);
+ cl_git_pass(git_patch_to_buf(&actual, patch));
+ cl_assert_equal_s(expected0, actual.ptr);
- git_buf_free(&buf);
+ git_buf_free(&actual);
git_patch_free(patch);
git_diff_free(diff);
@@ -92,10 +109,10 @@ void test_diff_drivers__patterns(void)
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
- cl_git_pass(git_patch_to_buf(&buf, patch));
- cl_assert_equal_s(expected1, buf.ptr);
+ cl_git_pass(git_patch_to_buf(&actual, patch));
+ cl_assert_equal_s(expected1, actual.ptr);
- git_buf_free(&buf);
+ git_buf_free(&actual);
git_patch_free(patch);
git_diff_free(diff);
@@ -106,17 +123,17 @@ void test_diff_drivers__patterns(void)
cl_git_pass(git_repository_config(&cfg, g_repo));
cl_git_pass(git_config_set_bool(cfg, "diff.kipling0.binary", 0));
- cl_git_pass(git_config_set_string(cfg, "diff.kipling0.xfuncname", "^H"));
+ cl_git_pass(git_config_set_string(cfg, "diff.kipling0.xfuncname", "^H.*$"));
git_config_free(cfg);
cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, one, NULL));
cl_assert_equal_i(1, (int)git_diff_num_deltas(diff));
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
- cl_git_pass(git_patch_to_buf(&buf, patch));
- cl_assert_equal_s(expected2, buf.ptr);
+ cl_git_pass(git_patch_to_buf(&actual, patch));
+ cl_assert_equal_s(expected2, actual.ptr);
- git_buf_free(&buf);
+ git_buf_free(&actual);
git_patch_free(patch);
git_diff_free(diff);
@@ -129,7 +146,7 @@ void test_diff_drivers__long_lines(void)
git_index *idx;
git_diff *diff;
git_patch *patch;
- git_buf buf = GIT_BUF_INIT;
+ git_buf actual = GIT_BUF_INIT;
const char *expected = "diff --git a/longlines.txt b/longlines.txt\nindex c1ce6ef..0134431 100644\n--- a/longlines.txt\n+++ b/longlines.txt\n@@ -3,3 +3,5 @@ Phasellus eget erat odio. Praesent at est iaculis, ultricies augue vel, dignissi\n Nam eget dolor fermentum, aliquet nisl at, convallis tellus. Pellentesque rhoncus erat enim, id porttitor elit euismod quis.\n Mauris sollicitudin magna odio, non egestas libero vehicula ut. Etiam et quam velit. Fusce eget libero rhoncus, ultricies felis sit amet, egestas purus.\n Aliquam in semper tellus. Pellentesque adipiscing rutrum velit, quis malesuada lacus consequat eget.\n+newline\n+newline\n";
g_repo = cl_git_sandbox_init("empty_standard_repo");
@@ -145,18 +162,91 @@ void test_diff_drivers__long_lines(void)
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, NULL));
cl_assert_equal_sz(1, git_diff_num_deltas(diff));
cl_git_pass(git_patch_from_diff(&patch, diff, 0));
- cl_git_pass(git_patch_to_buf(&buf, patch));
+ cl_git_pass(git_patch_to_buf(&actual, patch));
/* if chmod not supported, overwrite mode bits since anything is possible */
- if (!cl_is_chmod_supported()) {
- if (buf.size > 72 && memcmp(&buf.ptr[66], "100644", 6) != 0)
- memcpy(&buf.ptr[66], "100644", 6);
- }
+ overwrite_filemode(expected, &actual);
- cl_assert_equal_s(expected, buf.ptr);
+ cl_assert_equal_s(expected, actual.ptr);
- git_buf_free(&buf);
+ git_buf_free(&actual);
git_patch_free(patch);
git_diff_free(diff);
}
+void test_diff_drivers__builtins(void)
+{
+ git_diff *diff;
+ 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;
+ 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;
+
+ 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 */
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
+ cl_assert_equal_sz(1, git_diff_num_deltas(diff));
+ cl_git_pass(git_patch_from_diff(&patch, diff, 0));
+ cl_git_pass(git_patch_to_buf(&actual, patch));
+
+ git_buf_sets(&expected, "userdiff/expected/nodriver/diff.");
+ git_buf_puts(&expected, extension);
+ cl_git_pass(git_futils_readbuffer(&expected, expected.ptr));
+
+ overwrite_filemode(expected.ptr, &actual);
+
+ cl_assert_equal_s(expected.ptr, actual.ptr);
+
+ git_buf_clear(&actual);
+ git_patch_free(patch);
+ git_diff_free(diff);
+
+ /* do diff with driver */
+
+ {
+ FILE *fp = fopen("userdiff/.gitattributes", "w");
+ fprintf(fp, "*.%s diff=%s\n", extension, extension);
+ fclose(fp);
+ }
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts));
+ cl_assert_equal_sz(1, git_diff_num_deltas(diff));
+ cl_git_pass(git_patch_from_diff(&patch, diff, 0));
+ cl_git_pass(git_patch_to_buf(&actual, patch));
+
+ git_buf_sets(&expected, "userdiff/expected/driver/diff.");
+ git_buf_puts(&expected, extension);
+ cl_git_pass(git_futils_readbuffer(&expected, expected.ptr));
+
+ overwrite_filemode(expected.ptr, &actual);
+
+ cl_assert_equal_s(expected.ptr, actual.ptr);
+
+ 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);
+}
diff --git a/tests/resources/userdiff/.gitted/HEAD b/tests/resources/userdiff/.gitted/HEAD
new file mode 100644
index 000000000..cb089cd89
--- /dev/null
+++ b/tests/resources/userdiff/.gitted/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests/resources/userdiff/.gitted/config b/tests/resources/userdiff/.gitted/config
new file mode 100644
index 000000000..6c9406b7d
--- /dev/null
+++ b/tests/resources/userdiff/.gitted/config
@@ -0,0 +1,7 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
+ precomposeunicode = true
diff --git a/tests/resources/userdiff/.gitted/description b/tests/resources/userdiff/.gitted/description
new file mode 100644
index 000000000..498b267a8
--- /dev/null
+++ b/tests/resources/userdiff/.gitted/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
diff --git a/tests/resources/userdiff/.gitted/index b/tests/resources/userdiff/.gitted/index
new file mode 100644
index 000000000..b69d5cfb1
--- /dev/null
+++ b/tests/resources/userdiff/.gitted/index
Binary files differ
diff --git a/tests/resources/userdiff/.gitted/info/refs b/tests/resources/userdiff/.gitted/info/refs
new file mode 100644
index 000000000..b0743141d
--- /dev/null
+++ b/tests/resources/userdiff/.gitted/info/refs
@@ -0,0 +1 @@
+60e3f7b244a5305e2c9fa4ef0e897f3b14f3b8dd refs/heads/master
diff --git a/tests/resources/userdiff/.gitted/objects/info/packs b/tests/resources/userdiff/.gitted/objects/info/packs
new file mode 100644
index 000000000..0c5fc2a30
--- /dev/null
+++ b/tests/resources/userdiff/.gitted/objects/info/packs
@@ -0,0 +1,2 @@
+P pack-1652578900ac63564f2a24b9714529821276ceb9.pack
+
diff --git a/tests/resources/userdiff/.gitted/objects/pack/pack-1652578900ac63564f2a24b9714529821276ceb9.idx b/tests/resources/userdiff/.gitted/objects/pack/pack-1652578900ac63564f2a24b9714529821276ceb9.idx
new file mode 100644
index 000000000..6f4381cc7
--- /dev/null
+++ b/tests/resources/userdiff/.gitted/objects/pack/pack-1652578900ac63564f2a24b9714529821276ceb9.idx
Binary files differ
diff --git a/tests/resources/userdiff/.gitted/objects/pack/pack-1652578900ac63564f2a24b9714529821276ceb9.pack b/tests/resources/userdiff/.gitted/objects/pack/pack-1652578900ac63564f2a24b9714529821276ceb9.pack
new file mode 100644
index 000000000..39bd1d8f0
--- /dev/null
+++ b/tests/resources/userdiff/.gitted/objects/pack/pack-1652578900ac63564f2a24b9714529821276ceb9.pack
Binary files differ
diff --git a/tests/resources/userdiff/.gitted/packed-refs b/tests/resources/userdiff/.gitted/packed-refs
new file mode 100644
index 000000000..802f67ce0
--- /dev/null
+++ b/tests/resources/userdiff/.gitted/packed-refs
@@ -0,0 +1,2 @@
+# pack-refs with: peeled fully-peeled
+60e3f7b244a5305e2c9fa4ef0e897f3b14f3b8dd refs/heads/master
diff --git a/tests/resources/userdiff/.gitted/refs/dummy-marker.txt b/tests/resources/userdiff/.gitted/refs/dummy-marker.txt
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/resources/userdiff/.gitted/refs/dummy-marker.txt
diff --git a/tests/resources/userdiff/after/file.html b/tests/resources/userdiff/after/file.html
new file mode 100644
index 000000000..2320e2f1e
--- /dev/null
+++ b/tests/resources/userdiff/after/file.html
@@ -0,0 +1,41 @@
+<html>
+<body>
+ <h1 id="first section">
+ <ol>
+ <li>item 1.1</li>
+ <li>item 1.2 changed</li>
+ <li>item 1.3 changed</li>
+ <li>item 1.4</li>
+ <li>item 1.5</li>
+ <li>item 1.6</li>
+ <li>item 1.7</li>
+ <li>item 1.8</li>
+ <li>item 1.9</li>
+ <li>item 1.10 added</li>
+ </ol>
+ </h1>
+ <h1 id="second section">
+ <ol>
+ <li>item 2.1</li>
+ <li>item 2.2</li>
+ <li>item 2.3</li>
+ <li>item 2.4</li>
+ <li>item 2.5</li>
+ <li>item 2.6</li>
+ <li>item 2.7 changed</li>
+ <li>item 2.7.1 added</li>
+ <li>item 2.8</li>
+ </ol>
+ </h1>
+ <h1 id="third section">
+ <ol>
+ <li>item 3.1</li>
+ <li>item 3.2</li>
+ <li>item 3.3</li>
+ <li>item 3.4</li>
+ <li>item 3.5</li>
+ <li>item 3.6</li>
+ </ol>
+ </h1>
+</body>
+</html>
diff --git a/tests/resources/userdiff/after/file.javascript b/tests/resources/userdiff/after/file.javascript
new file mode 100644
index 000000000..7cd3c5a8a
--- /dev/null
+++ b/tests/resources/userdiff/after/file.javascript
@@ -0,0 +1,108 @@
+/*
+ Some code extracted from https://github.com/julianlloyd/scrollReveal.js
+ which happens to be a trending Javascript repo with an MIT license at
+ the time I was working on Javascript userdiff support in libgit2
+
+ I extracted just some of the code, so I suspect this is no longer valid
+ Javascript code, but it contains enough example patterns to work.
+*/
+;(function (window) {
+
+ 'use strict';
+
+ var docElem = window.document.documentElement;
+
+ function getViewportH () {
+ var client = docElem['clientHeight'],
+ inner = window['innerHeight'],
+ sample = window['otherProperty'];
+
+ return (client < inner) ? inner : client;
+ }
+
+ function getOffset (el) {
+ var offsetTop = 0,
+ offsetLeft = 0;
+
+ do {
+ if (!isNaN(el.offsetTop)) {
+ offsetTop += el.offsetTop + 1;
+ }
+ if (!isNaN(el.offsetLeft)) {
+ offsetLeft += el.offsetLeft;
+ }
+ } while (el = el.offsetParent)
+
+ return {
+ top: offsetTop,
+ left: offsetLeft
+ }
+ }
+
+ function isElementInViewport (el, h) {
+ var scrolled = window.pageYOffset,
+ viewed = scrolled + getViewportH(),
+ elTop = getOffset(el).top,
+ elBottom = elTop + el.offsetHeight,
+ h = h || 0;
+
+ return (elTop + el.offsetHeight * h) <= viewed && (elBottom) >= scrolled;
+ }
+
+ scrollReveal.prototype = {
+
+ _init: function () {
+
+ var self = this;
+
+ this.elems = Array.prototype.slice.call(docElem.querySelectorAll('[data-scrollReveal]'));
+ this.scrolled = false;
+
+ this.elems.forEach(function (el, i) {
+ self.animate(el);
+ });
+
+ var scrollHandler = function () {
+ if (!self.scrolled) {
+ self.scrolled = true;
+ setTimeout(function () {
+ self._scrollPage();
+ }, 61);
+ }
+ };
+
+ var resizeHandler = function () {
+ function delayed() {
+ self._scrollPage();
+ self.resizeTimeout = null;
+ }
+ if (self.resizeTimeout) {
+ clearTimeout(self.resizeTimeout);
+ }
+ self.resizeTimeout = setTimeout(delayed, 200);
+ };
+
+ window.addEventListener('scroll', scrollHandler, false);
+ window.addEventListener('resize', resizeHandler, false);
+ },
+
+ /*=============================================================================*/
+
+ _scrollPage: function () {
+ var self = this;
+
+ this.elems.forEach(function (el, i) {
+ if (isElementInViewport(el, self.options.viewportFactor)) {
+ self.animate(el);
+ }
+ });
+ this.scrolled = false;
+ this.tested = true;
+ },
+ }; // end scrollReveal.prototype
+
+ document.addEventListener("DOMContentLoaded", function (evt) {
+ window.scrollReveal = new scrollReveal();
+ });
+
+})(window);
diff --git a/tests/resources/userdiff/after/file.php b/tests/resources/userdiff/after/file.php
new file mode 100644
index 000000000..967d6466c
--- /dev/null
+++ b/tests/resources/userdiff/after/file.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace Faker;
+
+/**
+ * Proxy for other generators, to return only unique values. Works with
+ * Faker\Generator\Base->unique()
+ */
+class UniqueGenerator
+{
+ protected $generator;
+ protected $maxRetries;
+ protected $moreStuff;
+ protected $uniques = array();
+
+ public function __construct(Generator $generator, $maxRetries)
+ {
+ $this->generator = $generator;
+ $this->maxRetries = $maxRetries + 1;
+ }
+
+ /**
+ * Catch and proxy all generator calls but return only unique values
+ */
+ public function __get($attribute)
+ {
+ return $this->__call($attribute, array());
+ }
+
+ /**
+ * Catch and proxy all generator calls with arguments but return only unique values
+ */
+ public function __call($name, $arguments)
+ {
+ $i = 0;
+ if (!isset($this->uniques[$name])) {
+ $this->uniques[$name] = array();
+ }
+ do {
+ $res = call_user_func_array(array($this->generator, $name), $arguments);
+ $i++;
+ if ($i >= $this->maxRetries) {
+ throw new \OverflowException(sprintf('Maximum retries of %d reached without finding a unique value', $this->maxRetries));
+ }
+ } while (in_array($res, $this->uniques[$name]));
+ $this->uniques[$name][]= $res;
+
+ return $res;
+ }
+}
diff --git a/tests/resources/userdiff/before/file.html b/tests/resources/userdiff/before/file.html
new file mode 100644
index 000000000..872d19663
--- /dev/null
+++ b/tests/resources/userdiff/before/file.html
@@ -0,0 +1,41 @@
+<html>
+<body>
+ <h1 id="first section">
+ <ol>
+ <li>item 1.1</li>
+ <li>item 1.2</li>
+ <li>item 1.3</li>
+ <li>item 1.4</li>
+ <li>item 1.5</li>
+ <li>item 1.6</li>
+ <li>item 1.7</li>
+ <li>item 1.8</li>
+ <li>item 1.9</li>
+ </ol>
+ </h1>
+ <h1 id="second section">
+ <ol>
+ <li>item 2.1</li>
+ <li>item 2.2</li>
+ <li>item 2.3</li>
+ <li>item 2.4</li>
+ <li>item 2.5</li>
+ <li>item 2.6</li>
+ <li>item 2.7</li>
+ <li>item 2.8</li>
+ </ol>
+ </h1>
+ <h1 id="third section">
+ <ol>
+ <li>item 3.1</li>
+ <li>item 3.2</li>
+ <li>item 3.3</li>
+ <li>item 3.4</li>
+ <li>item 3.5</li>
+ <li>item 3.6</li>
+ <li>item 3.7</li>
+ <li>item 3.8</li>
+ </ol>
+ </h1>
+</body>
+</html>
diff --git a/tests/resources/userdiff/before/file.javascript b/tests/resources/userdiff/before/file.javascript
new file mode 100644
index 000000000..b9f1286e5
--- /dev/null
+++ b/tests/resources/userdiff/before/file.javascript
@@ -0,0 +1,109 @@
+/*
+ Some code extracted from https://github.com/julianlloyd/scrollReveal.js
+ which happens to be a trending Javascript repo with an MIT license at
+ the time I was working on Javascript userdiff support in libgit2
+
+ I extracted just some of the code, so I suspect this is no longer valid
+ Javascript code, but it contains enough example patterns to work.
+*/
+;(function (window) {
+
+ 'use strict';
+
+ var docElem = window.document.documentElement;
+
+ function getViewportH () {
+ var client = docElem['clientHeight'],
+ inner = window['innerHeight'];
+
+ return (client < inner) ? inner : client;
+ }
+
+ function getOffset (el) {
+ var offsetTop = 0,
+ offsetLeft = 0;
+
+ do {
+ if (!isNaN(el.offsetTop)) {
+ offsetTop += el.offsetTop;
+ }
+ if (!isNaN(el.offsetLeft)) {
+ offsetLeft += el.offsetLeft;
+ }
+ } while (el = el.offsetParent)
+
+ return {
+ top: offsetTop,
+ left: offsetLeft
+ }
+ }
+
+ function isElementInViewport (el, h) {
+ var scrolled = window.pageYOffset,
+ viewed = scrolled + getViewportH(),
+ elH = el.offsetHeight,
+ elTop = getOffset(el).top,
+ elBottom = elTop + elH,
+ h = h || 0;
+
+ return (elTop + elH * h) <= viewed && (elBottom) >= scrolled;
+ }
+
+ scrollReveal.prototype = {
+
+ _init: function () {
+
+ var self = this;
+
+ this.elems = Array.prototype.slice.call(docElem.querySelectorAll('[data-scrollReveal]'));
+ this.scrolled = false;
+
+ // Initialize all scrollreveals, triggering all
+ // reveals on visible elements.
+ this.elems.forEach(function (el, i) {
+ self.animate(el);
+ });
+
+ var scrollHandler = function () {
+ if (!self.scrolled) {
+ self.scrolled = true;
+ setTimeout(function () {
+ self._scrollPage();
+ }, 60);
+ }
+ };
+
+ var resizeHandler = function () {
+ function delayed() {
+ self._scrollPage();
+ self.resizeTimeout = null;
+ }
+ if (self.resizeTimeout) {
+ clearTimeout(self.resizeTimeout);
+ }
+ self.resizeTimeout = setTimeout(delayed, 200);
+ };
+
+ window.addEventListener('scroll', scrollHandler, false);
+ window.addEventListener('resize', resizeHandler, false);
+ },
+
+ /*=============================================================================*/
+
+ _scrollPage: function () {
+ var self = this;
+
+ this.elems.forEach(function (el, i) {
+ if (isElementInViewport(el, self.options.viewportFactor)) {
+ self.animate(el);
+ }
+ });
+ this.scrolled = false;
+ },
+ }; // end scrollReveal.prototype
+
+ document.addEventListener("DOMContentLoaded", function (evt) {
+ window.scrollReveal = new scrollReveal();
+ });
+
+})(window);
diff --git a/tests/resources/userdiff/before/file.php b/tests/resources/userdiff/before/file.php
new file mode 100644
index 000000000..63250ad01
--- /dev/null
+++ b/tests/resources/userdiff/before/file.php
@@ -0,0 +1,49 @@
+<?php
+
+namespace Faker;
+
+/**
+ * Proxy for other generators, to return only unique values. Works with
+ * Faker\Generator\Base->unique()
+ */
+class UniqueGenerator
+{
+ protected $generator;
+ protected $maxRetries;
+ protected $uniques = array();
+
+ public function __construct(Generator $generator, $maxRetries)
+ {
+ $this->generator = $generator;
+ $this->maxRetries = $maxRetries;
+ }
+
+ /**
+ * Catch and proxy all generator calls but return only unique values
+ */
+ public function __get($attribute)
+ {
+ return $this->__call($attribute, array());
+ }
+
+ /**
+ * Catch and proxy all generator calls with arguments but return only unique values
+ */
+ public function __call($name, $arguments)
+ {
+ if (!isset($this->uniques[$name])) {
+ $this->uniques[$name] = array();
+ }
+ $i = 0;
+ do {
+ $res = call_user_func_array(array($this->generator, $name), $arguments);
+ $i++;
+ if ($i > $this->maxRetries) {
+ throw new \OverflowException(sprintf('Maximum retries of %d reached without finding a unique value', $this->maxRetries));
+ }
+ } while (in_array($res, $this->uniques[$name]));
+ $this->uniques[$name][]= $res;
+
+ return $res;
+ }
+}
diff --git a/tests/resources/userdiff/expected/driver/diff.html b/tests/resources/userdiff/expected/driver/diff.html
new file mode 100644
index 000000000..5a428e7dc
--- /dev/null
+++ b/tests/resources/userdiff/expected/driver/diff.html
@@ -0,0 +1,26 @@
+diff --git a/files/file.html b/files/file.html
+index 872d196..2320e2f 100644
+--- a/files/file.html
++++ b/files/file.html
+@@ -5,4 +5,4 @@ <h1 id="first section">
+ <li>item 1.1</li>
+- <li>item 1.2</li>
+- <li>item 1.3</li>
++ <li>item 1.2 changed</li>
++ <li>item 1.3 changed</li>
+ <li>item 1.4</li>
+@@ -13,2 +13,3 @@ <h1 id="first section">
+ <li>item 1.9</li>
++ <li>item 1.10 added</li>
+ </ol>
+@@ -23,3 +24,4 @@ <h1 id="second section">
+ <li>item 2.6</li>
+- <li>item 2.7</li>
++ <li>item 2.7 changed</li>
++ <li>item 2.7.1 added</li>
+ <li>item 2.8</li>
+@@ -35,4 +37,2 @@ <h1 id="third section">
+ <li>item 3.6</li>
+- <li>item 3.7</li>
+- <li>item 3.8</li>
+ </ol>
diff --git a/tests/resources/userdiff/expected/driver/diff.javascript b/tests/resources/userdiff/expected/driver/diff.javascript
new file mode 100644
index 000000000..4e65d0746
--- /dev/null
+++ b/tests/resources/userdiff/expected/driver/diff.javascript
@@ -0,0 +1,40 @@
+diff --git a/files/file.javascript b/files/file.javascript
+index b9f1286..7cd3c5a 100644
+--- a/files/file.javascript
++++ b/files/file.javascript
+@@ -16,3 +16,4 @@ function getViewportH ()
+ var client = docElem['clientHeight'],
+- inner = window['innerHeight'];
++ inner = window['innerHeight'],
++ sample = window['otherProperty'];
+
+@@ -27,3 +28,3 @@ function getOffset (el)
+ if (!isNaN(el.offsetTop)) {
+- offsetTop += el.offsetTop;
++ offsetTop += el.offsetTop + 1;
+ }
+@@ -43,8 +44,7 @@ function isElementInViewport (el, h)
+ viewed = scrolled + getViewportH(),
+- elH = el.offsetHeight,
+ elTop = getOffset(el).top,
+- elBottom = elTop + elH,
++ elBottom = elTop + el.offsetHeight,
+ h = h || 0;
+
+- return (elTop + elH * h) <= viewed && (elBottom) >= scrolled;
++ return (elTop + el.offsetHeight * h) <= viewed && (elBottom) >= scrolled;
+ }
+@@ -60,4 +60,2 @@ _init: function ()
+
+- // Initialize all scrollreveals, triggering all
+- // reveals on visible elements.
+ this.elems.forEach(function (el, i) {
+@@ -71,3 +69,3 @@ var scrollHandler = function ()
+ self._scrollPage();
+- }, 60);
++ }, 61);
+ }
+@@ -101,2 +99,3 @@ _scrollPage: function ()
+ this.scrolled = false;
++ this.tested = true;
+ },
diff --git a/tests/resources/userdiff/expected/driver/diff.php b/tests/resources/userdiff/expected/driver/diff.php
new file mode 100644
index 000000000..9711b5b3e
--- /dev/null
+++ b/tests/resources/userdiff/expected/driver/diff.php
@@ -0,0 +1,26 @@
+diff --git a/files/file.php b/files/file.php
+index 63250ad..967d646 100644
+--- a/files/file.php
++++ b/files/file.php
+@@ -12,2 +12,3 @@ class UniqueGenerator
+ protected $maxRetries;
++ protected $moreStuff;
+ protected $uniques = array();
+@@ -17,3 +18,3 @@ public function __construct(Generator $generator, $maxRetries)
+ $this->generator = $generator;
+- $this->maxRetries = $maxRetries;
++ $this->maxRetries = $maxRetries + 1;
+ }
+@@ -33,10 +34,10 @@ public function __call($name, $arguments)
+ {
++ $i = 0;
+ if (!isset($this->uniques[$name])) {
+ $this->uniques[$name] = array();
+ }
+- $i = 0;
+ do {
+ $res = call_user_func_array(array($this->generator, $name), $arguments);
+ $i++;
+- if ($i > $this->maxRetries) {
++ if ($i >= $this->maxRetries) {
+ throw new \OverflowException(sprintf('Maximum retries of %d reached without finding a unique value', $this->maxRetries));
diff --git a/tests/resources/userdiff/expected/nodriver/diff.html b/tests/resources/userdiff/expected/nodriver/diff.html
new file mode 100644
index 000000000..2ea4b8a16
--- /dev/null
+++ b/tests/resources/userdiff/expected/nodriver/diff.html
@@ -0,0 +1,26 @@
+diff --git a/files/file.html b/files/file.html
+index 872d196..2320e2f 100644
+--- a/files/file.html
++++ b/files/file.html
+@@ -5,4 +5,4 @@
+ <li>item 1.1</li>
+- <li>item 1.2</li>
+- <li>item 1.3</li>
++ <li>item 1.2 changed</li>
++ <li>item 1.3 changed</li>
+ <li>item 1.4</li>
+@@ -13,2 +13,3 @@
+ <li>item 1.9</li>
++ <li>item 1.10 added</li>
+ </ol>
+@@ -23,3 +24,4 @@
+ <li>item 2.6</li>
+- <li>item 2.7</li>
++ <li>item 2.7 changed</li>
++ <li>item 2.7.1 added</li>
+ <li>item 2.8</li>
+@@ -35,4 +37,2 @@
+ <li>item 3.6</li>
+- <li>item 3.7</li>
+- <li>item 3.8</li>
+ </ol>
diff --git a/tests/resources/userdiff/expected/nodriver/diff.javascript b/tests/resources/userdiff/expected/nodriver/diff.javascript
new file mode 100644
index 000000000..69afe4fd8
--- /dev/null
+++ b/tests/resources/userdiff/expected/nodriver/diff.javascript
@@ -0,0 +1,40 @@
+diff --git a/files/file.javascript b/files/file.javascript
+index b9f1286..7cd3c5a 100644
+--- a/files/file.javascript
++++ b/files/file.javascript
+@@ -16,3 +16,4 @@
+ var client = docElem['clientHeight'],
+- inner = window['innerHeight'];
++ inner = window['innerHeight'],
++ sample = window['otherProperty'];
+
+@@ -27,3 +28,3 @@
+ if (!isNaN(el.offsetTop)) {
+- offsetTop += el.offsetTop;
++ offsetTop += el.offsetTop + 1;
+ }
+@@ -43,8 +44,7 @@
+ viewed = scrolled + getViewportH(),
+- elH = el.offsetHeight,
+ elTop = getOffset(el).top,
+- elBottom = elTop + elH,
++ elBottom = elTop + el.offsetHeight,
+ h = h || 0;
+
+- return (elTop + elH * h) <= viewed && (elBottom) >= scrolled;
++ return (elTop + el.offsetHeight * h) <= viewed && (elBottom) >= scrolled;
+ }
+@@ -60,4 +60,2 @@
+
+- // Initialize all scrollreveals, triggering all
+- // reveals on visible elements.
+ this.elems.forEach(function (el, i) {
+@@ -71,3 +69,3 @@
+ self._scrollPage();
+- }, 60);
++ }, 61);
+ }
+@@ -101,2 +99,3 @@
+ this.scrolled = false;
++ this.tested = true;
+ },
diff --git a/tests/resources/userdiff/expected/nodriver/diff.php b/tests/resources/userdiff/expected/nodriver/diff.php
new file mode 100644
index 000000000..e77c094aa
--- /dev/null
+++ b/tests/resources/userdiff/expected/nodriver/diff.php
@@ -0,0 +1,26 @@
+diff --git a/files/file.php b/files/file.php
+index 63250ad..967d646 100644
+--- a/files/file.php
++++ b/files/file.php
+@@ -12,2 +12,3 @@ class UniqueGenerator
+ protected $maxRetries;
++ protected $moreStuff;
+ protected $uniques = array();
+@@ -17,3 +18,3 @@ class UniqueGenerator
+ $this->generator = $generator;
+- $this->maxRetries = $maxRetries;
++ $this->maxRetries = $maxRetries + 1;
+ }
+@@ -33,10 +34,10 @@ class UniqueGenerator
+ {
++ $i = 0;
+ if (!isset($this->uniques[$name])) {
+ $this->uniques[$name] = array();
+ }
+- $i = 0;
+ do {
+ $res = call_user_func_array(array($this->generator, $name), $arguments);
+ $i++;
+- if ($i > $this->maxRetries) {
++ if ($i >= $this->maxRetries) {
+ throw new \OverflowException(sprintf('Maximum retries of %d reached without finding a unique value', $this->maxRetries));
diff --git a/tests/resources/userdiff/files/file.html b/tests/resources/userdiff/files/file.html
new file mode 100644
index 000000000..2320e2f1e
--- /dev/null
+++ b/tests/resources/userdiff/files/file.html
@@ -0,0 +1,41 @@
+<html>
+<body>
+ <h1 id="first section">
+ <ol>
+ <li>item 1.1</li>
+ <li>item 1.2 changed</li>
+ <li>item 1.3 changed</li>
+ <li>item 1.4</li>
+ <li>item 1.5</li>
+ <li>item 1.6</li>
+ <li>item 1.7</li>
+ <li>item 1.8</li>
+ <li>item 1.9</li>
+ <li>item 1.10 added</li>
+ </ol>
+ </h1>
+ <h1 id="second section">
+ <ol>
+ <li>item 2.1</li>
+ <li>item 2.2</li>
+ <li>item 2.3</li>
+ <li>item 2.4</li>
+ <li>item 2.5</li>
+ <li>item 2.6</li>
+ <li>item 2.7 changed</li>
+ <li>item 2.7.1 added</li>
+ <li>item 2.8</li>
+ </ol>
+ </h1>
+ <h1 id="third section">
+ <ol>
+ <li>item 3.1</li>
+ <li>item 3.2</li>
+ <li>item 3.3</li>
+ <li>item 3.4</li>
+ <li>item 3.5</li>
+ <li>item 3.6</li>
+ </ol>
+ </h1>
+</body>
+</html>
diff --git a/tests/resources/userdiff/files/file.javascript b/tests/resources/userdiff/files/file.javascript
new file mode 100644
index 000000000..7cd3c5a8a
--- /dev/null
+++ b/tests/resources/userdiff/files/file.javascript
@@ -0,0 +1,108 @@
+/*
+ Some code extracted from https://github.com/julianlloyd/scrollReveal.js
+ which happens to be a trending Javascript repo with an MIT license at
+ the time I was working on Javascript userdiff support in libgit2
+
+ I extracted just some of the code, so I suspect this is no longer valid
+ Javascript code, but it contains enough example patterns to work.
+*/
+;(function (window) {
+
+ 'use strict';
+
+ var docElem = window.document.documentElement;
+
+ function getViewportH () {
+ var client = docElem['clientHeight'],
+ inner = window['innerHeight'],
+ sample = window['otherProperty'];
+
+ return (client < inner) ? inner : client;
+ }
+
+ function getOffset (el) {
+ var offsetTop = 0,
+ offsetLeft = 0;
+
+ do {
+ if (!isNaN(el.offsetTop)) {
+ offsetTop += el.offsetTop + 1;
+ }
+ if (!isNaN(el.offsetLeft)) {
+ offsetLeft += el.offsetLeft;
+ }
+ } while (el = el.offsetParent)
+
+ return {
+ top: offsetTop,
+ left: offsetLeft
+ }
+ }
+
+ function isElementInViewport (el, h) {
+ var scrolled = window.pageYOffset,
+ viewed = scrolled + getViewportH(),
+ elTop = getOffset(el).top,
+ elBottom = elTop + el.offsetHeight,
+ h = h || 0;
+
+ return (elTop + el.offsetHeight * h) <= viewed && (elBottom) >= scrolled;
+ }
+
+ scrollReveal.prototype = {
+
+ _init: function () {
+
+ var self = this;
+
+ this.elems = Array.prototype.slice.call(docElem.querySelectorAll('[data-scrollReveal]'));
+ this.scrolled = false;
+
+ this.elems.forEach(function (el, i) {
+ self.animate(el);
+ });
+
+ var scrollHandler = function () {
+ if (!self.scrolled) {
+ self.scrolled = true;
+ setTimeout(function () {
+ self._scrollPage();
+ }, 61);
+ }
+ };
+
+ var resizeHandler = function () {
+ function delayed() {
+ self._scrollPage();
+ self.resizeTimeout = null;
+ }
+ if (self.resizeTimeout) {
+ clearTimeout(self.resizeTimeout);
+ }
+ self.resizeTimeout = setTimeout(delayed, 200);
+ };
+
+ window.addEventListener('scroll', scrollHandler, false);
+ window.addEventListener('resize', resizeHandler, false);
+ },
+
+ /*=============================================================================*/
+
+ _scrollPage: function () {
+ var self = this;
+
+ this.elems.forEach(function (el, i) {
+ if (isElementInViewport(el, self.options.viewportFactor)) {
+ self.animate(el);
+ }
+ });
+ this.scrolled = false;
+ this.tested = true;
+ },
+ }; // end scrollReveal.prototype
+
+ document.addEventListener("DOMContentLoaded", function (evt) {
+ window.scrollReveal = new scrollReveal();
+ });
+
+})(window);
diff --git a/tests/resources/userdiff/files/file.php b/tests/resources/userdiff/files/file.php
new file mode 100644
index 000000000..967d6466c
--- /dev/null
+++ b/tests/resources/userdiff/files/file.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace Faker;
+
+/**
+ * Proxy for other generators, to return only unique values. Works with
+ * Faker\Generator\Base->unique()
+ */
+class UniqueGenerator
+{
+ protected $generator;
+ protected $maxRetries;
+ protected $moreStuff;
+ protected $uniques = array();
+
+ public function __construct(Generator $generator, $maxRetries)
+ {
+ $this->generator = $generator;
+ $this->maxRetries = $maxRetries + 1;
+ }
+
+ /**
+ * Catch and proxy all generator calls but return only unique values
+ */
+ public function __get($attribute)
+ {
+ return $this->__call($attribute, array());
+ }
+
+ /**
+ * Catch and proxy all generator calls with arguments but return only unique values
+ */
+ public function __call($name, $arguments)
+ {
+ $i = 0;
+ if (!isset($this->uniques[$name])) {
+ $this->uniques[$name] = array();
+ }
+ do {
+ $res = call_user_func_array(array($this->generator, $name), $arguments);
+ $i++;
+ if ($i >= $this->maxRetries) {
+ throw new \OverflowException(sprintf('Maximum retries of %d reached without finding a unique value', $this->maxRetries));
+ }
+ } while (in_array($res, $this->uniques[$name]));
+ $this->uniques[$name][]= $res;
+
+ return $res;
+ }
+}