Exprash/tests/routes.sh

56 lines
1.2 KiB
Bash
Executable File

it "Should match plain route" $({
_exprashResetRouteGlobals
PATH_INFO='/plain/route'
all '/plain/route'
})
it "Should not match incorrect plain route" $({
_exprashResetRouteGlobals
PATH_INFO='/plain/WRONG'
! all '/plain/route'
})
it "Should extract parameter" $({
_exprashResetRouteGlobals
PATH_INFO='/cats/calico/pet'
all '/cats/:cat/pet' && hasParam 'cat' && [ "$(param 'cat')" == 'calico' ]
})
it "Should match wildcard route" $({
_exprashResetRouteGlobals
PATH_INFO='/cats/calico/pet'
all '/cats/*/pet'
})
it "Should not match incorrect wildcard route" $({
_exprashResetRouteGlobals
PATH_INFO='/cats/calico/'
! all '/cats/*/pet'
})
it "Should match multi-wildcard route" $({
_exprashResetRouteGlobals
PATH_INFO='/cats/calico/pet/donkey'
all '/cats/**'
})
it "Should not match incorrect multi-wildcard route" $({
_exprashResetRouteGlobals
PATH_INFO='/INCORRECT/calico/pet/donkey'
! all '/cats/**'
})
it "Should match get route" $({
_exprashResetRouteGlobals
REQUEST_METHOD='GET'
PATH_INFO='/simple/route'
get '/simple/route'
})
it "Should not match get route with incorrect method" $({
_exprashResetRouteGlobals
REQUEST_METHOD='POST'
PATH_INFO='/simple/route'
! get '/simple/route'
})