0
0
mirror of https://github.com/honojs/hono.git synced 2024-12-01 10:51:01 +00:00
hono/src/util.test.js

30 lines
834 B
JavaScript
Raw Normal View History

2021-12-26 18:53:44 +00:00
const { splitPath, getPattern, getParamName } = require('./util')
describe('Utility methods', () => {
it('splitPath', () => {
let ps = splitPath('/')
expect(ps[0]).toBe('')
ps = splitPath('/hello')
expect(ps[0]).toBe('hello')
ps = splitPath('*')
expect(ps[0]).toBe('*')
ps = splitPath('/wildcard-abc/*/wildcard-efg')
expect(ps[0]).toBe('wildcard-abc')
expect(ps[1]).toBe('*')
expect(ps[2]).toBe('wildcard-efg')
2021-12-27 03:12:22 +00:00
ps = splitPath('/map/:location/events')
expect(ps[0]).toBe('map')
expect(ps[1]).toBe(':location')
expect(ps[2]).toBe('events')
2021-12-26 18:53:44 +00:00
})
it('getPattern', () => {
let res = getPattern(':id')
expect(res[0]).toBe('id')
expect(res[1]).toBe('(.+)')
2021-12-26 18:53:44 +00:00
res = getPattern(':id{[0-9]+}')
expect(res[0]).toBe('id')
expect(res[1]).toBe('([0-9]+)')
2021-12-26 18:53:44 +00:00
})
})