Skip to content

Commit 534799b

Browse files
committed
привет мир (Add testcase for unicode queries)
I noticed that the IsString instance for Identifier and Query look suspect from an efficiency standpoint. I briefly considered using newtype deriving instead, but then remembered that this would probably break anybody using unicode inside queries. While this wouldn't affect me personally, postgresql-simple does have a number of international users and contributors. So I added this to the test suite, in case I do decide to try to tweak the IsString instance at some point.
1 parent e1253f2 commit 534799b

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

test/Main.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{-# LANGUAGE ScopedTypeVariables #-}
44
import Common
55
import Database.PostgreSQL.Simple.FromField (FromField)
6+
import Database.PostgreSQL.Simple.Types(Query(..))
67
import Database.PostgreSQL.Simple.HStore
78
import qualified Database.PostgreSQL.Simple.Transaction as ST
89
import Control.Applicative
@@ -13,8 +14,10 @@ import Data.IORef
1314
import Data.Typeable
1415
import qualified Data.ByteString as B
1516
import Data.Map (Map)
17+
import Data.List (sort)
1618
import qualified Data.Map as Map
1719
import Data.Text(Text)
20+
import qualified Data.Text.Encoding as T
1821
import System.Exit (exitFailure)
1922
import System.IO
2023
import qualified Data.Vector as V
@@ -36,6 +39,7 @@ tests =
3639
, TestLabel "HStore" . testHStore
3740
, TestLabel "JSON" . testJSON
3841
, TestLabel "Savepoint" . testSavepoint
42+
, TestLabel "Unicode" . testUnicode
3943
]
4044

4145
testBytea :: TestEnv -> Test
@@ -243,6 +247,15 @@ testSavepoint TestEnv{..} = TestCase $ do
243247

244248
return ()
245249

250+
testUnicode :: TestEnv -> Test
251+
testUnicode TestEnv{..} = TestCase $ do
252+
let q = Query . T.encodeUtf8
253+
let messages = map Only ["привет","мир"] :: [Only Text]
254+
execute_ conn (q "CREATE TEMPORARY TABLE ру́сский (сообщение TEXT)")
255+
executeMany conn "INSERT INTO ру́сский (сообщение) VALUES (?)" messages
256+
messages' <- query_ conn "SELECT сообщение FROM ру́сский"
257+
sort messages @?= sort messages'
258+
246259
data TestException
247260
= TestException
248261
deriving (Eq, Show, Typeable)

0 commit comments

Comments
 (0)