Commit 082e82dba5b5174756b3a5fc2e385ccc59626164

Russell Belfer 2014-01-27T11:45:06

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
diff --git a/src/diff_driver.c b/src/diff_driver.c
index 9249d14..4c9a0af 100644
--- a/src/diff_driver.c
+++ b/src/diff_driver.c
@@ -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;
 		}
diff --git a/src/userdiff.h b/src/userdiff.h
index 93b4d0d..2257035 100644
--- a/src/userdiff.h
+++ b/src/userdiff.h
@@ -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]?"
diff --git a/tests/diff/drivers.c b/tests/diff/drivers.c
index 1cbf9e2..8b12368 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);
 }
diff --git a/tests/resources/userdiff/.gitted/index b/tests/resources/userdiff/.gitted/index
index 9372411..df041cf 100644
Binary files a/tests/resources/userdiff/.gitted/index and b/tests/resources/userdiff/.gitted/index differ
diff --git a/tests/resources/userdiff/.gitted/info/refs b/tests/resources/userdiff/.gitted/info/refs
new file mode 100644
index 0000000..261695f
--- /dev/null
+++ b/tests/resources/userdiff/.gitted/info/refs
@@ -0,0 +1 @@
+802734c801bffc466d69876bc4814f747aaac4fe	refs/heads/master
diff --git a/tests/resources/userdiff/.gitted/objects/05/d669073b39d36847315e3a5b4512cf4cba4546 b/tests/resources/userdiff/.gitted/objects/05/d669073b39d36847315e3a5b4512cf4cba4546
deleted file mode 100644
index 3a9d75c..0000000
Binary files a/tests/resources/userdiff/.gitted/objects/05/d669073b39d36847315e3a5b4512cf4cba4546 and /dev/null differ
diff --git a/tests/resources/userdiff/.gitted/objects/20/ab776b6ff3169fa0e5eff65df30d45187d22ba b/tests/resources/userdiff/.gitted/objects/20/ab776b6ff3169fa0e5eff65df30d45187d22ba
deleted file mode 100644
index 3d57061..0000000
Binary files a/tests/resources/userdiff/.gitted/objects/20/ab776b6ff3169fa0e5eff65df30d45187d22ba and /dev/null differ
diff --git a/tests/resources/userdiff/.gitted/objects/23/20e2f1e4d9e6201a8e15949a0c10a533fa51cd b/tests/resources/userdiff/.gitted/objects/23/20e2f1e4d9e6201a8e15949a0c10a533fa51cd
deleted file mode 100644
index 6dbcafe..0000000
Binary files a/tests/resources/userdiff/.gitted/objects/23/20e2f1e4d9e6201a8e15949a0c10a533fa51cd and /dev/null differ
diff --git a/tests/resources/userdiff/.gitted/objects/2e/a4b8a16d737c180dfdd2b119dec9501592326c b/tests/resources/userdiff/.gitted/objects/2e/a4b8a16d737c180dfdd2b119dec9501592326c
deleted file mode 100644
index e7d2fba..0000000
Binary files a/tests/resources/userdiff/.gitted/objects/2e/a4b8a16d737c180dfdd2b119dec9501592326c and /dev/null differ
diff --git a/tests/resources/userdiff/.gitted/objects/49/c0ff897b2b07a2ea0ed073e62a9dcd02704ba0 b/tests/resources/userdiff/.gitted/objects/49/c0ff897b2b07a2ea0ed073e62a9dcd02704ba0
deleted file mode 100644
index 49d59c1..0000000
Binary files a/tests/resources/userdiff/.gitted/objects/49/c0ff897b2b07a2ea0ed073e62a9dcd02704ba0 and /dev/null differ
diff --git a/tests/resources/userdiff/.gitted/objects/50/346bde7428a29c9845470a14d87b1634293d48 b/tests/resources/userdiff/.gitted/objects/50/346bde7428a29c9845470a14d87b1634293d48
deleted file mode 100644
index 9de1b35..0000000
--- a/tests/resources/userdiff/.gitted/objects/50/346bde7428a29c9845470a14d87b1634293d48
+++ /dev/null
@@ -1 +0,0 @@
-x+)JMU06g040031QHI(ahוL7rYMJ;8
\ No newline at end of file
diff --git a/tests/resources/userdiff/.gitted/objects/5a/428e7dcffb41b65984517f1e6b8547babc8dff b/tests/resources/userdiff/.gitted/objects/5a/428e7dcffb41b65984517f1e6b8547babc8dff
deleted file mode 100644
index 143a1ce..0000000
Binary files a/tests/resources/userdiff/.gitted/objects/5a/428e7dcffb41b65984517f1e6b8547babc8dff and /dev/null differ
diff --git a/tests/resources/userdiff/.gitted/objects/87/2d19663f32459389597b52beec6457c1dc971f b/tests/resources/userdiff/.gitted/objects/87/2d19663f32459389597b52beec6457c1dc971f
deleted file mode 100644
index 415f40a..0000000
Binary files a/tests/resources/userdiff/.gitted/objects/87/2d19663f32459389597b52beec6457c1dc971f and /dev/null differ
diff --git a/tests/resources/userdiff/.gitted/objects/9d/b1d09ff9ad5190bcf12d72ea3c818ffca344c5 b/tests/resources/userdiff/.gitted/objects/9d/b1d09ff9ad5190bcf12d72ea3c818ffca344c5
deleted file mode 100644
index c0a03a2..0000000
--- a/tests/resources/userdiff/.gitted/objects/9d/b1d09ff9ad5190bcf12d72ea3c818ffca344c5
+++ /dev/null
@@ -1,2 +0,0 @@
-xM F]sfJ+έ7g$P:_O{0,cN:VE
-gRҚJ(l6x㠜I9R[sO⭻lPf3b)^{d39
\ No newline at end of file
diff --git a/tests/resources/userdiff/.gitted/objects/d6/3c806de4f666369ed169495657bec24b558165 b/tests/resources/userdiff/.gitted/objects/d6/3c806de4f666369ed169495657bec24b558165
deleted file mode 100644
index 2c0fbcc..0000000
Binary files a/tests/resources/userdiff/.gitted/objects/d6/3c806de4f666369ed169495657bec24b558165 and /dev/null differ
diff --git a/tests/resources/userdiff/.gitted/objects/ef/1641511d6cb425c6b4f59ef1feffe7762e86e0 b/tests/resources/userdiff/.gitted/objects/ef/1641511d6cb425c6b4f59ef1feffe7762e86e0
deleted file mode 100644
index 223f3b3..0000000
--- a/tests/resources/userdiff/.gitted/objects/ef/1641511d6cb425c6b4f59ef1feffe7762e86e0
+++ /dev/null
@@ -1 +0,0 @@
-x+)JMU06g040031QHLK(ar=q[dK`\v=Mr
\ No newline at end of file
diff --git a/tests/resources/userdiff/.gitted/objects/info/packs b/tests/resources/userdiff/.gitted/objects/info/packs
new file mode 100644
index 0000000..6970fd7
--- /dev/null
+++ b/tests/resources/userdiff/.gitted/objects/info/packs
@@ -0,0 +1,2 @@
+P pack-03f78c35e3ca74fffd9d6c2b6dcd60d6ab6a614a.pack
+
diff --git a/tests/resources/userdiff/.gitted/objects/pack/pack-03f78c35e3ca74fffd9d6c2b6dcd60d6ab6a614a.idx b/tests/resources/userdiff/.gitted/objects/pack/pack-03f78c35e3ca74fffd9d6c2b6dcd60d6ab6a614a.idx
new file mode 100644
index 0000000..6d723f5
Binary files /dev/null and b/tests/resources/userdiff/.gitted/objects/pack/pack-03f78c35e3ca74fffd9d6c2b6dcd60d6ab6a614a.idx differ
diff --git a/tests/resources/userdiff/.gitted/objects/pack/pack-03f78c35e3ca74fffd9d6c2b6dcd60d6ab6a614a.pack b/tests/resources/userdiff/.gitted/objects/pack/pack-03f78c35e3ca74fffd9d6c2b6dcd60d6ab6a614a.pack
new file mode 100644
index 0000000..5b263e2
Binary files /dev/null and b/tests/resources/userdiff/.gitted/objects/pack/pack-03f78c35e3ca74fffd9d6c2b6dcd60d6ab6a614a.pack differ
diff --git a/tests/resources/userdiff/.gitted/packed-refs b/tests/resources/userdiff/.gitted/packed-refs
new file mode 100644
index 0000000..6d24ee4
--- /dev/null
+++ b/tests/resources/userdiff/.gitted/packed-refs
@@ -0,0 +1,2 @@
+# pack-refs with: peeled fully-peeled 
+802734c801bffc466d69876bc4814f747aaac4fe refs/heads/master
diff --git a/tests/resources/userdiff/.gitted/refs/heads/master b/tests/resources/userdiff/.gitted/refs/heads/master
deleted file mode 100644
index 2ec79ec..0000000
--- a/tests/resources/userdiff/.gitted/refs/heads/master
+++ /dev/null
@@ -1 +0,0 @@
-9db1d09ff9ad5190bcf12d72ea3c818ffca344c5
diff --git a/tests/resources/userdiff/after/file.javascript b/tests/resources/userdiff/after/file.javascript
new file mode 100644
index 0000000..7cd3c5a
--- /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/before/file.javascript b/tests/resources/userdiff/before/file.javascript
new file mode 100644
index 0000000..b9f1286
--- /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/expected/driver/diff.javascript b/tests/resources/userdiff/expected/driver/diff.javascript
new file mode 100644
index 0000000..4e65d07
--- /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/nodriver/diff.javascript b/tests/resources/userdiff/expected/nodriver/diff.javascript
new file mode 100644
index 0000000..69afe4f
--- /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/files/file.javascript b/tests/resources/userdiff/files/file.javascript
new file mode 100644
index 0000000..7cd3c5a
--- /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);