Permalink
Browse files

Got tests up and running again

  • Loading branch information...
1 parent d8d429e commit 06e3269d866536b732d03cfabfa7c5a10757dc43 @snoyberg committed Dec 10, 2009
Showing with 35 additions and 3 deletions.
  1. +22 −0 data-object.cabal
  2. +13 −3 Test.hs → runtests.hs
View
@@ -15,7 +15,15 @@ cabal-version: >= 1.2
build-type: Simple
homepage: http://github.com/snoyberg/data-object/tree/master
+flag buildtests
+ description: Build the executable to run unit tests
+ default: False
+
library
+ if flag(buildtests)
+ Buildable: False
+ else
+ Buildable: True
build-depends: base >= 4 && < 5,
bytestring >= 0.9.1.4 && < 1,
text >= 0.5 && < 0.6,
@@ -30,3 +38,17 @@ library
Data.Object.Scalar
Data.Object.String
ghc-options: -Wall
+
+executable runtests
+ if flag(buildtests)
+ Buildable: True
+ cpp-options: -DTEST
+ build-depends: test-framework,
+ test-framework-quickcheck,
+ test-framework-hunit,
+ HUnit,
+ QuickCheck >= 1 && < 2
+ else
+ Buildable: False
+ ghc-options: -Wall
+ main-is: runtests.hs
@@ -1,6 +1,11 @@
{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
+{-# OPTIONS_GHC -fno-warn-orphans #-}
import Data.Object
+import Data.Object.Text
+import Data.Attempt
+import Data.Convertible.Text
import Test.Framework (defaultMain, testGroup, Test)
--import Test.Framework.Providers.HUnit
@@ -16,14 +21,19 @@ main = defaultMain
testSuite :: Test
testSuite = testGroup "Data.Object"
[ testProperty "propMapKeysValuesId" propMapKeysValuesId
- , testProperty "propToFromRawObject" propToFromRawObject
+ , testProperty "propToFromTextObject" propToFromTextObject
]
propMapKeysValuesId :: Object Int Int -> Bool
propMapKeysValuesId o = mapKeysValues id id o == o
-propToFromRawObject :: Object Int Int -> Bool
-propToFromRawObject o = fromRawObject (toRawObject o) == Just o
+instance FromObject (Object Int Int) Text Text where
+ fromObject = mapKeysValuesM convertAttempt convertAttempt
+instance ToObject (Object Int Int) Text Text where
+ toObject = mapKeysValues convertSuccess convertSuccess
+
+propToFromTextObject :: Object Int Int -> Bool
+propToFromTextObject o = fa (fromTextObject (toTextObject o)) == Just o
instance Arbitrary (Object Int Int) where
coarbitrary = undefined

0 comments on commit 06e3269

Please sign in to comment.