on dev help sign in
range tests
commite2abe3d03e2a6b0594ff53f00634e53350d2de89 authorEitan Chatav <eitan@EEM109LMBP-1.local> dateMon 22 Jul 2019, 13:01 (7 years ago) parent54d2f03
1 file changed+19−2
squeal-postgresql/test/Spec.hs+19−2
squeal-postgresql/test/Spec.hs+19−2
@@ -18,6 +18,7 @@ module Spec (specTests) where
1818
1919import Control.Concurrent.Async (replicateConcurrently)
2020import Data.ByteString (ByteString)
21+import Data.Int (Int32)
2122import Data.Text (Text)
2223import Test.Hspec
2324
@@ -89,7 +90,7 @@ spec = before_ setupDB . after_ dropDB $ do
8990 withConnection connectionString (transactionally_ insertUserTwice)
9091 `shouldThrow` (== err23505)
9192
92− describe "Pools" $ do
93+ describe "Pools" $
9394
9495 it "should manage concurrent transactions" $ do
9596 pool <- createConnectionPool
@@ -102,7 +103,23 @@ spec = before_ setupDB . after_ dropDB $ do
102103 Just (Only chr) <- firstRow result
103104 return chr
104105 chrs <- replicateConcurrently 10 session
105− chrs `shouldSatisfy` (all (== 'a'))
106+ chrs `shouldSatisfy` all (== 'a')
107+
108+ describe "Ranges" $
109+
110+ it "should correctly decode ranges" $ do
111+
112+ rangesOut <- withConnection connectionString $ do
113+ let
114+ query :: Query_ (Public '[]) () (Only (Range Int32))
115+ query = values
116+ ( range int4range (atLeast 3) `as` #fromOnly )
117+ [ range int4range (3 <=..< 5) `as` #fromOnly
118+ , range int4range Empty `as` #fromOnly
119+ , range int4range whole `as` #fromOnly ]
120+ getRows =<< runQuery query
121+ (fromOnly <$> rangesOut :: [Range Int32]) `shouldBe`
122+ [ atLeast 3, 3 <=..< 5, Empty, whole ]
106123
107124specTests :: IO ()
108125specTests = hspec spec