Commit 533da4ea by Edward Thomson

Merge pull request #2473 from arthurschreiber/arthur/new-javascript-test-files

New test files for the javascript diff driver.
parents f339f441 994a3006
...@@ -191,9 +191,9 @@ PATTERNS("php", ...@@ -191,9 +191,9 @@ PATTERNS("php",
"|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"), "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"),
PATTERNS("javascript", PATTERNS("javascript",
"^[ \t]*(function[ \t][a-zA-Z_][^\\{]*)\n" "([a-zA-Z_$][a-zA-Z0-9_$]*(\\.[a-zA-Z0-9_$]+)*[ \t]*=[ \t]*function([ \t][a-zA-Z_$][a-zA-Z0-9_$]*)?[^\\{]*)\n"
"^[ \t]*(var[ \t]+[a-zA-Z_][a-zA-Z0-9_]*[ \t]*=[ \t]*function[ \t\\(][^\\{]*)\n" "([a-zA-Z_$][a-zA-Z0-9_$]*[ \t]*:[ \t]*function([ \t][a-zA-Z_$][a-zA-Z0-9_$]*)?[^\\{]*)\n"
"^[ \t]*([a-zA-Z_][a-zA-Z0-9_]*[ \t]*:[ \t]*function[ \t\\(][^\\{]*)", "[^a-zA-Z0-9_\\$](function([ \t][a-zA-Z_$][a-zA-Z0-9_$]*)?[^\\{]*)",
/* -- */ /* -- */
"[a-zA-Z_][a-zA-Z0-9_]*" "[a-zA-Z_][a-zA-Z0-9_]*"
"|[-+0-9.e]+[fFlL]?|0[xX]?[0-9a-fA-F]+[lL]?" "|[-+0-9.e]+[fFlL]?|0[xX]?[0-9a-fA-F]+[lL]?"
......
/* define(function(require, exports, module) {
Some code extracted from https://github.com/julianlloyd/scrollReveal.js module.exports = Player;
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 var Key = require("./key")
Javascript code, but it contains enough example patterns to work. , Direction = require("./direction");
*/
;(function (window) {
'use strict'; function Player(game) {
this.game = game;
var docElem = window.document.documentElement; this.image = new Image("./assets/fighter.png");
this.game.resources.add(this.image);
function getViewportH () { this.x = 0;
var client = docElem['clientHeight'], this.y = 0;
inner = window['innerHeight'],
sample = window['otherProperty'];
return (client < inner) ? inner : client; this.pixelX = 10;
} this.pixelY = 10;
function getOffset (el) {
var offsetTop = 0,
offsetLeft = 0;
do { this.animationStep = 0;
if (!isNaN(el.offsetTop)) {
offsetTop += el.offsetTop + 1;
}
if (!isNaN(el.offsetLeft)) {
offsetLeft += el.offsetLeft;
} }
} while (el = el.offsetParent)
return { Player.prototype.update = function() {
top: offsetTop, if (!this.isWalking()) {
left: offsetLeft this.handleInput();
}
} }
function isElementInViewport (el, h) { if (this.isWalking()) {
var scrolled = window.pageYOffset, // Increase the animation step.
viewed = scrolled + getViewportH(), this.animationStep = ++this.animationStep % 60;
elTop = getOffset(el).top,
elBottom = elTop + el.offsetHeight,
h = h || 0;
return (elTop + el.offsetHeight * h) <= viewed && (elBottom) >= scrolled; if (this.x * 32 > this.pixelX) {
this.pixelX++;
} else if (this.x * 32 < this.pixelX) {
this.pixelX--;
} }
scrollReveal.prototype = { if (this.y * 32 > this.pixelY) {
this.pixelY++;
_init: function () { } else if (this.y * 32 < this.pixelY) {
this.pixelY--;
}
} else {
// Reset the animation step.
this.animationStep = 0;
}
};
var self = this; Player.prototype.handleInput = function() {
var keyboard = this.game.keyboard, finalAction, action, inputs = {
'moveDown': keyboard.isDown(Key.DOWN),
'moveUp': keyboard.isDown(Key.UP),
'moveLeft': keyboard.isDown(Key.LEFT),
'moveRight': keyboard.isDown(Key.RIGHT)
};
this.elems = Array.prototype.slice.call(docElem.querySelectorAll('[data-scrollReveal]')); for (action in inputs) {
this.scrolled = false; if (inputs[action]) {
if (!finalAction || inputs[finalAction] < inputs[action]) {
finalAction = action;
}
}
}
this.elems.forEach(function (el, i) { this[finalAction] && this[finalAction]();
self.animate(el); };
});
var scrollHandler = function () { Player.prototype.isWalking = function() {
if (!self.scrolled) { return this.x * 32 != this.pixelX || this.y * 32 != this.pixelY;
self.scrolled = true;
setTimeout(function () {
self._scrollPage();
}, 61);
}
}; };
var resizeHandler = function () { Player.prototype.moveDown = function() {
function delayed() { this.y += 1;
self._scrollPage(); this.direction = Direction.DOWN;
self.resizeTimeout = null;
}
if (self.resizeTimeout) {
clearTimeout(self.resizeTimeout);
}
self.resizeTimeout = setTimeout(delayed, 200);
}; };
window.addEventListener('scroll', scrollHandler, false); Player.prototype.moveUp = function() {
window.addEventListener('resize', resizeHandler, false); this.y -= 1;
}, this.direction = Direction.UP;
};
/*=============================================================================*/ Player.prototype.moveLeft = function() {
this.x -= 5;
this.direction = Direction.LEFT;
};
_scrollPage: function () { Player.prototype.moveRight = function() {
var self = this; this.x += 1;
this.direction = Direction.RIGHT;
};
this.elems.forEach(function (el, i) { Player.prototype.draw = function(context) {
if (isElementInViewport(el, self.options.viewportFactor)) { var offsetX = Math.floor(this.animationStep / 15) * 32, offsetY = 0;
self.animate(el);
switch(this.direction) {
case Direction.UP:
offsetY = 48 * 3;
break;
case Direction.RIGHT:
offsetY = 48 * 2;
break;
case Direction.LEFT:
offsetY = 48;
break;
} }
});
this.scrolled = false;
this.tested = true;
},
}; // end scrollReveal.prototype
document.addEventListener("DOMContentLoaded", function (evt) { context.drawImage(this.image.data, offsetX, offsetY, 32, 48, this.pixelX, this.pixelY, 32, 48);
window.scrollReveal = new scrollReveal(); };
}); });
})(window);
/* define(function(require, exports, module) {
Some code extracted from https://github.com/julianlloyd/scrollReveal.js module.exports = Player;
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 var Key = require("./key")
Javascript code, but it contains enough example patterns to work. , Direction = require("./direction")
*/ , Image = require("./image");
;(function (window) {
'use strict'; function Player(game) {
this.game = game;
var docElem = window.document.documentElement; this.image = new Image("./assets/fighter.png");
this.game.resources.add(this.image);
function getViewportH () { this.x = 0;
var client = docElem['clientHeight'], this.y = 0;
inner = window['innerHeight'];
return (client < inner) ? inner : client; this.pixelX = 0;
} this.pixelY = 0;
function getOffset (el) {
var offsetTop = 0,
offsetLeft = 0;
do { this.animationStep = 0;
if (!isNaN(el.offsetTop)) {
offsetTop += el.offsetTop;
}
if (!isNaN(el.offsetLeft)) {
offsetLeft += el.offsetLeft;
} }
} while (el = el.offsetParent)
return { Player.prototype.update = function() {
top: offsetTop, if (!this.isWalking()) {
left: offsetLeft this.handleInput();
}
} }
function isElementInViewport (el, h) { if (this.isWalking()) {
var scrolled = window.pageYOffset, // Increase the animation step.
viewed = scrolled + getViewportH(), this.animationStep = ++this.animationStep % 60;
elH = el.offsetHeight,
elTop = getOffset(el).top,
elBottom = elTop + elH,
h = h || 0;
return (elTop + elH * h) <= viewed && (elBottom) >= scrolled; if (this.x * 32 > this.pixelX) {
this.pixelX++;
} else if (this.x * 32 < this.pixelX) {
this.pixelX--;
} }
scrollReveal.prototype = { if (this.y * 32 > this.pixelY) {
this.pixelY++;
_init: function () { } else if (this.y * 32 < this.pixelY) {
this.pixelY--;
}
} else {
// Reset the animation step.
this.animationStep = 0;
}
};
var self = this; Player.prototype.handleInput = function() {
var keyboard = this.game.keyboard, finalAction, action, inputs = {
'moveDown': keyboard.isDown(Key.DOWN),
'moveUp': keyboard.isDown(Key.UP),
'moveLeft': keyboard.isDown(Key.LEFT),
'moveRight': keyboard.isDown(Key.RIGHT)
};
this.elems = Array.prototype.slice.call(docElem.querySelectorAll('[data-scrollReveal]')); for (action in inputs) {
this.scrolled = false; if (inputs[action]) {
if (!finalAction || inputs[finalAction] < inputs[action]) {
finalAction = action;
}
}
}
// Initialize all scrollreveals, triggering all this[finalAction] && this[finalAction]();
// reveals on visible elements. };
this.elems.forEach(function (el, i) {
self.animate(el);
});
var scrollHandler = function () { Player.prototype.isWalking = function() {
if (!self.scrolled) { return this.x * 32 != this.pixelX || this.y * 32 != this.pixelY;
self.scrolled = true;
setTimeout(function () {
self._scrollPage();
}, 60);
}
}; };
var resizeHandler = function () { Player.prototype.moveDown = function() {
function delayed() { this.y += 1;
self._scrollPage(); this.direction = Direction.DOWN;
self.resizeTimeout = null;
}
if (self.resizeTimeout) {
clearTimeout(self.resizeTimeout);
}
self.resizeTimeout = setTimeout(delayed, 200);
}; };
window.addEventListener('scroll', scrollHandler, false); Player.prototype.moveUp = function() {
window.addEventListener('resize', resizeHandler, false); this.y -= 1;
}, this.direction = Direction.UP;
};
/*=============================================================================*/ Player.prototype.moveLeft = function() {
this.x -= 1;
this.direction = Direction.LEFT;
};
_scrollPage: function () { Player.prototype.moveRight = function() {
var self = this; this.x += 1;
this.direction = Direction.RIGHT;
};
this.elems.forEach(function (el, i) { Player.prototype.draw = function(context) {
if (isElementInViewport(el, self.options.viewportFactor)) { var offsetX = Math.floor(this.animationStep / 15) * 32, offsetY = 0;
self.animate(el);
switch(this.direction) {
case Direction.UP:
offsetY = 48 * 3;
break;
case Direction.RIGHT:
offsetY = 48 * 2;
break;
case Direction.LEFT:
offsetY = 48;
break;
} }
});
this.scrolled = false;
},
}; // end scrollReveal.prototype
document.addEventListener("DOMContentLoaded", function (evt) { context.drawImage(this.image.data, offsetX, offsetY, 32, 48, this.pixelX, this.pixelY - 16, 32, 48);
window.scrollReveal = new scrollReveal(); };
}); });
})(window);
diff --git a/files/file.javascript b/files/file.javascript diff --git a/files/file.javascript b/files/file.javascript
index b9f1286..7cd3c5a 100644 index 0965b37..5391797 100644
--- a/files/file.javascript --- a/files/file.javascript
+++ b/files/file.javascript +++ b/files/file.javascript
@@ -16,3 +16,4 @@ function getViewportH () @@ -4,4 +4,3 @@ function(require, exports, module)
var client = docElem['clientHeight'], var Key = require("./key")
- inner = window['innerHeight']; - , Direction = require("./direction")
+ inner = window['innerHeight'], - , Image = require("./image");
+ sample = window['otherProperty']; + , Direction = require("./direction");
@@ -27,3 +28,3 @@ function getOffset (el) @@ -16,4 +15,4 @@ function Player(game)
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; - this.pixelX = 0;
+ return (elTop + el.offsetHeight * h) <= viewed && (elBottom) >= scrolled; - this.pixelY = 0;
} + this.pixelX = 10;
@@ -60,4 +60,2 @@ _init: function () + this.pixelY = 10;
- // Initialize all scrollreveals, triggering all @@ -82,3 +81,3 @@ Player.prototype.moveUp = function()
- // reveals on visible elements. Player.prototype.moveLeft = function() {
this.elems.forEach(function (el, i) { - this.x -= 1;
@@ -71,3 +69,3 @@ var scrollHandler = function () + this.x -= 5;
self._scrollPage(); this.direction = Direction.LEFT;
- }, 60); @@ -106,3 +105,3 @@ Player.prototype.draw = function(context)
+ }, 61);
} - context.drawImage(this.image.data, offsetX, offsetY, 32, 48, this.pixelX, this.pixelY - 16, 32, 48);
@@ -101,2 +99,3 @@ _scrollPage: function () + context.drawImage(this.image.data, offsetX, offsetY, 32, 48, this.pixelX, this.pixelY, 32, 48);
this.scrolled = false; };
+ this.tested = true;
},
diff --git a/files/file.javascript b/files/file.javascript diff --git a/files/file.javascript b/files/file.javascript
index b9f1286..7cd3c5a 100644 index 0965b37..5391797 100644
--- a/files/file.javascript --- a/files/file.javascript
+++ b/files/file.javascript +++ b/files/file.javascript
@@ -16,3 +16,4 @@ @@ -4,4 +4,3 @@ define(function(require, exports, module) {
var client = docElem['clientHeight'], var Key = require("./key")
- inner = window['innerHeight']; - , Direction = require("./direction")
+ inner = window['innerHeight'], - , Image = require("./image");
+ sample = window['otherProperty']; + , Direction = require("./direction");
@@ -27,3 +28,3 @@ @@ -16,4 +15,4 @@ define(function(require, exports, module) {
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; - this.pixelX = 0;
+ return (elTop + el.offsetHeight * h) <= viewed && (elBottom) >= scrolled; - this.pixelY = 0;
} + this.pixelX = 10;
@@ -60,4 +60,2 @@ + this.pixelY = 10;
- // Initialize all scrollreveals, triggering all @@ -82,3 +81,3 @@ define(function(require, exports, module) {
- // reveals on visible elements. Player.prototype.moveLeft = function() {
this.elems.forEach(function (el, i) { - this.x -= 1;
@@ -71,3 +69,3 @@ + this.x -= 5;
self._scrollPage(); this.direction = Direction.LEFT;
- }, 60); @@ -106,3 +105,3 @@ define(function(require, exports, module) {
+ }, 61);
} - context.drawImage(this.image.data, offsetX, offsetY, 32, 48, this.pixelX, this.pixelY - 16, 32, 48);
@@ -101,2 +99,3 @@ + context.drawImage(this.image.data, offsetX, offsetY, 32, 48, this.pixelX, this.pixelY, 32, 48);
this.scrolled = false; };
+ this.tested = true;
},
/* define(function(require, exports, module) {
Some code extracted from https://github.com/julianlloyd/scrollReveal.js module.exports = Player;
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 var Key = require("./key")
Javascript code, but it contains enough example patterns to work. , Direction = require("./direction");
*/
;(function (window) {
'use strict'; function Player(game) {
this.game = game;
var docElem = window.document.documentElement; this.image = new Image("./assets/fighter.png");
this.game.resources.add(this.image);
function getViewportH () { this.x = 0;
var client = docElem['clientHeight'], this.y = 0;
inner = window['innerHeight'],
sample = window['otherProperty'];
return (client < inner) ? inner : client; this.pixelX = 10;
} this.pixelY = 10;
function getOffset (el) {
var offsetTop = 0,
offsetLeft = 0;
do { this.animationStep = 0;
if (!isNaN(el.offsetTop)) {
offsetTop += el.offsetTop + 1;
}
if (!isNaN(el.offsetLeft)) {
offsetLeft += el.offsetLeft;
} }
} while (el = el.offsetParent)
return { Player.prototype.update = function() {
top: offsetTop, if (!this.isWalking()) {
left: offsetLeft this.handleInput();
}
} }
function isElementInViewport (el, h) { if (this.isWalking()) {
var scrolled = window.pageYOffset, // Increase the animation step.
viewed = scrolled + getViewportH(), this.animationStep = ++this.animationStep % 60;
elTop = getOffset(el).top,
elBottom = elTop + el.offsetHeight,
h = h || 0;
return (elTop + el.offsetHeight * h) <= viewed && (elBottom) >= scrolled; if (this.x * 32 > this.pixelX) {
this.pixelX++;
} else if (this.x * 32 < this.pixelX) {
this.pixelX--;
} }
scrollReveal.prototype = { if (this.y * 32 > this.pixelY) {
this.pixelY++;
_init: function () { } else if (this.y * 32 < this.pixelY) {
this.pixelY--;
}
} else {
// Reset the animation step.
this.animationStep = 0;
}
};
var self = this; Player.prototype.handleInput = function() {
var keyboard = this.game.keyboard, finalAction, action, inputs = {
'moveDown': keyboard.isDown(Key.DOWN),
'moveUp': keyboard.isDown(Key.UP),
'moveLeft': keyboard.isDown(Key.LEFT),
'moveRight': keyboard.isDown(Key.RIGHT)
};
this.elems = Array.prototype.slice.call(docElem.querySelectorAll('[data-scrollReveal]')); for (action in inputs) {
this.scrolled = false; if (inputs[action]) {
if (!finalAction || inputs[finalAction] < inputs[action]) {
finalAction = action;
}
}
}
this.elems.forEach(function (el, i) { this[finalAction] && this[finalAction]();
self.animate(el); };
});
var scrollHandler = function () { Player.prototype.isWalking = function() {
if (!self.scrolled) { return this.x * 32 != this.pixelX || this.y * 32 != this.pixelY;
self.scrolled = true;
setTimeout(function () {
self._scrollPage();
}, 61);
}
}; };
var resizeHandler = function () { Player.prototype.moveDown = function() {
function delayed() { this.y += 1;
self._scrollPage(); this.direction = Direction.DOWN;
self.resizeTimeout = null;
}
if (self.resizeTimeout) {
clearTimeout(self.resizeTimeout);
}
self.resizeTimeout = setTimeout(delayed, 200);
}; };
window.addEventListener('scroll', scrollHandler, false); Player.prototype.moveUp = function() {
window.addEventListener('resize', resizeHandler, false); this.y -= 1;
}, this.direction = Direction.UP;
};
/*=============================================================================*/ Player.prototype.moveLeft = function() {
this.x -= 5;
this.direction = Direction.LEFT;
};
_scrollPage: function () { Player.prototype.moveRight = function() {
var self = this; this.x += 1;
this.direction = Direction.RIGHT;
};
this.elems.forEach(function (el, i) { Player.prototype.draw = function(context) {
if (isElementInViewport(el, self.options.viewportFactor)) { var offsetX = Math.floor(this.animationStep / 15) * 32, offsetY = 0;
self.animate(el);
switch(this.direction) {
case Direction.UP:
offsetY = 48 * 3;
break;
case Direction.RIGHT:
offsetY = 48 * 2;
break;
case Direction.LEFT:
offsetY = 48;
break;
} }
});
this.scrolled = false;
this.tested = true;
},
}; // end scrollReveal.prototype
document.addEventListener("DOMContentLoaded", function (evt) { context.drawImage(this.image.data, offsetX, offsetY, 32, 48, this.pixelX, this.pixelY, 32, 48);
window.scrollReveal = new scrollReveal(); };
}); });
})(window);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment