An Express-like HTTP router for Bash compatible with CGI 1.1
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.

62 lines
1.2 KiB

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