rename from bottle (taken, sadface) to flaska
This commit is contained in:
parent
0c2030c2cd
commit
0bfd4de78d
5 changed files with 70 additions and 19 deletions
|
@ -1,7 +1,7 @@
|
|||
import assert from 'assert'
|
||||
import Benchmark from 'benchmarkjs-pretty'
|
||||
import { koaRouter1, koaRouter2 } from './router_koa.js'
|
||||
import { bottleRouter1, bottleRouter2 } from './router_bottle.js'
|
||||
import { flaskaRouter1, flaskaRouter2 } from './router_flaska.js'
|
||||
import { expressRouter1, expressRouter2 } from './router_express.js'
|
||||
import * as consts from './const.js'
|
||||
|
||||
|
@ -25,7 +25,7 @@ function TestSmallStaticRoute() {
|
|||
assert.ok(testData.route)
|
||||
})
|
||||
.add('bottle-router', function() {
|
||||
testData = bottleRouter1.match('/api/staff')
|
||||
testData = flaskaRouter1.match('/api/staff')
|
||||
assert.ok(testData.handler)
|
||||
})
|
||||
.run()
|
||||
|
@ -50,7 +50,7 @@ function TestSmallParamRoute() {
|
|||
assert.ok(testData.route)
|
||||
})
|
||||
.add('bottle-router', function() {
|
||||
testData = bottleRouter1.match('/api/staff/justatest')
|
||||
testData = flaskaRouter1.match('/api/staff/justatest')
|
||||
assert.ok(testData.handler)
|
||||
})
|
||||
.run()
|
||||
|
@ -75,7 +75,7 @@ function TestLargeStaticRoute() {
|
|||
assert.ok(testData.route)
|
||||
})
|
||||
.add('bottle-router', function() {
|
||||
testData = bottleRouter2.match('/api/staff')
|
||||
testData = flaskaRouter2.match('/api/staff')
|
||||
assert.ok(testData.handler)
|
||||
})
|
||||
.run()
|
||||
|
@ -100,7 +100,7 @@ function TestLargeParamRoute() {
|
|||
assert.ok(testData.route)
|
||||
})
|
||||
.add('bottle-router', function() {
|
||||
testData = bottleRouter2.match('/api/staff/justatest')
|
||||
testData = flaskaRouter2.match('/api/staff/justatest')
|
||||
assert.ok(testData.handler)
|
||||
})
|
||||
.run()
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { BottleRouter } from '../bottle.js'
|
||||
import { FlaskaRouter } from '../flaska.mjs'
|
||||
import * as consts from './const.js'
|
||||
|
||||
const router1 = new BottleRouter()
|
||||
const router2 = new BottleRouter()
|
||||
const router1 = new FlaskaRouter()
|
||||
const router2 = new FlaskaRouter()
|
||||
|
||||
for (let key in consts.allRoutes) {
|
||||
router1.addRoute(consts.allRoutes[key], consts.dummy)
|
||||
|
@ -13,6 +13,6 @@ for (let key in consts.allManyRoutes) {
|
|||
}
|
||||
|
||||
export {
|
||||
router1 as bottleRouter1,
|
||||
router2 as bottleRouter2,
|
||||
router1 as flaskaRouter1,
|
||||
router2 as flaskaRouter2,
|
||||
}
|
|
@ -11,11 +11,11 @@ function Branch() {
|
|||
|
||||
const __paramMapName = '__param'
|
||||
|
||||
function BottleRouter() {
|
||||
function FlaskaRouter() {
|
||||
this._root = new Branch()
|
||||
}
|
||||
|
||||
BottleRouter.prototype.addRoute = function(route, handler) {
|
||||
FlaskaRouter.prototype.addRoute = function(route, handler) {
|
||||
if (route[0] !== '/')
|
||||
throw new Error(`route "${route}" must start with forward slash`);
|
||||
|
||||
|
@ -76,7 +76,7 @@ BottleRouter.prototype.addRoute = function(route, handler) {
|
|||
}
|
||||
}
|
||||
|
||||
BottleRouter.prototype.match = function(url) {
|
||||
FlaskaRouter.prototype.match = function(url) {
|
||||
let branch = this._root;
|
||||
let start = 1;
|
||||
let end = 1;
|
||||
|
@ -120,5 +120,5 @@ BottleRouter.prototype.match = function(url) {
|
|||
}
|
||||
|
||||
export {
|
||||
BottleRouter,
|
||||
FlaskaRouter,
|
||||
}
|
13
package.json
13
package.json
|
@ -1,10 +1,10 @@
|
|||
{
|
||||
"name": "bottle-node",
|
||||
"name": "flasha-node",
|
||||
"version": "1.0.0",
|
||||
"description": "Bottle is a micro web-framework for node. It is designed to be fast, simple and lightweight, and is distributed as a single file module with no dependencies.",
|
||||
"main": "bottle.js",
|
||||
"description": "Flaska is a micro web-framework for node. It is designed to be fast, simple and lightweight, and is distributed as a single file module with no dependencies.",
|
||||
"main": "flaska.mjs",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
"test": "eltro"
|
||||
},
|
||||
"type": "module",
|
||||
"repository": {
|
||||
|
@ -16,5 +16,8 @@
|
|||
"bugs": {
|
||||
"url": "https://github.com/nfp-projects/bottle-node/issues"
|
||||
},
|
||||
"homepage": "https://github.com/nfp-projects/bottle-node#readme"
|
||||
"homepage": "https://github.com/nfp-projects/bottle-node#readme",
|
||||
"devDependencies": {
|
||||
"eltro": "^0.9.0"
|
||||
}
|
||||
}
|
||||
|
|
48
test/flaska.test.mjs
Normal file
48
test/flaska.test.mjs
Normal file
|
@ -0,0 +1,48 @@
|
|||
import { Eltro as t, assert } from 'eltro'
|
||||
import { FlaskaRouter } from '../flaska.mjs'
|
||||
|
||||
t.describe('FlaskaRouter', function() {
|
||||
t.describe('#match()', function() {
|
||||
t.test('should match basic paths', function() {
|
||||
let assertMatched = false
|
||||
let router = new FlaskaRouter()
|
||||
router.addRoute('/test', function() { assertMatched = true })
|
||||
let result = router.match('/test')
|
||||
assert.ok(result.handler)
|
||||
result.handler()
|
||||
assert.strictEqual(assertMatched, true)
|
||||
})
|
||||
|
||||
t.test('should match variable paths', function() {
|
||||
const assertParameter = 'bla'
|
||||
let assertMatched = false
|
||||
let router = new FlaskaRouter()
|
||||
router.addRoute('/test/:id', function() { assertMatched = true })
|
||||
let result = router.match('/test/' + assertParameter)
|
||||
assert.ok(result.handler)
|
||||
result.handler()
|
||||
assert.strictEqual(assertMatched, true)
|
||||
assert.strictEqual(result.params.get('id'), assertParameter)
|
||||
})
|
||||
|
||||
t.test('should match paths properly', function() {
|
||||
let assertMatched = true
|
||||
let router = new FlaskaRouter()
|
||||
router.addRoute('/test/:id', function() { assertMatched = false })
|
||||
router.addRoute('/test/:id/test1', function() { })
|
||||
let result = router.match('/test/asdf/test1')
|
||||
assert.ok(result.handler)
|
||||
result.handler()
|
||||
assert.strictEqual(assertMatched, true)
|
||||
assert.strictEqual(result.params.get('id'), 'asdf')
|
||||
})
|
||||
|
||||
t.test('should return null when no match is found', function() {
|
||||
let router = new FlaskaRouter()
|
||||
router.addRoute('/test/:id', function() { })
|
||||
router.addRoute('/test/:id/test1', function() { })
|
||||
let result = router.match('/test/asdf/test2')
|
||||
assert.notOk(result)
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Reference in a new issue