aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/unit_test/SourceConstructionTest.hs
blob: 18a66de1a4726126f6b732094748d9e2097e37af (plain)
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
module SourceConstructionTest
  ( test
  )
where

import           BuildModel                     ( RawSource(..)
                                                , Source(..)
                                                , processRawSource
                                                )
import           Hedge                          ( Result
                                                , Test
                                                , assertEquals
                                                , assertThat
                                                , fail'
                                                , givenInput
                                                , then'
                                                , whenTransformed
                                                )

test :: IO (Test ())
test = return $ givenInput
  "a program"
  exampleProgram
  [ whenTransformed
      "processed to a source"
      processRawSource
      [ then' "it is a Program" checkIsProgram
      , then' "its source file name is the same as the original"
              checkProgramSourceFileName
      ]
  ]

exampleProgram :: RawSource
exampleProgram = RawSource programSourceFileName' $ unlines
  [ "program some_program"
  , "  implicit none"
  , "  print *, \"Hello, World!\""
  , "end program"
  ]

programSourceFileName' :: String
programSourceFileName' = "some/file/somewhere.f90"

checkIsProgram :: Source -> Result
checkIsProgram s = assertThat $ case s of
  Program{} -> True
  _       -> False

checkProgramSourceFileName :: Source -> Result
checkProgramSourceFileName s = case s of
  p@(Program{}) ->
    assertEquals programSourceFileName' $ programSourceFileName p
  _ -> fail' "wasn't a Program"