-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gists are either name/hex{32}, or just /hex{32}. If someone omits the project, and just specifies a name, then that is an error and should be treated as such. Also, eliminate some dead code paths and bring the tests up to 100%.
- Loading branch information
Showing
7 changed files
with
73 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,42 +3,43 @@ var HostedGit = require('../index') | |
var test = require('tap').test | ||
|
||
test('fromUrl(gist url)', function (t) { | ||
var proj = new Array(33).join('2') | ||
function verify (host, label, branch) { | ||
var hostinfo = HostedGit.fromUrl(host) | ||
var hash = branch ? '#' + branch : '' | ||
t.ok(hostinfo, label) | ||
if (!hostinfo) return | ||
t.is(hostinfo.https(), 'git+https://gist.github.com/222.git' + hash, label + ' -> https') | ||
t.is(hostinfo.git(), 'git://gist.github.com/222.git' + hash, label + ' -> git') | ||
t.is(hostinfo.browse(), 'https://gist.github.com/222' + (branch ? '/' + branch : ''), label + ' -> browse') | ||
t.is(hostinfo.browse('C'), 'https://gist.github.com/222' + (branch ? '/' + branch : '') + '#file-c', label + ' -> browse(path)') | ||
t.is(hostinfo.browse('C', 'A'), 'https://gist.github.com/222' + (branch ? '/' + branch : '') + '#file-c', label + ' -> browse(path, fragment)') | ||
t.is(hostinfo.bugs(), 'https://gist.github.com/222', label + ' -> bugs') | ||
t.is(hostinfo.docs(), 'https://gist.github.com/222' + (branch ? '/' + branch : ''), label + ' -> docs') | ||
t.is(hostinfo.ssh(), '[email protected]:/222.git' + hash, label + ' -> ssh') | ||
t.is(hostinfo.sshurl(), 'git+ssh://[email protected]/222.git' + hash, label + ' -> sshurl') | ||
t.is(hostinfo.shortcut(), 'gist:222' + hash, label + ' -> shortcut') | ||
t.is(hostinfo.https(), 'git+https://gist.github.com/' + proj + '.git' + hash, label + ' -> https') | ||
t.is(hostinfo.git(), 'git://gist.github.com/' + proj + '.git' + hash, label + ' -> git') | ||
t.is(hostinfo.browse(), 'https://gist.github.com/' + proj + (branch ? '/' + branch : ''), label + ' -> browse') | ||
t.is(hostinfo.browse('C'), 'https://gist.github.com/' + proj + (branch ? '/' + branch : '') + '#file-c', label + ' -> browse(path)') | ||
t.is(hostinfo.browse('C', 'A'), 'https://gist.github.com/' + proj + (branch ? '/' + branch : '') + '#file-c', label + ' -> browse(path, fragment)') | ||
t.is(hostinfo.bugs(), 'https://gist.github.com/' + proj, label + ' -> bugs') | ||
t.is(hostinfo.docs(), 'https://gist.github.com/' + proj + (branch ? '/' + branch : ''), label + ' -> docs') | ||
t.is(hostinfo.ssh(), '[email protected]:/' + proj + '.git' + hash, label + ' -> ssh') | ||
t.is(hostinfo.sshurl(), 'git+ssh://[email protected]/' + proj + '.git' + hash, label + ' -> sshurl') | ||
t.is(hostinfo.shortcut(), 'gist:' + proj + hash, label + ' -> shortcut') | ||
if (hostinfo.user) { | ||
t.is(hostinfo.file('C'), 'https://gist.githubusercontent.com/111/222/raw/' + (branch ? branch + '/' : '') + 'C', label + ' -> file') | ||
t.is(hostinfo.tarball(), 'https://gist.github.com/111/222/archive/' + (branch || 'master') + '.tar.gz', label + ' -> tarball') | ||
t.is(hostinfo.file('C'), 'https://gist.githubusercontent.com/111/' + proj + '/raw/' + (branch ? branch + '/' : '') + 'C', label + ' -> file') | ||
t.is(hostinfo.tarball(), 'https://gist.github.com/111/' + proj + '/archive/' + (branch || 'master') + '.tar.gz', label + ' -> tarball') | ||
} | ||
} | ||
|
||
verify('[email protected]:222.git', 'git@') | ||
var hostinfo = HostedGit.fromUrl('[email protected]:/ef860c7z5e0de3179341.git') | ||
verify('[email protected]:' + proj + '.git', 'git@') | ||
var hostinfo = HostedGit.fromUrl('[email protected]:/c2b12db30a49324325a3781302668408.git') | ||
if (t.ok(hostinfo, 'git@hex')) { | ||
t.is(hostinfo.https(), 'git+https://gist.github.com/ef860c7z5e0de3179341.git', 'git@hex -> https') | ||
t.is(hostinfo.https(), 'git+https://gist.github.com/c2b12db30a49324325a3781302668408.git', 'git@hex -> https') | ||
} | ||
verify('[email protected]:/222.git', 'git@/') | ||
verify('git://gist.github.com/222', 'git') | ||
verify('git://gist.github.com/222.git', 'git.git') | ||
verify('git://gist.github.com/222#branch', 'git#branch', 'branch') | ||
verify('git://gist.github.com/222.git#branch', 'git.git#branch', 'branch') | ||
verify('[email protected]:/' + proj + '.git', 'git@/') | ||
verify('git://gist.github.com/' + proj, 'git') | ||
verify('git://gist.github.com/' + proj + '.git', 'git.git') | ||
verify('git://gist.github.com/' + proj + '#branch', 'git#branch', 'branch') | ||
verify('git://gist.github.com/' + proj + '.git#branch', 'git.git#branch', 'branch') | ||
|
||
require('./lib/standard-tests')(verify, 'gist.github.com', 'gist') | ||
require('./lib/standard-tests')(verify, 'gist.github.com', 'gist', proj) | ||
|
||
verify(HostedGit.fromUrl('gist:111/222').toString(), 'round-tripped shortcut') | ||
verify('gist:222', 'shortened shortcut') | ||
verify(HostedGit.fromUrl('gist:111/' + proj).toString(), 'round-tripped shortcut') | ||
verify('gist:' + proj, 'shortened shortcut') | ||
|
||
t.end() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,17 +6,23 @@ test('fromUrl(github url)', function (t) { | |
function verify (host, label, branch) { | ||
var hostinfo = HostedGit.fromUrl(host) | ||
var hash = branch ? '#' + branch : '' | ||
var treebranch = branch ? '/tree/' + branch : '' | ||
t.equal(hostinfo._fill(), undefined) | ||
t.ok(hostinfo, label) | ||
if (!hostinfo) return | ||
t.is(hostinfo.https(), 'git+https://github.com/111/222.git' + hash, label + ' -> https') | ||
t.is(hostinfo.git(), 'git://github.com/111/222.git' + hash, label + ' -> git') | ||
t.is(hostinfo.browse(), 'https://github.com/111/222' + (branch ? '/tree/' + branch : ''), label + ' -> browse') | ||
t.is(hostinfo.browse(), 'https://github.com/111/222' + treebranch, label + ' -> browse') | ||
t.is(hostinfo.browse('C'), 'https://github.com/111/222/tree/' + (branch || 'master') + '/C', label + ' -> browse(path)') | ||
t.is(hostinfo.browse('C', 'A'), 'https://github.com/111/222/tree/' + (branch || 'master') + '/C#a', label + ' -> browse(path, fragment)') | ||
t.is(hostinfo.bugs(), 'https://github.com/111/222/issues', label + ' -> bugs') | ||
t.is(hostinfo.docs(), 'https://github.com/111/222' + (branch ? '/tree/' + branch : '') + '#readme', label + ' -> docs') | ||
t.is(hostinfo.docs(), 'https://github.com/111/222' + treebranch + '#readme', label + ' -> docs') | ||
t.is(hostinfo.ssh(), '[email protected]:111/222.git' + hash, label + ' -> ssh') | ||
t.is(hostinfo.sshurl(), 'git+ssh://[email protected]/111/222.git' + hash, label + ' -> sshurl') | ||
t.is(hostinfo.sshurl({ noGitPlus: true }), 'ssh://[email protected]/111/222.git' + hash, label + ' -> sshurl (no git plus)') | ||
t.is(hostinfo.path(), '111/222' + hash, ' -> path') | ||
t.is(hostinfo.hash(), hash, ' -> hash') | ||
t.is(hostinfo.path({ noCommittish: true }), '111/222', ' -> path (no committish)') | ||
t.is(hostinfo.shortcut(), 'github:111/222' + hash, label + ' -> shortcut') | ||
t.is(hostinfo.file('C'), 'https://raw.githubusercontent.com/111/222/' + (branch || 'master') + '/C', label + ' -> file') | ||
t.is(hostinfo.tarball(), 'https://codeload.github.com/111/222/tar.gz/' + (branch || 'master'), label + ' -> tarball') | ||
|
@@ -41,5 +47,7 @@ test('fromUrl(github url)', function (t) { | |
|
||
require('./lib/standard-tests')(verify, 'www.github.com', 'github') | ||
|
||
t.equal(HostedGit.fromUrl('git+ssh://github.com/foo.git'), undefined) | ||
|
||
t.end() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,28 @@ | ||
'use strict' | ||
module.exports = function (verify, domain, shortname) { | ||
verify('https://' + domain + '/111/222', 'https') | ||
verify('https://' + domain + '/111/222.git', 'https.git') | ||
verify('https://' + domain + '/111/222#branch', 'https#branch', 'branch') | ||
verify('https://' + domain + '/111/222.git#branch', 'https.git#branch', 'branch') | ||
module.exports = function (verify, domain, shortname, proj) { | ||
proj = proj || '222' | ||
verify('https://' + domain + '/111/' + proj, 'https') | ||
verify('https://' + domain + '/111/' + proj + '.git', 'https.git') | ||
verify('https://' + domain + '/111/' + proj + '#branch', 'https#branch', 'branch') | ||
verify('https://' + domain + '/111/' + proj + '.git#branch', 'https.git#branch', 'branch') | ||
|
||
verify('git+https://' + domain + '/111/222', 'git+https') | ||
verify('git+https://' + domain + '/111/222.git', 'git+https.git') | ||
verify('git+https://' + domain + '/111/222#branch', 'git+https#branch', 'branch') | ||
verify('git+https://' + domain + '/111/222.git#branch', 'git+https.git#branch', 'branch') | ||
verify('git+https://' + domain + '/111/' + proj, 'git+https') | ||
verify('git+https://' + domain + '/111/' + proj + '.git', 'git+https.git') | ||
verify('git+https://' + domain + '/111/' + proj + '#branch', 'git+https#branch', 'branch') | ||
verify('git+https://' + domain + '/111/' + proj + '.git#branch', 'git+https.git#branch', 'branch') | ||
|
||
verify('git@' + domain + ':111/222', 'ssh') | ||
verify('git@' + domain + ':111/222.git', 'ssh.git') | ||
verify('git@' + domain + ':111/222#branch', 'ssh', 'branch') | ||
verify('git@' + domain + ':111/222.git#branch', 'ssh.git', 'branch') | ||
verify('git@' + domain + ':111/' + proj, 'ssh') | ||
verify('git@' + domain + ':111/' + proj + '.git', 'ssh.git') | ||
verify('git@' + domain + ':111/' + proj + '#branch', 'ssh', 'branch') | ||
verify('git@' + domain + ':111/' + proj + '.git#branch', 'ssh.git', 'branch') | ||
|
||
verify('git+ssh://git@' + domain + '/111/222', 'ssh url') | ||
verify('git+ssh://git@' + domain + '/111/222.git', 'ssh url.git') | ||
verify('git+ssh://git@' + domain + '/111/222#branch', 'ssh url#branch', 'branch') | ||
verify('git+ssh://git@' + domain + '/111/222.git#branch', 'ssh url.git#branch', 'branch') | ||
verify('git+ssh://git@' + domain + '/111/' + proj, 'ssh url') | ||
verify('git+ssh://git@' + domain + '/111/' + proj + '.git', 'ssh url.git') | ||
verify('git+ssh://git@' + domain + '/111/' + proj + '#branch', 'ssh url#branch', 'branch') | ||
verify('git+ssh://git@' + domain + '/111/' + proj + '.git#branch', 'ssh url.git#branch', 'branch') | ||
|
||
verify(shortname + ':111/222', 'shortcut') | ||
verify(shortname + ':111/222.git', 'shortcut.git') | ||
verify(shortname + ':111/222#branch', 'shortcut#branch', 'branch') | ||
verify(shortname + ':111/222.git#branch', 'shortcut.git#branch', 'branch') | ||
verify(shortname + ':111/' + proj, 'shortcut') | ||
verify(shortname + ':111/' + proj + '.git', 'shortcut.git') | ||
verify(shortname + ':111/' + proj + '#branch', 'shortcut#branch', 'branch') | ||
verify(shortname + ':111/' + proj + '.git#branch', 'shortcut.git#branch', 'branch') | ||
} |