@@ -0,0 +1,64 @@
1+import qualified Data.ByteString.Lazy as B
2+import Data.Maybe
3+import qualified Data.UUID as U
4+import qualified Data.UUID.V5 as U
5+import Test.HUnit
6+import Test.QuickCheck
7+import System.IO
8+import System.Random
9+
10+
11+instance Arbitrary U.UUID where
12+ arbitrary = (fst . random) `fmap` rand
13+ coarbitrary = undefined
14+
15+test_null = TestList [
16+ "nil is null" ~: assertBool "" (U.null U.nil),
17+ "namespaceDNS is not null" ~: assertBool "" (not $ U.null U.namespaceDNS)
18+ ]
19+
20+test_nil = TestList [
21+ "nil string" ~: U.toString U.nil @?= "00000000-0000-0000-0000-000000000000",
22+ "nil bytes" ~: U.toByteString U.nil @?= B.pack (replicate 16 0)
23+ ]
24+
25+test_conv = TestList [
26+ "conv bytes to string" ~:
27+ maybe "" (U.toString) (U.fromByteString b16) @?= s16,
28+ "conv string to bytes" ~:
29+ maybe B.empty (U.toByteString) (U.fromString s16) @?= b16
30+ ]
31+ where b16 = B.pack [1..16]
32+ s16 = "01020304-0506-0708-090a-0b0c0d0e0f10"
33+
34+prop_stringRoundTrip = label "String round trip" stringRoundTrip
35+ where stringRoundTrip :: U.UUID -> Bool
36+ stringRoundTrip u = maybe False (== u) $ U.fromString (U.toString u)
37+
38+prop_byteStringRoundTrip = label "ByteString round trip" byteStringRoundTrip
39+ where byteStringRoundTrip :: U.UUID -> Bool
40+ byteStringRoundTrip u = maybe False (== u)
41+ $ U.fromByteString (U.toByteString u)
42+
43+prop_stringLength = label "String length" stringLength
44+ where stringLength :: U.UUID -> Bool
45+ stringLength u = length (U.toString u) == 36
46+
47+prop_byteStringLength = label "ByteString length" byteStringLength
48+ where byteStringLength :: U.UUID -> Bool
49+ byteStringLength u = B.length (U.toByteString u) == 16
50+
51+
52+main :: IO ()
53+main = do
54+ runTestText (putTextToHandle stderr False) (TestList [
55+ test_null,
56+ test_nil,
57+ test_conv
58+ ])
59+ mapM_ quickCheck $ [
60+ prop_stringRoundTrip,
61+ prop_byteStringRoundTrip,
62+ prop_stringLength,
63+ prop_byteStringLength
64+ ]