You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
1.1 KiB

3 years ago
'use strict'
const { test } = require('tap')
const { formatParamUrl } = require('../lib/util/common')
const cases = [
['/example/:userId', '/example/{userId}'],
['/example/:userId/:secretToken', '/example/{userId}/{secretToken}'],
['/example/near/:lat-:lng/radius/:r', '/example/near/{lat}-{lng}/radius/{r}'],
['/example/near/:lat_1-:lng_1/radius/:r_1', '/example/near/{lat_1}-{lng_1}/radius/{r_1}'],
['/example/*', '/example/{wildcard}'],
['/example/:file(^\\d+).png', '/example/{file}.png'],
['/example/at/:hour(^\\d{2})h:minute(^\\d{2})m', '/example/at/{hour}h{minute}m'],
['/example/at/(^\\d{2})h(^\\d{2})m', '/example/at/{regexp1}h{regexp2}m'],
['/example/at/(^([0-9]{2})h$)-(^([0-9]{2})m$)', '/example/at/{regexp1}-{regexp2}'],
['/name::verb', '/name:verb'],
['/api/v1/postalcode-jp/:code(^[0-9]{7}$)', '/api/v1/postalcode-jp/{code}'],
['/api/v1/postalcode-jp/(^[0-9]{7}$)', '/api/v1/postalcode-jp/{regexp1}']
]
test('formatParamUrl', t => {
t.plan(cases.length)
for (const kase of cases) {
t.equal(formatParamUrl(kase[0]), kase[1])
}
})