Add a bunch of tests

This commit is contained in:
Daniel Imms
2016-06-10 18:53:32 -07:00
parent 08928d8b8e
commit f2f0f460c4
3 changed files with 66 additions and 13 deletions
+17 -12
View File
@@ -91,22 +91,13 @@
continue;
}
var url = exports.findLinkMatch(node.data, lenient);
if (lenient) {
match = node.data.match(lenientUrlRegex);
} else {
match = node.data.match(strictUrlRegex);
}
/**
* If no URL was found in the current text, return.
*/
if (!match) {
if (!url) {
continue;
}
var url = match[1],
startsWithProtocol = new RegExp('^' + protocolClause),
var startsWithProtocol = new RegExp('^' + protocolClause),
urlHasProtocol = url.match(startsWithProtocol),
href = (urlHasProtocol) ? url : 'http://' + url,
link = '<a href="' + href + '" >' + url + '</a>',
@@ -125,6 +116,20 @@
terminal.emit('linkify:line', line);
};
/**
* Finds a link within a block of text.
*
* @param {string} text - The text to search .
* @param {boolean} lenient - Whether to use the lenient search.
* @return {string} A URL.
*/
exports.findLinkMatch = function (text, lenient) {
var match = text.match(lenient ? lenientUrlRegex : strictUrlRegex);
if (!match || match.length === 0) {
return null;
}
return match[1];
}
/**
* Converts all valid URLs found in the terminal view into hyperlinks.