|
| 1 | + |
| 2 | +var assert = require('assert') |
| 3 | + |
| 4 | +var parse = require('./') |
| 5 | + |
| 6 | +describe('versionless', function () { |
| 7 | + [ |
| 8 | + 'component/emitter', |
| 9 | + 'https://github.com/component/emitter', |
| 10 | + 'git://github.com/component/emitter.git', |
| 11 | + 'https://github.com/repos/component/emitter/tarball', |
| 12 | + 'https://github.com/repos/component/emitter/zipball', |
| 13 | + 'https://codeload.github.com/component/emitter/legacy.zip', |
| 14 | + 'https://codeload.github.com/component/emitter/legacy.tar.gz', |
| 15 | + ].forEach(function (url) { |
| 16 | + it(url, function () { |
| 17 | + assert.deepEqual(['component', 'emitter', ''], parse(url)) |
| 18 | + }) |
| 19 | + }) |
| 20 | + |
| 21 | + it('works for www.github.com', function () { |
| 22 | + var url = 'https://www.github.com/component/emitter' |
| 23 | + var parsed = parse(url) |
| 24 | + assert.deepEqual(['component', 'emitter', ''], parsed) |
| 25 | + }) |
| 26 | + |
| 27 | + it('works for http://www.github.com', function () { |
| 28 | + var url = 'http://www.github.com/component/emitter' |
| 29 | + var parsed = parse(url) |
| 30 | + assert.deepEqual(['component', 'emitter', ''], parsed) |
| 31 | + }) |
| 32 | +}) |
| 33 | + |
| 34 | +describe('versioned', function () { |
| 35 | + [ |
| 36 | + 'component/emitter#1', |
| 37 | + 'component/emitter@1', |
| 38 | + 'component/emitter#"1"', |
| 39 | + 'component/emitter@"1"', |
| 40 | + 'git://github.com/component/emitter.git#1', |
| 41 | + 'https://github.com/repos/component/emitter/tarball/1', |
| 42 | + 'https://github.com/repos/component/emitter/zipball/1', |
| 43 | + 'https://codeload.github.com/component/emitter/legacy.zip/1', |
| 44 | + 'https://codeload.github.com/component/emitter/legacy.tar.gz/1', |
| 45 | + 'https://github.com/component/emitter/archive/1.tar.gz', |
| 46 | + ].forEach(function (url) { |
| 47 | + it(url, function () { |
| 48 | + assert.deepEqual(['component', 'emitter', '1'], parse(url)) |
| 49 | + }) |
| 50 | + }) |
| 51 | +}) |
| 52 | + |
| 53 | +describe('url parse', function () { |
| 54 | + var builtinUrlParse = require('url').parse |
| 55 | + |
| 56 | + it('handles https:// url', function () { |
| 57 | + var url = 'https://foo.com/bar' |
| 58 | + var parsed = builtinUrlParse(url) |
| 59 | + assert.equal('foo.com', parsed.hostname) |
| 60 | + }) |
| 61 | + |
| 62 | + it('does not handle emails', function () { |
| 63 | + |
| 64 | + var parsed = builtinUrlParse(url) |
| 65 | + assert.equal(null, parsed.hostname, JSON.stringify(parsed)) |
| 66 | + }) |
| 67 | +}) |
| 68 | + |
| 69 | +describe('git @ syntax', function () { |
| 70 | + it('works for git url', function () { |
| 71 | + var url = '[email protected]:bahmutov/lazy-ass.git' |
| 72 | + var parsed = parse(url) |
| 73 | + assert.deepEqual(['bahmutov', 'lazy-ass', ''], parsed) |
| 74 | + }); |
| 75 | + |
| 76 | + it('works for https:git url', function () { |
| 77 | + var url = 'https:[email protected]:bahmutov/lazy-ass.git' |
| 78 | + var parsed = parse(url) |
| 79 | + assert.deepEqual(['bahmutov', 'lazy-ass', ''], parsed) |
| 80 | + }); |
| 81 | +}) |
0 commit comments