generated from tpl/purs
50 lines
1.6 KiB
Haskell
50 lines
1.6 KiB
Haskell
module Spec.Data.Postgres.Query.Builder where
|
|
|
|
import Prelude
|
|
|
|
import Control.Monad.Trans.Class (lift)
|
|
import Data.Postgres.Query.Builder (param, reference, runBuilder)
|
|
import Data.Set as Set
|
|
import Data.Tuple.Nested ((/\))
|
|
import Foreign (unsafeFromForeign)
|
|
import Foreign.Internal.Stringify (unsafeStringify)
|
|
import Test.Spec (Spec, describe, it)
|
|
import Test.Spec.Assertions (shouldEqual)
|
|
|
|
spec :: Spec Unit
|
|
spec =
|
|
describe "Data.Postgres.Query.Builder" do
|
|
describe "runBuilder" do
|
|
it "empty" do
|
|
_ /\ { params, refs } <- runBuilder (pure unit)
|
|
map unsafeStringify params `shouldEqual` []
|
|
refs `shouldEqual` Set.empty
|
|
describe "reference" do
|
|
it "one" do
|
|
_ /\ { refs } <- runBuilder $ reference "foo"
|
|
refs `shouldEqual` (Set.singleton "foo")
|
|
it "dup" do
|
|
_ /\ { refs } <- runBuilder do
|
|
reference "foo"
|
|
reference "foo"
|
|
refs `shouldEqual` (Set.singleton "foo")
|
|
it "multiple" do
|
|
_ /\ { refs } <- runBuilder do
|
|
reference "foo"
|
|
reference "bar"
|
|
reference "baz"
|
|
refs `shouldEqual` (Set.fromFoldable [ "foo", "bar", "baz" ])
|
|
describe "param" do
|
|
it "single" do
|
|
p /\ { params } <- runBuilder $ param 123
|
|
p `shouldEqual` "$1"
|
|
map unsafeFromForeign params `shouldEqual` [ 123 ]
|
|
it "many" do
|
|
_ /\ { params } <- runBuilder do
|
|
a <- param 123
|
|
b <- param "abc"
|
|
c <- param [ 123 ]
|
|
d <- param true
|
|
lift $ [ a, b, c, d ] `shouldEqual` [ "$1", "$2", "$3", "$4" ]
|
|
map unsafeStringify params `shouldEqual` [ "123", "\"abc\"", "[123]", "true" ]
|