2017-10-26 21:19:30 +00:00
|
|
|
module Test.HTTPure.LookupSpec where
|
2017-09-26 06:08:07 +00:00
|
|
|
|
|
|
|
import Prelude
|
|
|
|
|
2017-10-23 22:50:27 +00:00
|
|
|
import Data.Maybe as Maybe
|
2018-07-08 23:16:48 +00:00
|
|
|
import Foreign.Object as Object
|
2017-09-26 07:14:06 +00:00
|
|
|
|
2017-09-26 06:08:07 +00:00
|
|
|
import Test.Spec as Spec
|
|
|
|
|
2017-10-23 22:50:27 +00:00
|
|
|
import HTTPure.Lookup ((!!), (!@), (!?))
|
2017-09-26 06:08:07 +00:00
|
|
|
|
2017-10-26 21:19:30 +00:00
|
|
|
import Test.HTTPure.TestHelpers as TestHelpers
|
|
|
|
import Test.HTTPure.TestHelpers ((?=))
|
2017-09-26 06:08:07 +00:00
|
|
|
|
2017-10-26 21:19:30 +00:00
|
|
|
atSpec :: TestHelpers.Test
|
2017-10-23 22:50:27 +00:00
|
|
|
atSpec = Spec.describe "at" do
|
|
|
|
Spec.describe "when the lookup returns a Just" do
|
|
|
|
Spec.it "is the value inside the Just" do
|
|
|
|
[ "one", "two", "three" ] !@ 1 ?= "two"
|
|
|
|
Spec.describe "when the lookup returns a Nothing" do
|
|
|
|
Spec.it "is mempty" do
|
|
|
|
[ "one", "two", "three" ] !@ 4 ?= ""
|
|
|
|
|
2017-10-26 21:19:30 +00:00
|
|
|
hasSpec :: TestHelpers.Test
|
2017-10-23 22:50:27 +00:00
|
|
|
hasSpec = Spec.describe "has" do
|
|
|
|
Spec.describe "when the lookup returns a Just" do
|
|
|
|
Spec.it "is true" do
|
|
|
|
[ "one", "two", "three" ] !? 1 ?= true
|
|
|
|
Spec.describe "when the lookup returns a Nothing" do
|
|
|
|
Spec.it "is false" do
|
|
|
|
[ "one", "two", "three" ] !? 4 ?= false
|
|
|
|
|
2017-10-26 21:19:30 +00:00
|
|
|
lookupArraySpec :: TestHelpers.Test
|
2017-09-26 06:08:07 +00:00
|
|
|
lookupArraySpec = Spec.describe "lookupArray" do
|
|
|
|
Spec.describe "when the index is in bounds" do
|
2017-10-23 22:50:27 +00:00
|
|
|
Spec.it "is Just the value at the index" do
|
|
|
|
[ "one", "two", "three" ] !! 1 ?= Maybe.Just "two"
|
2017-09-26 06:08:07 +00:00
|
|
|
Spec.describe "when the index is out of bounds" do
|
2017-10-23 22:50:27 +00:00
|
|
|
Spec.it "is Nothing" do
|
|
|
|
(([ "one", "two", "three" ] !! 4) :: Maybe.Maybe String) ?= Maybe.Nothing
|
2017-09-26 06:08:07 +00:00
|
|
|
|
2018-07-08 23:16:48 +00:00
|
|
|
lookupMapSpec :: TestHelpers.Test
|
|
|
|
lookupMapSpec = Spec.describe "lookupMap" do
|
|
|
|
Spec.describe "when the key is in the Map" do
|
2017-10-23 22:50:27 +00:00
|
|
|
Spec.it "is Just the value at the given key" do
|
2018-07-08 23:16:48 +00:00
|
|
|
mockMap !! "foo" ?= Maybe.Just "bar"
|
|
|
|
Spec.describe "when the key is not in the Map" do
|
2017-10-23 22:50:27 +00:00
|
|
|
Spec.it "is Nothing" do
|
2018-07-08 23:16:48 +00:00
|
|
|
((mockMap !! "baz") :: Maybe.Maybe String) ?= Maybe.Nothing
|
2017-09-26 07:14:06 +00:00
|
|
|
where
|
2018-07-08 23:16:48 +00:00
|
|
|
mockMap = Object.singleton "foo" "bar"
|
2017-09-26 07:14:06 +00:00
|
|
|
|
2017-10-26 21:19:30 +00:00
|
|
|
lookupSpec :: TestHelpers.Test
|
2017-09-26 06:08:07 +00:00
|
|
|
lookupSpec = Spec.describe "Lookup" do
|
2017-10-23 22:50:27 +00:00
|
|
|
atSpec
|
|
|
|
hasSpec
|
2017-09-26 06:08:07 +00:00
|
|
|
lookupArraySpec
|
2018-07-08 23:16:48 +00:00
|
|
|
lookupMapSpec
|