Skip to content

Commit

Permalink
Check that stimes works right in corner cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
kindaro committed Apr 13, 2024
1 parent bf0c343 commit 9657d60
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/Tests/Properties.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Tests.Properties.Read (testRead)
import Tests.Properties.Text (testText)
import Tests.Properties.Transcoding (testTranscoding)
import Tests.Properties.Validate (testValidate)
import Tests.Properties.CornerCases (testCornerCases)

tests :: TestTree
tests =
Expand All @@ -30,5 +31,6 @@ tests =
testBuilder,
testLowLevel,
testRead,
testCornerCases,
testValidate
]
36 changes: 36 additions & 0 deletions tests/Tests/Properties/CornerCases.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}

-- | Check that the definitions that are partial crash in the expected ways or
-- return sensible defaults.
module Tests.Properties.CornerCases (testCornerCases) where

import Control.Exception
import Data.Either
import Data.Semigroup
import Data.Text
import Test.QuickCheck
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.QuickCheck (testProperty)
import Tests.QuickCheckUtils ()

testCornerCases :: TestTree
testCornerCases =
testGroup
"corner cases"
[ testGroup
"stimes"
let specimen = stimes :: Integer -> Text -> Text
in [ testProperty
"given a negative number, return empty text"
\(Negative number) text -> do
specimen number text == ""
, testProperty
"given a number that does not fit into Int, evaluate to error call"
\(NonNegative number) text -> (ioProperty . fmap isLeft . try @ErrorCall . evaluate) do
specimen
(fromIntegral (number :: Int) + fromIntegral (maxBound :: Int) + 1)
text
]
]
1 change: 1 addition & 0 deletions text.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ test-suite tests
Tests.Properties.Substrings
Tests.Properties.Text
Tests.Properties.Transcoding
Tests.Properties.CornerCases
Tests.Properties.Validate
Tests.QuickCheckUtils
Tests.RebindableSyntaxTest
Expand Down

0 comments on commit 9657d60

Please sign in to comment.