-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86e7331
commit 33ae435
Showing
3 changed files
with
347 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
'use strict' | ||
|
||
const t = require('tap') | ||
const test = t.test | ||
const FindMyWay = require('..') | ||
|
||
test('has returns false if there is no routes', t => { | ||
t.plan(1) | ||
|
||
const findMyWay = FindMyWay() | ||
|
||
const hastRoute = findMyWay.has({ method: 'GET', path: '/example' }) | ||
t.equal(hastRoute, false) | ||
}) | ||
|
||
test('has returns true for a static route', t => { | ||
t.plan(1) | ||
|
||
const findMyWay = FindMyWay() | ||
|
||
findMyWay.on('GET', '/example', () => {}) | ||
|
||
const hastRoute = findMyWay.has({ method: 'GET', path: '/example' }) | ||
t.equal(hastRoute, true) | ||
}) | ||
|
||
test('has returns false for a static route', t => { | ||
t.plan(1) | ||
|
||
const findMyWay = FindMyWay() | ||
|
||
findMyWay.on('GET', '/example', () => {}) | ||
|
||
const hastRoute = findMyWay.has({ method: 'GET', path: '/example1' }) | ||
t.equal(hastRoute, false) | ||
}) | ||
|
||
test('has returns true for a parametric route', t => { | ||
t.plan(1) | ||
|
||
const findMyWay = FindMyWay() | ||
|
||
findMyWay.on('GET', '/:param', () => {}) | ||
|
||
const hastRoute = findMyWay.has({ method: 'GET', path: '/:param' }) | ||
t.equal(hastRoute, true) | ||
}) | ||
|
||
test('has returns false for a parametric route', t => { | ||
t.plan(1) | ||
|
||
const findMyWay = FindMyWay() | ||
|
||
findMyWay.on('GET', '/foo/:param', () => {}) | ||
|
||
const hastRoute = findMyWay.has({ method: 'GET', path: '/bar/:param' }) | ||
t.equal(hastRoute, false) | ||
}) | ||
|
||
test('has returns true for a parametric route with static suffix', t => { | ||
t.plan(1) | ||
|
||
const findMyWay = FindMyWay() | ||
|
||
findMyWay.on('GET', '/:param-static', () => {}) | ||
|
||
const hastRoute = findMyWay.has({ method: 'GET', path: '/:param-static' }) | ||
t.equal(hastRoute, true) | ||
}) | ||
|
||
test('has returns false for a parametric route with static suffix', t => { | ||
t.plan(1) | ||
|
||
const findMyWay = FindMyWay() | ||
|
||
findMyWay.on('GET', '/:param-static1', () => {}) | ||
|
||
const hastRoute = findMyWay.has({ method: 'GET', path: '/:param-static2' }) | ||
t.equal(hastRoute, false) | ||
}) | ||
|
||
test('has returns true even if a param name different', t => { | ||
t.plan(1) | ||
|
||
const findMyWay = FindMyWay() | ||
|
||
findMyWay.on('GET', '/:param1', () => {}) | ||
|
||
const hastRoute = findMyWay.has({ method: 'GET', path: '/:param2' }) | ||
t.equal(hastRoute, true) | ||
}) | ||
|
||
test('has returns true for a multi-parametric route', t => { | ||
t.plan(1) | ||
|
||
const findMyWay = FindMyWay() | ||
|
||
findMyWay.on('GET', '/:param1-:param2', () => {}) | ||
|
||
const hastRoute = findMyWay.has({ method: 'GET', path: '/:param1-:param2' }) | ||
t.equal(hastRoute, true) | ||
}) | ||
|
||
test('has returns false for a multi-parametric route', t => { | ||
t.plan(1) | ||
|
||
const findMyWay = FindMyWay() | ||
|
||
findMyWay.on('GET', '/foo/:param1-:param2/bar1', () => {}) | ||
|
||
const hastRoute = findMyWay.has({ method: 'GET', path: '/foo/:param1-:param2/bar2' }) | ||
t.equal(hastRoute, false) | ||
}) | ||
|
||
test('has returns true for a regexp route', t => { | ||
t.plan(1) | ||
|
||
const findMyWay = FindMyWay() | ||
|
||
findMyWay.on('GET', '/:param(^\\d+$)', () => {}) | ||
|
||
const hastRoute = findMyWay.has({ method: 'GET', path: '/:param(^\\d+$)' }) | ||
t.equal(hastRoute, true) | ||
}) | ||
|
||
test('has returns false for a regexp route', t => { | ||
t.plan(1) | ||
|
||
const findMyWay = FindMyWay() | ||
|
||
findMyWay.on('GET', '/:file(^\\S+).png', () => {}) | ||
|
||
const hastRoute = findMyWay.has({ method: 'GET', path: '/:file(^\\D+).png' }) | ||
t.equal(hastRoute, false) | ||
}) | ||
|
||
test('has returns true for a wildcard route', t => { | ||
t.plan(1) | ||
|
||
const findMyWay = FindMyWay() | ||
|
||
findMyWay.on('GET', '/example/*', () => {}) | ||
|
||
const hastRoute = findMyWay.has({ method: 'GET', path: '/example/*' }) | ||
t.equal(hastRoute, true) | ||
}) | ||
|
||
test('has returns false for a wildcard route', t => { | ||
t.plan(1) | ||
|
||
const findMyWay = FindMyWay() | ||
|
||
findMyWay.on('GET', '/foo1/*', () => {}) | ||
|
||
const hastRoute = findMyWay.has({ method: 'GET', path: '/foo2/*' }) | ||
t.equal(hastRoute, false) | ||
}) |