File: ListSpec.hs

package info (click to toggle)
haskell-rio 0.1.22.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 500 kB
  • sloc: haskell: 4,858; makefile: 3
file content (27 lines) | stat: -rw-r--r-- 1,115 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
{-# LANGUAGE NoImplicitPrelude #-}
module RIO.ListSpec where

import Test.Hspec
import RIO
import qualified RIO.List as List

data TestType = TestType { testTypeContents :: Int }
  deriving (Eq, Show)

testTypeList :: [TestType]
testTypeList = [TestType { testTypeContents = 1 }, TestType { testTypeContents = 0 }]

spec :: Spec
spec = do
  describe "dropPrefix" $ do
    it "present" $ List.dropPrefix "foo" "foobar" `shouldBe` "bar"
    it "absent" $ List.dropPrefix "bar" "foobar" `shouldBe` "foobar"
  describe "dropSuffix" $ do
    it "present" $ List.dropSuffix "bar" "foobar" `shouldBe` "foo"
    it "absent" $ List.dropSuffix "foo" "foobar" `shouldBe` "foobar"
  describe "maximumByMaybe" $ do
    it "should support elements that do not have an Ord instance" $
      List.maximumByMaybe (compare `on` testTypeContents) testTypeList `shouldBe` (Just TestType { testTypeContents = 1})
  describe "minimumByMaybe" $ do
    it "should support elements that do not have an Ord instance" $
      List.minimumByMaybe (compare `on` testTypeContents) testTypeList `shouldBe` (Just TestType { testTypeContents = 0})