1
exercism fetch haskell lens-person

test/Tests.hs

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import Data.Char          (toUpper)
import Data.Time.Calendar (fromGregorian)
import Test.Hspec         (Spec, it, shouldBe)
import Test.Hspec.Runner  (configFastFail, defaultConfig, hspecWith)

import Person
  ( Address (..)
  , Born    (..)
  , Name    (..)
  , Person  (..)
  , bornStreet
  , renameStreets
  , setBirthMonth
  , setCurrentStreet
  )

main :: IO ()
main = hspecWith defaultConfig {configFastFail = True} specs

specs :: Spec
specs = do

    it "bornStreet" $
      (bornStreet . _born) testPerson
      `shouldBe` "Longway"

    it "setCurrentStreet" $
      (_street . _address . setCurrentStreet "Middleroad") testPerson
      `shouldBe` "Middleroad"

    it "setBirthMonth" $
      (_bornOn . _born . setBirthMonth 9) testPerson
      `shouldBe` fromGregorian 1984 9 12

    it "renameStreets birth" $
      (_street . _bornAt . _born . renameStreets (map toUpper)) testPerson
      `shouldBe` "LONGWAY"

    it "renameStreets current" $
      (_street . _address . renameStreets (map toUpper)) testPerson
      `shouldBe` "SHORTLANE"

testPerson :: Person
testPerson = Person {
               _name = Name {
                         _foreNames = "Jane Joanna",
                         _surName   = "Doe"
                       },
               _born = Born {
                         _bornAt = Address {
                                     _street      = "Longway"      ,
                                     _houseNumber = 1024           ,
                                     _place       = "Springfield"  ,
                                     _country     = "United States"
                                   },
                         _bornOn = fromGregorian 1984 4 12
                       },
               _address = Address {
                            _street      = "Shortlane" ,
                            _houseNumber = 2           ,
                            _place       = "Fallmeadow",
                            _country     = "Canada"
                          }
             }