@@ -0,0 +1,65 @@
1+module Servant.Common.TextSpec where
2+
3+import Servant.Common.Text
4+import Test.Hspec
5+import Test.QuickCheck
6+import Test.QuickCheck.Instances ()
7+import Data.Int ( Int8, Int16, Int32, Int64 )
8+import Data.Text ( Text )
9+import Data.Word ( Word, Word8, Word16, Word32, Word64 )
10+
11+spec :: Spec
12+spec = describe "Servant.Common.Text" $ do
13+
14+ context "FromText and ToText laws" $ do
15+
16+ it "holds for Text" $
17+ property $ \x -> textLaw (x :: Text)
18+
19+ it "holds for String" $
20+ property $ \x -> textLaw (x :: String)
21+
22+ it "holds for Bool" $
23+ property $ \x -> textLaw (x :: Bool)
24+
25+ it "holds for Int" $
26+ property $ \x -> textLaw (x :: Int)
27+
28+ it "holds for Int8" $
29+ property $ \x -> textLaw (x :: Int8)
30+
31+ it "holds for Int16" $
32+ property $ \x -> textLaw (x :: Int16)
33+
34+ it "holds for Int32" $
35+ property $ \x -> textLaw (x :: Int32)
36+
37+ it "holds for Int64" $
38+ property $ \x -> textLaw (x :: Int64)
39+
40+ it "holds for Word" $
41+ property $ \x -> textLaw (x :: Word)
42+
43+ it "holds for Word8" $
44+ property $ \x -> textLaw (x :: Word8)
45+
46+ it "holds for Word16" $
47+ property $ \x -> textLaw (x :: Word16)
48+
49+ it "holds for Word32" $
50+ property $ \x -> textLaw (x :: Word32)
51+
52+ it "holds for Word64" $
53+ property $ \x -> textLaw (x :: Word64)
54+
55+ it "holds for Integer" $
56+ property $ \x -> textLaw (x :: Integer)
57+
58+ it "holds for Double" $
59+ property $ \x -> textLaw (x :: Double)
60+
61+ it "holds for Float" $
62+ property $ \x -> textLaw (x :: Float)
63+
64+textLaw :: (FromText a, ToText a, Eq a) => a -> Bool
65+textLaw a = fromText (toText a) == Just a