diff options
Diffstat (limited to 'test/Unit.hs')
-rw-r--r-- | test/Unit.hs | 95 |
1 files changed, 69 insertions, 26 deletions
diff --git a/test/Unit.hs b/test/Unit.hs index 8bcc702..a72e188 100644 --- a/test/Unit.hs +++ b/test/Unit.hs @@ -1,4 +1,7 @@ -module Unit (unitTests) where +module Unit + ( unitTests + ) +where import Control.Lens import qualified Data.Graph.Inductive as G @@ -8,35 +11,75 @@ import Test.Tasty import Test.Tasty.HUnit import VeriFuzz -unitTests = testGroup "Unit tests" - [ testCase "Transformation of AST" $ - assertEqual "Successful transformation" transformExpectedResult +unitTests = testGroup + "Unit tests" + [ testCase "Transformation of AST" $ assertEqual + "Successful transformation" + transformExpectedResult (transformOf traverseExpr trans transformTestData) ] transformTestData :: Expr -transformTestData = BinOp (BinOp (BinOp (Id "id1") BinAnd (Id "id2")) BinAnd - (BinOp (Id "id1") BinAnd (Id "id2"))) BinAnd - (BinOp (BinOp (BinOp (Id "id1") BinAnd (Id "id2")) BinAnd - (BinOp (Id "id1") BinAnd (BinOp (BinOp (Id "id1") BinAnd (Id "id2")) BinAnd - (BinOp (Id "id1") BinAnd (Id "id2"))))) BinOr - (Concat [Concat [ Concat [Id "id1", Id "id2", Id "id2"], Id "id2", Id "id2" - , Concat [Id "id2", Id "id2", Concat [Id "id1", Id "id2"]] - , Id "id2"], Id "id1", Id "id2"])) +transformTestData = BinOp + (BinOp (BinOp (Id "id1") BinAnd (Id "id2")) BinAnd (BinOp (Id "id1") BinAnd (Id "id2"))) + BinAnd + (BinOp + (BinOp + (BinOp (Id "id1") BinAnd (Id "id2")) + BinAnd + (BinOp + (Id "id1") + BinAnd + (BinOp (BinOp (Id "id1") BinAnd (Id "id2")) BinAnd (BinOp (Id "id1") BinAnd (Id "id2"))) + ) + ) + BinOr + (Concat + [ Concat + [ Concat [Id "id1", Id "id2", Id "id2"] + , Id "id2" + , Id "id2" + , Concat [Id "id2", Id "id2", Concat [Id "id1", Id "id2"]] + , Id "id2" + ] + , Id "id1" + , Id "id2" + ] + ) + ) transformExpectedResult :: Expr -transformExpectedResult = BinOp (BinOp (BinOp (Id "id1") BinAnd (Id "Replaced")) BinAnd - (BinOp (Id "id1") BinAnd (Id "Replaced"))) BinAnd - (BinOp (BinOp (BinOp (Id "id1") BinAnd (Id "Replaced")) BinAnd - (BinOp (Id "id1") BinAnd (BinOp (BinOp (Id "id1") BinAnd (Id "Replaced")) BinAnd - (BinOp (Id "id1") BinAnd (Id "Replaced"))))) BinOr - (Concat [Concat [ Concat [Id "id1", Id "Replaced", Id "Replaced"], Id "Replaced", Id "Replaced" - , Concat [Id "Replaced", Id "Replaced", Concat [Id "id1", Id "Replaced"]] - , Id "Replaced"], Id "id1", Id "Replaced"])) +transformExpectedResult = BinOp + (BinOp (BinOp (Id "id1") BinAnd (Id "Replaced")) BinAnd (BinOp (Id "id1") BinAnd (Id "Replaced"))) + BinAnd + (BinOp + (BinOp + (BinOp (Id "id1") BinAnd (Id "Replaced")) + BinAnd + (BinOp + (Id "id1") + BinAnd + (BinOp (BinOp (Id "id1") BinAnd (Id "Replaced")) + BinAnd + (BinOp (Id "id1") BinAnd (Id "Replaced")) + ) + ) + ) + BinOr + (Concat + [ Concat + [ Concat [Id "id1", Id "Replaced", Id "Replaced"] + , Id "Replaced" + , Id "Replaced" + , Concat [Id "Replaced", Id "Replaced", Concat [Id "id1", Id "Replaced"]] + , Id "Replaced" + ] + , Id "id1" + , Id "Replaced" + ] + ) + ) -trans e = - case e of - Id id -> if id == Identifier "id2" then - Id $ Identifier "Replaced" - else Id id - _ -> e +trans e = case e of + Id id -> if id == Identifier "id2" then Id $ Identifier "Replaced" else Id id + _ -> e |