aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/unit_test/ModuleSourceConstructionTest.hs
blob: fd6984461c1ec45ac85ff01c90a9d6bb0cfb1031 (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
54
55
56
57
module ModuleSourceConstructionTest
  ( test
  )
where

import           BuildModel                     ( RawSource(..)
                                                , Source(..)
                                                , processRawSource
                                                )
import           Hedge                          ( Result
                                                , Test
                                                , assertEquals
                                                , assertThat
                                                , fail'
                                                , givenInput
                                                , then'
                                                , whenTransformed
                                                )
import           System.FilePath                ( (</>) )

test :: IO (Test ())
test = return $ givenInput
  "a module"
  exampleModule
  [ whenTransformed
      "processed to a source"
      processRawSource
      [ then' "it is a Module" checkIsModule
      , then' "its source file name is the same as the original"
              checkModuleSourceFileName
      , then'
        "its object file name is the 'flattened' path of the source file with '.o' appeneded"
        checkModuleObjectFileName
      ]
  ]

exampleModule :: RawSource
exampleModule =
  RawSource moduleSourceFileName' $ unlines ["module some_module", "end module"]

moduleSourceFileName' :: String
moduleSourceFileName' = "some" </> "file" </> "somewhere.f90"

checkIsModule :: Source -> Result
checkIsModule Module{} = assertThat True
checkIsModule _        = assertThat False

checkModuleSourceFileName :: Source -> Result
checkModuleSourceFileName m@(Module{}) =
  assertEquals moduleSourceFileName' $ moduleSourceFileName m
checkModuleSourceFileName _ = fail' "wasn't a Module"

checkModuleObjectFileName :: Source -> Result
checkModuleObjectFileName m@(Module{}) =
  assertEquals ("." </> "some_file_somewhere.f90.o")
    $ (moduleObjectFileName m) "."
checkModuleObjectFileName _ = fail' "wasn't a Module"