blob: de4fa16e1bc1a56fc8332477c9b6bc964f7ec77a (
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
|
module Unit (unitTests) where
import Control.Lens
import qualified Data.Graph.Inductive as G
import Data.Text (Text)
import qualified Data.Text as T
import Test.Tasty
import Test.Tasty.HUnit
import Test.VeriFuzz
unitTests = testGroup "Unit tests"
[ testCase "Transformation of AST" $
assertEqual "Successful transformation" transformExpectedResult
(transformOf traverseExpr trans transformTestData)
]
primExpr :: Text -> Expression
primExpr = PrimExpr . PrimId . Identifier
transformTestData :: Expression
transformTestData = OpExpr (OpExpr (OpExpr (primExpr "id1") BinAnd (primExpr "id2")) BinAnd
(OpExpr (primExpr "id1") BinAnd (primExpr "id2"))) BinAnd
(OpExpr (OpExpr (primExpr "id1") BinAnd (primExpr "id2")) BinAnd
(OpExpr (primExpr "id1") BinAnd (OpExpr (OpExpr (primExpr "id1") BinAnd (primExpr "id2")) BinAnd
(OpExpr (primExpr "id1") BinAnd (primExpr "id2")))))
transformExpectedResult :: Expression
transformExpectedResult = OpExpr (OpExpr (OpExpr (primExpr "id1") BinAnd (primExpr "Replaced")) BinAnd
(OpExpr (primExpr "id1") BinAnd (primExpr "Replaced"))) BinAnd
(OpExpr (OpExpr (primExpr "id1") BinAnd (primExpr "Replaced")) BinAnd
(OpExpr (primExpr "id1") BinAnd (OpExpr (OpExpr (primExpr "id1") BinAnd
(primExpr "Replaced")) BinAnd
(OpExpr (primExpr "id1") BinAnd (primExpr "Replaced")))))
trans e =
case e of
PrimExpr (PrimId id) -> if id == Identifier "id2" then
PrimExpr . PrimId $ Identifier "Replaced"
else PrimExpr (PrimId id)
_ -> e
|