NonEmptyList.hs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. {-# LANGUAGE TemplateHaskell #-}
  2. module Internal.Utils.NonEmptyList ( tests ) where
  3. import Data.List.NonEmpty (NonEmpty(..), nonEmpty)
  4. import qualified Data.List.NonEmpty as NonEmpty
  5. import Data.Maybe
  6. import Internal.Helpers
  7. import Agda.Utils.Impossible
  8. ------------------------------------------------------------------------
  9. -- * Instances
  10. ------------------------------------------------------------------------
  11. instance Arbitrary a => Arbitrary (NonEmpty a) where
  12. arbitrary = fromMaybe __IMPOSSIBLE__ . nonEmpty . getNonEmpty <$> arbitrary
  13. shrink = map (fromMaybe __IMPOSSIBLE__ . nonEmpty . getNonEmpty) . shrink . (NonEmpty . NonEmpty.toList)
  14. ------------------------------------------------------------------------
  15. -- * Properties
  16. ------------------------------------------------------------------------
  17. prop_NonemptyList_roundtrip :: Eq a => NonEmpty a -> Bool
  18. prop_NonemptyList_roundtrip l = maybe False (l ==) $ nonEmpty $ NonEmpty.toList l
  19. ------------------------------------------------------------------------
  20. -- * All tests
  21. ------------------------------------------------------------------------
  22. -- Template Haskell hack to make the following $allProperties work
  23. -- under ghc-7.8.
  24. return [] -- KEEP!
  25. -- | All tests as collected by 'allProperties'.
  26. --
  27. -- Using 'allProperties' is convenient and superior to the manual
  28. -- enumeration of tests, since the name of the property is added
  29. -- automatically.
  30. tests :: TestTree
  31. tests = testProperties "Internal.Utils.NonemptyList" $allProperties