Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add test suite

  • Loading branch information...
commit 6efff7d53f83b923be7b3986ce89d05b844cbddd 1 parent 543183b
@reinerp authored
View
8 Data/Text/Serialize/Show.hs
@@ -1,5 +1,5 @@
{-# LANGUAGE BangPatterns, OverloadedStrings #-}
-module Data.Text.Serialize.Show(Show(..), showParen, buildPrec, preludeShowPrec) where
+module Data.Text.Serialize.Show(Show(..), showLazyText, showParen, buildPrec, preludeShowPrec) where
import Data.Text.Serialize.Show.Class(Show(..))
import Data.Text.Serialize.Show.Generic()
@@ -15,7 +15,7 @@ import qualified Data.ByteString.Char8 as SB
import qualified Data.ByteString.Lazy.Char8 as LB
import qualified Data.Text as S
import qualified Data.Text.Lazy as L
-import Data.Text.Lazy.Builder(Builder)
+import Data.Text.Lazy.Builder(Builder, toLazyText)
import Data.Array
import Data.Monoid
import Data.Word
@@ -24,6 +24,10 @@ import Data.Word
import qualified GHC.Generics
import qualified Data.Typeable
+showLazyText :: Show a => a -> L.Text
+showLazyText = toLazyText . show
+{-# INLINABLE showLazyText #-}
+
showParen :: Bool -> Builder -> Builder
showParen !b !p = (if b then "(" else mempty) <> p <> (if b then ")" else mempty)
{-# INLINABLE showParen #-}
View
BIN  bench/Main
Binary file not shown
View
0  bench/BenchRead.hs → tests/BenchRead.hs
File renamed without changes
View
0  bench/BenchShow.hs → tests/BenchShow.hs
File renamed without changes
View
23 tests/Test.hs
@@ -0,0 +1,23 @@
+{-# LANGUAGE ScopedTypeVariables #-}
+module Main (main) where
+
+import Types(Type(..), types)
+
+import Data.Text.Serialize.Show
+import Prelude hiding (Show(..))
+import qualified Prelude
+import Test.HUnit (assertBool)
+import Test.Framework (Test, defaultMain, testGroup)
+import Test.Framework.Providers.HUnit (testCase)
+import Test.Framework.Providers.QuickCheck2 (testProperty)
+import Data.Typeable
+import Data.Text.Lazy(unpack)
+
+equalsPrelude val = unpack (showLazyText val) == Prelude.show val
+
+testType :: Type -> Test
+testType (Auto name (ty :: a)) = testProperty name (equalsPrelude :: a -> Bool)
+testType (Custom name vals) =
+ testGroup name (map (testCase "" . assertBool "" . equalsPrelude) vals)
+
+main = defaultMain (map testType types)
View
56 tests/Types.hs
@@ -0,0 +1,56 @@
+{-# LANGUAGE ExistentialQuantification, OverloadedStrings, ScopedTypeVariables #-}
+module Types(Type(..), types) where
+
+import Prelude hiding (Read(..), Show(..))
+import qualified Prelude
+import Data.Text.Serialize
+import Data.Typeable
+import qualified Data.Text as S
+import qualified Data.Text.Lazy as T
+import Test.QuickCheck.Arbitrary(Arbitrary)
+
+data Type
+ = forall a.
+ (
+ --Read a,
+ Show a,
+ Prelude.Read a,
+ Prelude.Show a,
+ Eq a,
+ Arbitrary a
+ )
+ => Auto String a
+ | forall a.
+ (
+ --Read a,
+ Show a,
+ Prelude.Read a,
+ Prelude.Show a,
+ Eq a
+ )
+ => Custom String [a]
+
+__ = undefined
+
+auto ty = Auto (Prelude.show (typeOf ty)) ty
+custom (vals :: [ty]) = Custom (Prelude.show (typeOf (__ :: ty))) vals
+
+types = [
+ auto (__ :: Double),
+ auto (__ :: Int),
+ custom ["123456" :: String],
+ auto (__ :: Bool),
+ auto (__ :: [Bool]),
+ auto (__ :: [Double]),
+ auto (__ :: [Int]),
+ auto (__ :: Char),
+ custom [["123456","789012"] :: [String]],
+ custom ["123456" :: T.Text],
+ custom ["123456" :: S.Text],
+ auto (__ :: Either Int Int),
+ auto (__ :: ()),
+ auto (__ :: [()]),
+ auto (__ :: ((),())),
+ auto (__ :: (Int, Int)),
+ auto (__ :: [(Int, Int)])
+ ]
View
50 text-serialise.cabal
@@ -34,29 +34,49 @@ library
text ==0.11.*,
array ==0.4.*
+test-suite test
+ hs-source-dirs: tests
+ main-is: Test.hs
+ type: exitcode-stdio-1.0
+
+ build-depends:
+ base ==4.5.*,
+ HUnit <1.3,
+ QuickCheck >= 2.4.0.1,
+ test-framework >= 0.3.3 && < 0.7,
+ test-framework-hunit ==0.2.*,
+ test-framework-quickcheck2 >= 0.2.9 && < 0.3,
+ text >=0.11.0.5 && <0.12,
+
+ text-serialise
+
benchmark bench-show
type: exitcode-stdio-1.0
- hs-source-dirs: bench
+ hs-source-dirs: tests
main-is: BenchShow.hs
build-depends:
- base,
- criterion,
- random,
- text-serialise,
- text,
- ghc-prim,
- QuickCheck
+ base ==4.5.*,
+ criterion >=0.5 && <0.7,
+ ghc-prim ==0.2.*,
+ random ==1.0.*,
+ QuickCheck >=2.4.0.1 && <2.5,
+ text >=0.11.0.5 && <0.12,
+
+ text-serialise
ghc-options: -O2
benchmark bench-read
type: exitcode-stdio-1.0
- hs-source-dirs: bench
+ hs-source-dirs: tests
main-is: BenchRead.hs
build-depends:
- base,
- criterion,
- text-serialise,
- text,
- ghc-prim,
- attoparsec
+ attoparsec ==0.10.*,
+ base ==4.5.*,
+ criterion >=0.5 && <0.7,
+ ghc-prim ==0.2.*,
+ random ==1.0.*,
+ QuickCheck >=2.4.0.1 && <2.5,
+ text >=0.11.0.5 && <0.12,
+
+ text-serialise
ghc-options: -O2
Please sign in to comment.
Something went wrong with that request. Please try again.