Skip to content

Commit b07cf2d

Browse files
committed
migrated tests
1 parent e6d60ed commit b07cf2d

6 files changed

Lines changed: 104 additions & 183 deletions

File tree

default.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{ mkDerivation, attoparsec, base, bytestring, case-conversion
2-
, heredoc, hspec2, HUnit, postgresql-simple, stdenv
2+
, heredoc, hspec, HUnit, postgresql-simple, stdenv
33
, template-haskell, text, time
44
}:
55
mkDerivation {
@@ -11,7 +11,7 @@ mkDerivation {
1111
template-haskell text time
1212
];
1313
testHaskellDepends = [
14-
attoparsec base bytestring case-conversion hspec2 HUnit
14+
attoparsec base bytestring case-conversion hspec HUnit
1515
postgresql-simple text
1616
];
1717
description = "A FFI-like bindings for PostgreSQL stored functions";

postgresql-simple-bind.cabal

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ test-suite tests
5959

6060
build-depends: base >= 4.8 && < 5.0
6161
, bytestring >= 0.10.8 && < 0.11
62-
, HUnit
63-
, hspec2
64-
, hspec-expectations
62+
, hspec
6563
, postgresql-simple >= 0.5.2 && < 0.6
6664
, postgresql-simple-bind
6765
, text >= 1.2.2 && < 1.3

tests/Common.hs

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/Main.hs

Lines changed: 101 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
{-# LANGUAGE OverloadedStrings #-}
22
{-# LANGUAGE NamedFieldPuns #-}
33

4-
import Control.Monad (unless)
5-
-- import Data.WithLocation (WithLocation)
64
import Test.Hspec
7-
import Test.Hspec.Expectations (expectationFailure)
8-
-- import Test.Hspec.Wai (with)
95
import Database.PostgreSQL.Simple.Bind.Representation
106
import Data.Text ()
117

@@ -14,7 +10,7 @@ main = hspec spec
1410

1511
spec :: Spec
1612
spec = do
17-
describe "simple signatures" $ do
13+
describe "parsePGFunction" $ do
1814
it "works with simple signatures" $ do
1915
(parsePGFunction "function f(x bigint) returns bigint") `shouldBe`
2016
(PGFunction "" "f" [PGArgument "x" "bigint" False] (PGSingle "bigint"))
@@ -29,3 +25,103 @@ spec = do
2925
(parsePGFunction "FUNCTION H(Z VARCHAR) RETURNS BIGINT") `shouldBe`
3026
(PGFunction "" "h" [PGArgument "z" "varchar" False] (PGSingle "bigint"))
3127

28+
29+
it "works with default values" $ do
30+
(parsePGFunction "function f(x bigint default 0::bigint) returns void") `shouldBe`
31+
(PGFunction "" "f" [PGArgument "x" "bigint" True] (PGSingle "void"))
32+
33+
(parsePGFunction "function f(x bigint, y bigint default 0::bigint) returns void") `shouldBe`
34+
(PGFunction "" "f"
35+
[PGArgument "x" "bigint" False, PGArgument "y" "bigint" True] (PGSingle "void"))
36+
37+
(parsePGFunction
38+
"function f(x bigint, y bigint = 0::bigint, z bigint = 0::bigint) returns void") `shouldBe`
39+
(PGFunction "" "f" [
40+
PGArgument "x" "bigint" False
41+
, PGArgument "y" "bigint" True
42+
, PGArgument "z" "bigint" True
43+
] (PGSingle "void"))
44+
45+
46+
it "works with return value types" $ do
47+
(parsePGFunction "function f() returns setof bigint") `shouldBe`
48+
(PGFunction "" "f" [] (PGSetOf "bigint"))
49+
50+
(parsePGFunction "function f() returns SETOF bigint") `shouldBe`
51+
(PGFunction "" "f" [] (PGSetOf "bigint"))
52+
53+
(parsePGFunction "function f() returns table (x bigint, y varchar)") `shouldBe`
54+
(PGFunction "" "f" [] (PGTable [PGColumn "x" "bigint", PGColumn "y" "varchar"]))
55+
56+
57+
it "works with schema names" $ do
58+
(parsePGFunction "function public.f() returns bigint") `shouldBe`
59+
(PGFunction "public" "f" [] (PGSingle "bigint"))
60+
61+
(parsePGFunction "function Test.f() returns bigint") `shouldBe`
62+
(PGFunction "test" "f" [] (PGSingle "bigint"))
63+
64+
65+
66+
describe "parsing a function with specific type" $ do
67+
it "works for multiple word types" $ do
68+
(parsePGFunction "function f(x double precision) returns void") `shouldBe`
69+
(PGFunction "" "f" [PGArgument "x" "double precision" False] (PGSingle "void"))
70+
71+
72+
it "works for types with precisions" $ do
73+
(parsePGFunction "function f(x bit) returns void") `shouldBe`
74+
(PGFunction "" "f" [PGArgument "x" "bit" False] (PGSingle "void"))
75+
76+
(parsePGFunction "function f(x bit (32)) returns void") `shouldBe`
77+
(PGFunction "" "f" [PGArgument "x" "bit" False] (PGSingle "void"))
78+
79+
80+
it "works for types with precisions and multiple words" $ do
81+
(parsePGFunction "function f(x character varying) returns void") `shouldBe`
82+
(PGFunction "" "f" [PGArgument "x" "character varying" False] (PGSingle "void"))
83+
(parsePGFunction "function f(x character varying (256)) returns void") `shouldBe`
84+
(PGFunction "" "f" [PGArgument "x" "character varying" False] (PGSingle "void"))
85+
86+
87+
it "works for types with multiple precisions" $ do
88+
(parsePGFunction "function f(x numeric) returns void") `shouldBe`
89+
(PGFunction "" "f" [PGArgument "x" "numeric" False] (PGSingle "void"))
90+
91+
(parsePGFunction "function f(x numeric(10)) returns void") `shouldBe`
92+
(PGFunction "" "f" [PGArgument "x" "numeric" False] (PGSingle "void"))
93+
94+
(parsePGFunction "function f(x numeric(10,3)) returns void") `shouldBe`
95+
(PGFunction "" "f" [PGArgument "x" "numeric" False] (PGSingle "void"))
96+
97+
98+
it "works for time types" $ do
99+
(parsePGFunction "function f(x time) returns void") `shouldBe`
100+
(PGFunction "" "f" [PGArgument "x" "time" False] (PGSingle "void"))
101+
102+
(parsePGFunction "function f(x time (6)) returns void") `shouldBe`
103+
(PGFunction "" "f" [PGArgument "x" "time" False] (PGSingle "void"))
104+
105+
(parsePGFunction "function f(x time (6) with time zone) returns void") `shouldBe`
106+
(PGFunction "" "f" [PGArgument "x" "time with time zone" False] (PGSingle "void"))
107+
108+
(parsePGFunction "function f(x time with time zone) returns void") `shouldBe`
109+
(PGFunction "" "f" [PGArgument "x" "time with time zone" False] (PGSingle "void"))
110+
111+
(parsePGFunction "function f(x time without time zone) returns void") `shouldBe`
112+
(PGFunction "" "f" [PGArgument "x" "time without time zone" False] (PGSingle "void"))
113+
114+
(parsePGFunction "function f(x timestamp with time zone) returns void") `shouldBe`
115+
(PGFunction "" "f" [PGArgument "x" "timestamp with time zone" False] (PGSingle "void"))
116+
117+
118+
it "works for intervals" $ do
119+
(parsePGFunction "function f(x interval) returns void") `shouldBe`
120+
(PGFunction "" "f" [PGArgument "x" "interval" False] (PGSingle "void"))
121+
122+
(parsePGFunction "function f(x interval month) returns void") `shouldBe`
123+
(PGFunction "" "f" [PGArgument "x" "interval month" False] (PGSingle "void"))
124+
125+
(parsePGFunction "function f(x interval minute to second (4)) returns void") `shouldBe`
126+
(PGFunction "" "f" [PGArgument "x" "interval minute to second" False] (PGSingle "void"))
127+

tests/TestRepresentation.hs

Lines changed: 0 additions & 63 deletions
This file was deleted.

tests/TestTypes.hs

Lines changed: 0 additions & 94 deletions
This file was deleted.

0 commit comments

Comments
 (0)