Skip to content

Commit acd2387

Browse files
committed
Extracted some utility function from CreatedBySpec to Test/Util
1 parent bf10eae commit acd2387

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

grin/src/Test/ExtendedSyntax/Util.hs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,19 @@ module Test.ExtendedSyntax.Util where
55

66
import System.FilePath
77

8+
import Data.Set (Set)
9+
import Data.Map (Map)
10+
import Data.Vector (Vector)
811
import Data.Text (Text)
12+
13+
import qualified Data.Set as Set
14+
import qualified Data.Map as Map
15+
import qualified Data.Vector as V
916
import qualified Data.Text.IO as T (readFile)
1017

1118
import Grin.ExtendedSyntax.Grin
1219
import Grin.ExtendedSyntax.Parse
20+
import AbstractInterpretation.ExtendedSyntax.HeapPointsTo.Result as HPT
1321

1422
import Test.Hspec
1523
import Test.ExtendedSyntax.Assertions
@@ -56,6 +64,30 @@ cNope = Tag C "Nope"
5664
cNopeH :: Tag
5765
cNopeH = Tag C "NopeH"
5866

67+
loc :: HPT.Loc -> TypeSet
68+
loc = tySetFromTypes . pure . HPT.T_Location
69+
70+
unspecLoc :: TypeSet
71+
unspecLoc = tySetFromTypes [HPT.T_UnspecifiedLocation]
72+
73+
mkNode :: [[HPT.SimpleType]] -> Vector (Set HPT.SimpleType)
74+
mkNode = V.fromList . map Set.fromList
75+
76+
mkNodeSet :: [(Tag, [[HPT.SimpleType]])] -> NodeSet
77+
mkNodeSet = HPT.NodeSet . Map.fromList . map (\(t,v) -> (t,mkNode v))
78+
79+
mkTySet :: [(Tag, [[HPT.SimpleType]])] -> TypeSet
80+
mkTySet = tySetFromNodeSet . mkNodeSet
81+
82+
tySetFromNodeSet :: NodeSet -> TypeSet
83+
tySetFromNodeSet = TypeSet mempty
84+
85+
tySetFromTypes :: [HPT.SimpleType] -> TypeSet
86+
tySetFromTypes = flip TypeSet mempty . Set.fromList
87+
88+
mkSimpleMain :: HPT.SimpleType -> (TypeSet, Vector TypeSet)
89+
mkSimpleMain t = (tySetFromTypes [t], mempty)
90+
5991
-- name ~ name of the test case, and also the grin source file
6092
mkBeforeAfterTestCase :: String ->
6193
FilePath ->

grin/test/AbstractInterpretation/ExtendedSyntax/CreatedBySpec.hs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@ spec = do
3636
calcHPTResultWithCBy = _hptResult . calcCByResult
3737
mkProducerSet = ProducerSet . M.fromList . map (\(t,xs) -> (t,S.fromList xs))
3838
emptyProducerSet = mkProducerSet []
39-
unspecLoc = tySetFromTypes [T_UnspecifiedLocation]
40-
loc = tySetFromTypes . pure . T_Location
41-
mkNode = V.fromList . map S.fromList
42-
mkNodeSet = HPT.NodeSet . M.fromList . map (\(t,v) -> (t,mkNode v))
43-
mkTySet = tySetFromNodeSet . mkNodeSet
44-
tySetFromNodeSet = TypeSet mempty
45-
tySetFromTypes = flip TypeSet mempty . S.fromList
46-
mkSimpleMain t = (tySetFromTypes [t], mempty)
4739

4840
describe "Created-By producers are calculated correctly for" $ do
4941
it "pures" $ do

0 commit comments

Comments
 (0)