2022-05-22 11:47:58 +00:00
|
|
|
module Test.HTTPurple.LookupSpec where
|
2017-09-26 06:08:07 +00:00
|
|
|
|
|
|
|
import Prelude
|
2022-05-04 21:02:29 +00:00
|
|
|
|
2021-11-19 06:16:35 +00:00
|
|
|
import Data.Maybe (Maybe(Nothing, Just))
|
|
|
|
import Foreign.Object (singleton)
|
2022-05-22 11:47:58 +00:00
|
|
|
import HTTPurple.Lookup ((!!), (!?), (!@))
|
|
|
|
import Test.HTTPurple.TestHelpers (Test, (?=))
|
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
|
|
|
atSpec :: Test
|
2021-03-22 19:02:36 +00:00
|
|
|
atSpec =
|
2021-11-19 06:16:35 +00:00
|
|
|
describe "at" do
|
|
|
|
describe "when the lookup returns a Just" do
|
|
|
|
it "is the value inside the Just" do
|
2021-03-22 19:02:36 +00:00
|
|
|
[ "one", "two", "three" ] !@ 1 ?= "two"
|
2021-11-19 06:16:35 +00:00
|
|
|
describe "when the lookup returns a Nothing" do
|
|
|
|
it "is mempty" do
|
2021-03-22 19:02:36 +00:00
|
|
|
[ "one", "two", "three" ] !@ 4 ?= ""
|
2017-10-23 22:50:27 +00:00
|
|
|
|
2021-11-19 06:16:35 +00:00
|
|
|
hasSpec :: Test
|
2021-03-22 19:02:36 +00:00
|
|
|
hasSpec =
|
2021-11-19 06:16:35 +00:00
|
|
|
describe "has" do
|
|
|
|
describe "when the lookup returns a Just" do
|
|
|
|
it "is true" do
|
2021-03-22 19:02:36 +00:00
|
|
|
[ "one", "two", "three" ] !? 1 ?= true
|
2021-11-19 06:16:35 +00:00
|
|
|
describe "when the lookup returns a Nothing" do
|
|
|
|
it "is false" do
|
2021-03-22 19:02:36 +00:00
|
|
|
[ "one", "two", "three" ] !? 4 ?= false
|
2017-10-23 22:50:27 +00:00
|
|
|
|
2021-11-19 06:16:35 +00:00
|
|
|
lookupFunctionSpec :: Test
|
2021-03-22 19:02:36 +00:00
|
|
|
lookupFunctionSpec =
|
2021-11-19 06:16:35 +00:00
|
|
|
describe "lookup" do
|
|
|
|
describe "Array" do
|
|
|
|
describe "when the index is in bounds" do
|
|
|
|
it "is Just the value at the index" do
|
|
|
|
[ "one", "two", "three" ] !! 1 ?= Just "two"
|
|
|
|
describe "when the index is out of bounds" do
|
|
|
|
it "is Nothing" do
|
|
|
|
(([ "one", "two", "three" ] !! 4) :: Maybe String) ?= Nothing
|
|
|
|
describe "Map" do
|
|
|
|
describe "when the key is in the Map" do
|
|
|
|
it "is Just the value at the given key" do
|
|
|
|
let mockMap = singleton "foo" "bar"
|
|
|
|
mockMap !! "foo" ?= Just "bar"
|
|
|
|
describe "when the key is not in the Map" do
|
|
|
|
it "is Nothing" do
|
|
|
|
let mockMap = singleton "foo" "bar"
|
|
|
|
((mockMap !! "baz") :: Maybe String) ?= Nothing
|
2017-09-26 07:14:06 +00:00
|
|
|
|
2021-11-19 06:16:35 +00:00
|
|
|
lookupSpec :: Test
|
2021-03-22 19:02:36 +00:00
|
|
|
lookupSpec =
|
2021-11-19 06:16:35 +00:00
|
|
|
describe "Lookup" do
|
2021-03-22 19:02:36 +00:00
|
|
|
atSpec
|
|
|
|
hasSpec
|
|
|
|
lookupFunctionSpec
|