Skip to content

Commit 90ca226

Browse files
burzraehik
authored andcommitted
Add tests for arrays of structs with arrays
1 parent f285e79 commit 90ca226

File tree

1 file changed

+79
-13
lines changed

1 file changed

+79
-13
lines changed

test/Language/Fortran/Analysis/TypesSpec.hs

Lines changed: 79 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,28 @@ spec = do
152152
(Just (CTArray [(Nothing, Just 20)])))]
153153
`shouldNotSatisfy` null
154154

155-
describe "Structure arrays" $ do
155+
describe "structs and arrays" $ do
156156
it "can handle typing assignments to arrays within structs" $ do
157-
let mapping = inferTable structArray
157+
let mapping = inferTable $ structArray False
158158
mapping ! "s" `shouldBe` IDType (Just $ TCustom "strut") (Just CTVariable)
159+
it "can handle typing assignments to elements in arrays of structs" $ do
160+
let mapping = inferTable $ arrayOfStructs False
161+
mapping ! "a" `shouldBe` IDType (Just $ TCustom "elem") (Just $ CTArray [(Nothing, Just 10)])
162+
it "can handle typing assignments to array elements in arrays of structs" $ do
163+
let mapping = inferTable $ arrayOfStructsWithArrays False
164+
mapping ! "arr" `shouldBe` IDType (Just $ TCustom "elem2") (Just $ CTArray [(Nothing, Just 10)])
165+
166+
describe "structs and arrays in common area" $ do
167+
it "can handle typing assignments to arrays within structs in common area" $ do
168+
let mapping = inferTable $ structArray True
169+
mapping ! "s" `shouldBe` IDType (Just $ TCustom "strut") (Just CTVariable)
170+
it "can handle typing assignments to elements in arrays of structs in common area" $ do
171+
let mapping = inferTable $ arrayOfStructs True
172+
mapping ! "a" `shouldBe` IDType (Just $ TCustom "elem") (Just $ CTArray [(Nothing, Just 10)])
173+
it "can handle typing assignments to array elements in arrays of structs in common area" $ do
174+
let mapping = inferTable $ arrayOfStructsWithArrays True
175+
mapping ! "arr" `shouldBe` IDType (Just $ TCustom "elem2") (Just $ CTArray [(Nothing, Just 10)])
176+
159177

160178
ex1 :: ProgramFile ()
161179
ex1 = ProgramFile mi77 [ ex1pu1 ]
@@ -315,17 +333,65 @@ teststrings1 = resetSrcSpan . flip fortran90Parser "" $ unlines [
315333
, "end program teststrings"
316334
]
317335

318-
structArray :: ProgramFile A0
319-
structArray = resetSrcSpan . flip legacy77Parser "" $ unlines [
320-
" subroutine totes"
321-
, " structure /strut/"
322-
, " integer*4 arr(10)"
323-
, " end structure"
324-
, " record /strut/ s"
325-
, " s.arr(7) = 345"
326-
, " print *, 'eyo'"
327-
, " end subroutine totes"
328-
]
336+
commonTransform :: [String] -> String -> [String] -> Bool -> ProgramFile A0
337+
commonTransform front cdecl back common =
338+
resetSrcSpan . flip legacy77Parser "" . unlines . (++) front $
339+
if common then cdecl : back else back
340+
341+
structArray :: Bool -> ProgramFile A0
342+
structArray = commonTransform front cdecl back
343+
where
344+
front = [
345+
" subroutine totes"
346+
, " structure /strut/"
347+
, " integer*4 arr(10)"
348+
, " end structure"
349+
, " record /strut/ s"
350+
]
351+
cdecl =
352+
" common /comm/ s"
353+
back = [
354+
" s.arr(7) = 345"
355+
, " print *, 'eyo'"
356+
, " end subroutine totes"
357+
]
358+
359+
arrayOfStructs :: Bool -> ProgramFile A0
360+
arrayOfStructs = commonTransform front cdecl back
361+
where
362+
front = [
363+
" subroutine totes"
364+
, " structure /elem/"
365+
, " integer val"
366+
, " end structure"
367+
, " record /elem/ a(10)"
368+
]
369+
cdecl =
370+
" common /comm2/ a"
371+
back = [
372+
" a(7).val = 345"
373+
, " print *, 'done'"
374+
, " end subroutine totes"
375+
]
376+
377+
arrayOfStructsWithArrays :: Bool -> ProgramFile A0
378+
arrayOfStructsWithArrays = commonTransform front cdecl back
379+
where
380+
front = [
381+
" subroutine totes"
382+
, " structure /elem2/"
383+
, " integer vals(4)"
384+
, " end structure"
385+
, " record /elem2/ arr(10)"
386+
]
387+
cdecl =
388+
" common /comm3/ arr"
389+
back = [
390+
" arr(7).vals(2) = 45"
391+
, " print *, 'DONE'"
392+
, " end subroutine totes"
393+
]
394+
329395

330396
-- Local variables:
331397
-- mode: haskell

0 commit comments

Comments
 (0)