introduction-test (empty) → 0.0.1.0
raw patch · 4 files changed
+235/−0 lines, 4 filesdep +QuickCheckdep +basedep +bytestringsetup-changed
Dependencies added: QuickCheck, base, bytestring, containers, filepath, genvalidity, genvalidity-containers, genvalidity-hspec, genvalidity-text, hspec, introduction, path, path-io, time
Files
- LICENSE +22/−0
- Setup.hs +2/−0
- introduction-test.cabal +52/−0
- src/TestIntroduction.hs +159/−0
+ LICENSE view
@@ -0,0 +1,22 @@+The MIT License++Copyright (c) 2016 Tom Sydney Kerckhove http://cs-syd.eu++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in+all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+THE SOFTWARE.+
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ introduction-test.cabal view
@@ -0,0 +1,52 @@+name: introduction-test+version: 0.0.1.0+synopsis: A prelude for the tests of safe new projects+description: A prelude for the tests of safe new projects+homepage: https://github.com/NorfairKing/introduction+license: MIT+license-file: LICENSE+author: Tom Sydney Kerckhove+maintainer: syd.kerckhove@gmail.com+copyright: 2016 Tom Sydney Kerckhove+category: Testing+build-type: Simple+cabal-version: >=1.10+tested-with:+ GHC == 8.0.1+Bug-Reports: https://github.com/NorfairKing/introduction/issues++library+ hs-source-dirs:+ src++ exposed-modules:+ TestIntroduction++ ghc-options:+ -Wall+ -fwarn-implicit-prelude++ build-depends:+ base >= 4.9 && < 5 + , introduction++ , hspec >= 2.2 && < 2.3+ , QuickCheck >= 2.8 && < 2.10++ , time >= 1.6 && < 1.7+ , containers >= 0.5 && < 0.6+ , bytestring >= 0.10 && < 0.11+ , filepath >= 1.4 && < 1.5++ , path >= 0.5 && < 0.6+ , path-io >= 1.2 && < 1.3++ , genvalidity >= 0.2.0.4 && < 0.3+ , genvalidity-containers >= 0.1.0.2 && < 0.2+ , genvalidity-text >= 0.1.0.1 && < 0.2+ , genvalidity-hspec >= 0.2.0.5 && < 0.3+ default-language: Haskell2010++source-repository head+ type: git+ location: https://github.com/NorfairKing/introduction
+ src/TestIntroduction.hs view
@@ -0,0 +1,159 @@+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE NoImplicitPrelude #-}+module TestIntroduction+ ( module X+ ) where++import Introduction as X hiding ((.&.))++import Test.Hspec as X+import Test.QuickCheck as X++import Data.GenRelativeValidity as X+import Data.GenValidity as X+import Data.GenValidity.Containers as X+import Data.GenValidity.Text as X+import Test.Validity as X++import Path.Internal++import qualified Data.Time as Time+import qualified Data.Time.Clock.TAI as Time++import Data.Tree (Tree)++import qualified Data.ByteString as SB+import qualified Data.ByteString.Lazy as LB++instance Arbitrary a => Arbitrary (Tree a) where+ arbitrary = genTreeOf arbitrary++instance Arbitrary Text where+ arbitrary = genValid++instance Arbitrary LB.ByteString where+ arbitrary = LB.fromStrict <$> arbitrary++instance Arbitrary SB.ByteString where+ arbitrary = SB.pack <$> arbitrary++instance Arbitrary Time.Day where+ arbitrary = Time.ModifiedJulianDay <$> (2000 +) <$> arbitrary+ shrink = (Time.ModifiedJulianDay <$>) . shrink . Time.toModifiedJulianDay++instance CoArbitrary Time.Day where+ coarbitrary = coarbitrary . Time.toModifiedJulianDay++instance Arbitrary Time.UniversalTime where+ arbitrary = Time.ModJulianDate <$> (2000 +) <$> arbitrary+ shrink = (Time.ModJulianDate <$>) . shrink . Time.getModJulianDate++instance CoArbitrary Time.UniversalTime where+ coarbitrary = coarbitrary . Time.getModJulianDate++instance Arbitrary Time.DiffTime where+ arbitrary = arbitrarySizedFractional+ shrink = shrinkRealFrac++instance CoArbitrary Time.DiffTime where+ coarbitrary = coarbitraryReal++instance Arbitrary Time.UTCTime where+ arbitrary =+ Time.UTCTime+ <$> arbitrary+ <*> (fromRational . toRational <$> choose (0::Double, 86400))+ shrink ut@(Time.UTCTime day dayTime) =+ [ ut { Time.utctDay = d' } | d' <- shrink day ] +++ [ ut { Time.utctDayTime = t' } | t' <- shrink dayTime ]++instance CoArbitrary Time.UTCTime where+ coarbitrary (Time.UTCTime day dayTime) =+ coarbitrary day . coarbitrary dayTime++instance Arbitrary Time.NominalDiffTime where+ arbitrary = arbitrarySizedFractional+ shrink = shrinkRealFrac++instance CoArbitrary Time.NominalDiffTime where+ coarbitrary = coarbitraryReal++instance Arbitrary Time.TimeZone where+ arbitrary =+ Time.TimeZone+ <$> choose (-12*60,14*60) -- utc offset (m)+ <*> arbitrary -- is summer time+ <*> (sequence . replicate 4 $ choose ('A','Z'))+ shrink tz@(Time.TimeZone minutes summerOnly name) =+ [ tz { Time.timeZoneMinutes = m' } | m' <- shrink minutes ] +++ [ tz { Time.timeZoneSummerOnly = s' } | s' <- shrink summerOnly ] +++ [ tz { Time.timeZoneName = n' } | n' <- shrink name ]++instance CoArbitrary Time.TimeZone where+ coarbitrary (Time.TimeZone minutes summerOnly name) =+ coarbitrary minutes . coarbitrary summerOnly . coarbitrary name++instance Arbitrary Time.TimeOfDay where+ arbitrary =+ Time.TimeOfDay+ <$> choose (0, 23) -- hour+ <*> choose (0, 59) -- minute+ <*> (fromRational . toRational <$> choose (0::Double, 60)) -- picoseconds, via double+ shrink tod@(Time.TimeOfDay hour minute second) =+ [ tod { Time.todHour = h' } | h' <- shrink hour ] +++ [ tod { Time.todMin = m' } | m' <- shrink minute ] +++ [ tod { Time.todSec = s' } | s' <- shrink second ]++instance CoArbitrary Time.TimeOfDay where+ coarbitrary (Time.TimeOfDay hour minute second) =+ coarbitrary hour . coarbitrary minute . coarbitrary second++instance Arbitrary Time.LocalTime where+ arbitrary =+ Time.LocalTime+ <$> arbitrary+ <*> arbitrary+ shrink lt@(Time.LocalTime day tod) =+ [ lt { Time.localDay = d' } | d' <- shrink day ] +++ [ lt { Time.localTimeOfDay = t' } | t' <- shrink tod ]++instance CoArbitrary Time.LocalTime where+ coarbitrary (Time.LocalTime day tod) =+ coarbitrary day . coarbitrary tod++instance Arbitrary Time.ZonedTime where+ arbitrary =+ Time.ZonedTime+ <$> arbitrary+ <*> arbitrary+ shrink zt@(Time.ZonedTime lt zone) =+ [ zt { Time.zonedTimeToLocalTime = l' } | l' <- shrink lt ] +++ [ zt { Time.zonedTimeZone = z' } | z' <- shrink zone ]++instance CoArbitrary Time.ZonedTime where+ coarbitrary (Time.ZonedTime lt zone) =+ coarbitrary lt . coarbitrary zone++instance Arbitrary Time.AbsoluteTime where+ arbitrary =+ Time.addAbsoluteTime+ <$> arbitrary+ <*> return Time.taiEpoch+ shrink at =+ (`Time.addAbsoluteTime` at) <$> shrink (Time.diffAbsoluteTime at Time.taiEpoch)++instance CoArbitrary Time.AbsoluteTime where+ coarbitrary = coarbitrary . flip Time.diffAbsoluteTime Time.taiEpoch++instance GenValidity (Path Abs File) where+ genUnchecked = Path <$> arbitrary++instance GenValidity (Path Rel File) where+ genUnchecked = Path <$> arbitrary++instance GenValidity (Path Abs Dir) where+ genUnchecked = Path <$> arbitrary++instance GenValidity (Path Rel Dir) where+ genUnchecked = Path <$> arbitrary+