2022-05-22 11:47:58 +00:00
|
|
|
module Test.HTTPurple.PathSpec where
|
2017-07-14 06:28:57 +00:00
|
|
|
|
2017-07-18 05:31:46 +00:00
|
|
|
import Prelude
|
2022-05-04 21:02:29 +00:00
|
|
|
|
2022-05-22 11:47:58 +00:00
|
|
|
import HTTPurple.Path (read)
|
|
|
|
import Test.HTTPurple.TestHelpers (Test, mockRequest, (?=))
|
2022-05-04 21:02:29 +00:00
|
|
|
import Test.Spec (describe, it)
|
2017-09-26 06:08:07 +00:00
|
|
|
|
2021-11-19 06:16:35 +00:00
|
|
|
readSpec :: Test
|
2021-03-22 19:02:36 +00:00
|
|
|
readSpec =
|
2021-11-19 06:16:35 +00:00
|
|
|
describe "read" do
|
|
|
|
describe "with a query string" do
|
|
|
|
it "is just the path" do
|
|
|
|
request <- mockRequest "" "GET" "test/path?blabla" "" []
|
|
|
|
read request ?= [ "test", "path" ]
|
|
|
|
describe "with no query string" do
|
|
|
|
it "is the path" do
|
|
|
|
request <- mockRequest "" "GET" "test/path" "" []
|
|
|
|
read request ?= [ "test", "path" ]
|
|
|
|
describe "with no segments" do
|
|
|
|
it "is an empty array" do
|
|
|
|
request <- mockRequest "" "GET" "" "" []
|
|
|
|
read request ?= []
|
|
|
|
describe "with empty segments" do
|
|
|
|
it "strips the empty segments" do
|
|
|
|
request <- mockRequest "" "GET" "//test//path///?query" "" []
|
|
|
|
read request ?= [ "test", "path" ]
|
|
|
|
describe "with percent encoded segments" do
|
|
|
|
it "decodes percent encoding" do
|
|
|
|
request <- mockRequest "" "GET" "/test%20path/%2Fthis" "" []
|
|
|
|
read request ?= [ "test path", "/this" ]
|
|
|
|
it "does not decode a plus sign" do
|
|
|
|
request <- mockRequest "" "GET" "/test+path/this" "" []
|
|
|
|
read request ?= [ "test+path", "this" ]
|
2017-07-14 06:28:57 +00:00
|
|
|
|
2021-11-19 06:16:35 +00:00
|
|
|
pathSpec :: Test
|
2021-03-22 19:02:36 +00:00
|
|
|
pathSpec =
|
2021-11-19 06:16:35 +00:00
|
|
|
describe "Path" do
|
2021-03-22 19:02:36 +00:00
|
|
|
readSpec
|