This repository has been archived by the owner on Sep 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
50 lines (42 loc) · 1.76 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var linkToFunc = require('./build/index')
var tape = require('tape')
tape('basic', function (t) {
var product = linkToFunc('/home/product(/:productId)')
var productList = linkToFunc('/home/product')
var productDetail = linkToFunc('/home/product/:id')
t.equal(product(), '/home/product')
t.equal(product(10000), '/home/product/10000')
t.equal(productList(), '/home/product')
t.equal(productDetail(10000), '/home/product/10000')
t.end()
})
tape('getLink', function (t) {
var product = linkToFunc('/home/product(/:productId)')
var productList = linkToFunc('/home/product')
var productDetail = linkToFunc('/home/product/:id')
t.equal(product.getLink(), '/home/product(/:productId)')
t.equal(productList.getLink(), '/home/product')
t.equal(productDetail.getLink(), '/home/product/:id')
t.end()
})
tape('toString', function (t) {
var product = linkToFunc('/home/product(/:productId)')
var productList = linkToFunc('/home/product')
var productDetail = linkToFunc('/home/product/:id')
t.equal(product.toString(), '/home/product')
t.equal(product.toString(10000), '/home/product/10000')
t.equal(productList.toString(), '/home/product')
t.equal(productDetail.toString(10000), '/home/product/10000')
t.end()
})
tape('absPath', function (t) {
var url = 'http://url.com';
var product = linkToFunc.absPath(url, '/home/product(/:productId)')
var productList = linkToFunc.absPath(url, '/home/product')
var productDetail = linkToFunc.absPath(url, '/home/product/:id')
t.equal(product.toAbsPath(), 'http://url.com/home/product')
t.equal(product.toAbsPath(10000), 'http://url.com/home/product/10000')
t.equal(productList.toAbsPath(), 'http://url.com/home/product')
t.equal(productDetail.toAbsPath(10000), 'http://url.com/home/product/10000')
t.end()
})