2016-12-13 05:47:12 +03:00
|
|
|
module UnitTests(
|
|
|
|
allUnitTests
|
|
|
|
) where
|
|
|
|
|
|
|
|
import Test.HUnit
|
|
|
|
|
|
|
|
import qualified Data.Graph.Inductive.Graph as ING
|
|
|
|
import qualified Data.Graph.Inductive.PatriciaTree as FGR
|
|
|
|
|
2016-12-14 10:13:43 +03:00
|
|
|
import Data.List(foldl', sort, sortOn)
|
2016-12-14 02:26:24 +03:00
|
|
|
|
2016-12-16 09:58:19 +03:00
|
|
|
import Translate(translateStringToSyntaxGraph)
|
2016-12-29 11:15:17 +03:00
|
|
|
import TranslateCore(syntaxGraphToFglGraph, SyntaxGraph(..), SgBind(..))
|
2016-12-27 12:32:51 +03:00
|
|
|
import Types(SgNamedNode(..), Edge(..), SyntaxNode(..),
|
2016-12-14 02:26:24 +03:00
|
|
|
IngSyntaxGraph, NodeName(..), LikeApplyFlavor(..), NameAndPort(..))
|
2016-12-13 05:47:12 +03:00
|
|
|
import qualified GraphAlgorithms
|
2016-12-14 10:21:34 +03:00
|
|
|
import Util(fromMaybeError)
|
2016-12-13 05:47:12 +03:00
|
|
|
|
2016-12-13 10:02:48 +03:00
|
|
|
-- Unit Test Helpers --
|
|
|
|
|
|
|
|
assertAllEqual :: (Eq a, Show a) => [a] -> Test
|
|
|
|
assertAllEqual items = case items of
|
|
|
|
[] -> TestCase $ assertFailure "assertAllEqual: argument is empty list"
|
|
|
|
(first : rest) -> TestList $ fmap (first ~=?) rest
|
|
|
|
|
|
|
|
assertEqualSyntaxGraphs :: [String] -> Test
|
2016-12-16 09:58:19 +03:00
|
|
|
assertEqualSyntaxGraphs ls = assertAllEqual $ fmap (renameGraph . translateStringToSyntaxGraph) ls
|
2016-12-14 02:26:24 +03:00
|
|
|
|
|
|
|
-- BEGIN renameGraph --
|
2016-12-16 04:12:16 +03:00
|
|
|
type NameMap = [(NodeName, NodeName)]
|
|
|
|
|
|
|
|
renameNode
|
|
|
|
:: NameMap -> Int -> SgNamedNode -> (SgNamedNode, NameMap, Int)
|
2016-12-27 12:32:51 +03:00
|
|
|
renameNode nameMap counter (SgNamedNode nodeName syntaxNode) = (newNamedNode, nameMap3, newCounter) where
|
2016-12-16 04:12:16 +03:00
|
|
|
newNodeName = NodeName counter
|
|
|
|
nameMap2 = (nodeName, newNodeName) : nameMap
|
|
|
|
(newSyntaxNode, nameMap3, newCounter) = renameSyntaxNode nameMap2 syntaxNode (counter + 1)
|
2016-12-27 12:32:51 +03:00
|
|
|
newNamedNode = SgNamedNode newNodeName newSyntaxNode
|
2016-12-16 04:12:16 +03:00
|
|
|
|
|
|
|
maybeRenameNodeFolder ::
|
2017-01-02 11:37:27 +03:00
|
|
|
([(Maybe SgNamedNode, String)], NameMap, Int) -> Maybe SgNamedNode -> ([(Maybe SgNamedNode, String)], NameMap, Int)
|
2016-12-16 04:12:16 +03:00
|
|
|
maybeRenameNodeFolder (renamedNodes, nameMap, counter) mNode = case mNode of
|
2017-01-02 11:37:27 +03:00
|
|
|
Nothing -> ((Nothing, ""):renamedNodes, nameMap, counter)
|
|
|
|
Just node -> ((Just newNamedNode, ""):renamedNodes, newNameMap, newCounter) where
|
2016-12-16 04:12:16 +03:00
|
|
|
(newNamedNode, newNameMap, newCounter) = renameNode nameMap counter node
|
|
|
|
|
|
|
|
renameSyntaxNode :: NameMap -> SyntaxNode -> Int -> (SyntaxNode, NameMap, Int)
|
|
|
|
renameSyntaxNode nameMap node counter = case node of
|
|
|
|
-- TODO Keep the Nothing subNodes
|
|
|
|
NestedPatternApplyNode s subNodes -> (NestedPatternApplyNode s (reverse renamedSubNodes), newNameMap, counter2)
|
|
|
|
where
|
2017-01-02 11:37:27 +03:00
|
|
|
(renamedSubNodes, newNameMap, counter2) = foldl' maybeRenameNodeFolder ([], nameMap, counter) (fmap fst subNodes)
|
2016-12-16 04:12:16 +03:00
|
|
|
_ -> (node, nameMap, counter)
|
|
|
|
|
|
|
|
renameNodeFolder :: ([SgNamedNode], NameMap, Int) -> SgNamedNode -> ([SgNamedNode], NameMap, Int)
|
2016-12-27 12:32:51 +03:00
|
|
|
renameNodeFolder state@(renamedNodes, nameMap, counter) node@(SgNamedNode nodeName _) = case lookup nodeName nameMap of
|
2016-12-14 02:26:24 +03:00
|
|
|
Nothing -> (newNamedNode:renamedNodes, newNameMap, newCounter) where
|
2016-12-16 04:12:16 +03:00
|
|
|
(newNamedNode, newNameMap, newCounter) = renameNode nameMap counter node
|
2016-12-14 02:26:24 +03:00
|
|
|
Just _ -> error $ "renameNode: node already in name map. State = " ++ show state ++ " Node = " ++ show node
|
|
|
|
|
2016-12-16 04:12:16 +03:00
|
|
|
renameNamePort :: NameMap -> NameAndPort -> NameAndPort
|
2016-12-14 02:26:24 +03:00
|
|
|
renameNamePort nameMap nameAndPort@(NameAndPort name port) = NameAndPort newName port where
|
|
|
|
newName = fromMaybeError errorStr $ lookup name nameMap
|
|
|
|
errorStr = "renameNamePort: name not found. name = " ++ show name ++ "\nNameAndPort = " ++ show nameAndPort ++ "\nNameMap = " ++ show nameMap
|
|
|
|
|
2016-12-16 04:12:16 +03:00
|
|
|
renameEdge :: NameMap -> Edge -> Edge
|
2016-12-14 02:26:24 +03:00
|
|
|
renameEdge nameMap (Edge options ends (np1, np2)) =
|
|
|
|
Edge options ends (renameNamePort nameMap np1, renameNamePort nameMap np2)
|
|
|
|
|
2016-12-27 03:37:10 +03:00
|
|
|
renameSource :: NameMap -> SgBind -> SgBind
|
|
|
|
renameSource nameMap (SgBind str ref) = SgBind str newRef where
|
2016-12-14 02:26:24 +03:00
|
|
|
newRef = case ref of
|
|
|
|
Left _ -> ref
|
|
|
|
Right namePort@(NameAndPort _ _) -> Right $ renameNamePort nameMap namePort
|
|
|
|
|
2016-12-16 04:12:16 +03:00
|
|
|
renameEmbed :: NameMap -> (NodeName, NodeName) -> (NodeName, NodeName)
|
|
|
|
renameEmbed nameMap (leftName, rightName) = (newLeftName, newRightName) where
|
|
|
|
newLeftName = fromMaybeError "renameEmbed: leftName not found" (lookup leftName nameMap)
|
|
|
|
newRightName = fromMaybeError "renameEmbed: RightName not found" (lookup rightName nameMap)
|
|
|
|
|
2016-12-14 10:13:43 +03:00
|
|
|
-- TODO May want to remove names for sub-nodes
|
|
|
|
removeNames :: SgNamedNode -> SyntaxNode
|
2016-12-27 12:32:51 +03:00
|
|
|
removeNames (SgNamedNode _ syntaxNode) = syntaxNode
|
2016-12-14 10:13:43 +03:00
|
|
|
|
2016-12-16 04:12:16 +03:00
|
|
|
-- TODO Rename sinks
|
2016-12-14 02:26:24 +03:00
|
|
|
-- TODO Add unit tests for renameGraph
|
|
|
|
renameGraph :: SyntaxGraph -> SyntaxGraph
|
|
|
|
renameGraph (SyntaxGraph nodes edges sinks sources embedMap) =
|
2016-12-16 04:12:16 +03:00
|
|
|
SyntaxGraph renamedNodes renamedEdges sinks renamedSources renamedEmbedMap
|
2016-12-14 02:26:24 +03:00
|
|
|
where
|
2016-12-16 04:12:16 +03:00
|
|
|
(renamedNodes, nameMap, _) = foldl' renameNodeFolder ([], [], 0) $ sortOn removeNames nodes
|
2016-12-14 02:26:24 +03:00
|
|
|
renamedEdges = sort $ fmap (renameEdge nameMap) edges
|
|
|
|
renamedSources = sort $ fmap (renameSource nameMap) sources
|
2016-12-16 04:12:16 +03:00
|
|
|
renamedEmbedMap = sort $ fmap (renameEmbed nameMap) embedMap
|
2016-12-14 02:26:24 +03:00
|
|
|
|
|
|
|
-- END renameGraph
|
2016-12-13 10:02:48 +03:00
|
|
|
|
|
|
|
-- END Unit Test Helpers --
|
|
|
|
|
2016-12-14 02:26:24 +03:00
|
|
|
|
2016-12-13 05:47:12 +03:00
|
|
|
-- 0:(toName "app02",ApplyNode 1)->[]
|
|
|
|
-- 1:(toName "f0",LiteralNode "f")->[(Edge {edgeOptions = [], edgeEnds = (EndNone,EndNone), edgeConnection = (NameAndPort (toName "f0") Nothing,NameAndPort (toName "app02") (Just 0))},0)]
|
|
|
|
-- 2:(toName "x1",LiteralNode "x")->[(Edge {edgeOptions = [], edgeEnds = (EndNone,EndNone), edgeConnection = (NameAndPort (toName "x1") Nothing,NameAndPort (toName "app02") (Just 2))},0)]
|
|
|
|
-- 3:(toName "y3",NameNode "y")->[(Edge {edgeOptions = [], edgeEnds = (EndNone,EndNone), edgeConnection = (NameAndPort (toName "y3") Nothing,NameAndPort (toName "app02") (Just 1))},0)]
|
|
|
|
singleApplyGraph :: FGR.Gr SgNamedNode Edge
|
2016-12-16 09:58:19 +03:00
|
|
|
singleApplyGraph = syntaxGraphToFglGraph $ translateStringToSyntaxGraph "y = f x"
|
2016-12-13 05:47:12 +03:00
|
|
|
|
|
|
|
makeTreeRootTest :: (String, [Maybe SgNamedNode], String) -> Test
|
|
|
|
makeTreeRootTest (testName, expected, haskellString) = TestCase $ assertEqual testName expected actual where
|
|
|
|
actual = fmap (ING.lab graph) treeRoots
|
2016-12-16 09:58:19 +03:00
|
|
|
graph = syntaxGraphToFglGraph $ translateStringToSyntaxGraph haskellString
|
2016-12-13 05:47:12 +03:00
|
|
|
treeRoots = GraphAlgorithms.findTreeRoots graph
|
|
|
|
|
|
|
|
treeRootTests :: Test
|
|
|
|
treeRootTests = TestList $ fmap makeTreeRootTest treeRootTestList where
|
|
|
|
treeRootTestList = [
|
2016-12-27 12:32:51 +03:00
|
|
|
("single apply", [Just $ SgNamedNode (NodeName 2) (LikeApplyNode ApplyNodeFlavor 1)], "y = f x"),
|
2016-12-13 05:47:12 +03:00
|
|
|
-- TODO Fix test below
|
2016-12-27 12:32:51 +03:00
|
|
|
("double apply", [Just $ SgNamedNode (NodeName 3) (LikeApplyNode ComposeNodeFlavor 2)], "y = f (g x)"),
|
|
|
|
("recursive apply", [Just $ SgNamedNode (NodeName 3) (LikeApplyNode ComposeNodeFlavor 2)], "y = f (g y)")
|
2016-12-13 05:47:12 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
makeChildCanBeEmbeddedTest ::
|
|
|
|
ING.Graph gr =>
|
|
|
|
(String, IngSyntaxGraph gr, ING.Node, Bool) -> Test
|
|
|
|
makeChildCanBeEmbeddedTest (testName, graph, node, expected) =TestCase $ assertEqual testName expected canBeEmbedded where
|
|
|
|
canBeEmbedded = GraphAlgorithms.nodeWillBeEmbedded graph node
|
|
|
|
|
|
|
|
-- TODO Add more cases for childCanBeEmbeddedTests
|
|
|
|
-- TODO Fix these tests
|
|
|
|
childCanBeEmbeddedTests :: Test
|
|
|
|
childCanBeEmbeddedTests = TestList $ fmap makeChildCanBeEmbeddedTest childCanBeEmbeddedList where
|
|
|
|
childCanBeEmbeddedList = [
|
|
|
|
("single apply, ap", singleApplyGraph, 0, False),
|
|
|
|
("single apply, f", singleApplyGraph, 1, True),
|
|
|
|
("single apply, x", singleApplyGraph, 2, True),
|
|
|
|
("single apply, y", singleApplyGraph, 3, False)
|
|
|
|
]
|
|
|
|
|
|
|
|
collapseUnitTests :: Test
|
|
|
|
collapseUnitTests = TestList[
|
|
|
|
TestLabel "findTreeRoots" treeRootTests
|
|
|
|
--TestLabel "childCanBeEmbedded" childCanBeEmbeddedTests
|
|
|
|
]
|
|
|
|
|
|
|
|
-- Translate unit tests
|
|
|
|
|
2016-12-14 11:30:03 +03:00
|
|
|
applyTests :: Test
|
|
|
|
applyTests = TestList [
|
2016-12-13 10:02:48 +03:00
|
|
|
TestLabel "dollarTests1" $ assertEqualSyntaxGraphs [
|
|
|
|
"y = f x",
|
|
|
|
"y = f $ x"
|
|
|
|
]
|
|
|
|
,
|
|
|
|
TestLabel "dollarTests2" $ assertEqualSyntaxGraphs [
|
|
|
|
"y = f (g x)",
|
|
|
|
"y = f $ (g x)",
|
|
|
|
"y = f $ g $ x",
|
|
|
|
"y = f (g $ x)"
|
|
|
|
]
|
|
|
|
,
|
|
|
|
TestLabel "dollarTests3" $ assertEqualSyntaxGraphs [
|
|
|
|
"y = f 1 (g 2)",
|
|
|
|
"y = f 1 $ g 2"
|
|
|
|
]
|
2016-12-14 11:30:03 +03:00
|
|
|
,
|
|
|
|
assertEqualSyntaxGraphs [
|
|
|
|
"y = f 3 4",
|
|
|
|
"y = (f 3) 4"
|
|
|
|
]
|
2016-12-14 02:26:24 +03:00
|
|
|
]
|
|
|
|
|
2016-12-14 10:21:34 +03:00
|
|
|
composeApplyTests :: Test
|
2016-12-14 02:26:24 +03:00
|
|
|
composeApplyTests = TestList [
|
2016-12-13 10:02:48 +03:00
|
|
|
TestLabel "composeApplyTests1" $ assertEqualSyntaxGraphs [
|
|
|
|
"y = f (g x)",
|
|
|
|
"y = (f . g) x",
|
|
|
|
"y = f . g $ x"
|
|
|
|
]
|
|
|
|
,
|
|
|
|
TestLabel "composeApplyTests2" $ assertEqualSyntaxGraphs [
|
|
|
|
"y = f3 (f2 (f1 x))",
|
|
|
|
"y = f3 . f2 . f1 $ x",
|
|
|
|
"y = (f3 . f2 . f1) x"
|
|
|
|
]
|
2016-12-14 02:26:24 +03:00
|
|
|
]
|
|
|
|
|
2016-12-14 10:21:34 +03:00
|
|
|
infixTests :: Test
|
2016-12-14 02:26:24 +03:00
|
|
|
infixTests = TestList [
|
2016-12-13 12:53:04 +03:00
|
|
|
TestLabel "infixTests1" $ assertEqualSyntaxGraphs [
|
|
|
|
"y = (+) 1 2",
|
|
|
|
"y = ((+) 1) 2",
|
|
|
|
"y = 1 + 2",
|
|
|
|
"y = (1 +) 2"
|
|
|
|
]
|
|
|
|
,
|
|
|
|
TestLabel "infixTests2" $ assertEqualSyntaxGraphs [
|
|
|
|
"y = f (1 +) 2",
|
|
|
|
"y = f ((+) 1) 2"
|
|
|
|
]
|
2016-12-13 05:47:12 +03:00
|
|
|
]
|
|
|
|
|
2016-12-14 10:21:34 +03:00
|
|
|
letTests :: Test
|
2016-12-14 02:26:24 +03:00
|
|
|
letTests = TestList [
|
|
|
|
TestLabel "letTests1" $ assertEqualSyntaxGraphs [
|
|
|
|
"y = f 1",
|
2016-12-14 10:13:43 +03:00
|
|
|
"y = let x = 1 in f x",
|
|
|
|
"y = let {b = a; a = 1} in f b"
|
|
|
|
]
|
|
|
|
,
|
|
|
|
assertEqualSyntaxGraphs [
|
|
|
|
"y = 2",
|
|
|
|
"y = let z = 2 in z",
|
|
|
|
"y = let {z = 2; z2 = z} in z2"
|
|
|
|
]
|
|
|
|
,
|
|
|
|
assertEqualSyntaxGraphs [
|
|
|
|
"y = f y",
|
|
|
|
"y = let x = f x in x"
|
|
|
|
]
|
|
|
|
,
|
|
|
|
assertEqualSyntaxGraphs [
|
|
|
|
"y = f 7 5",
|
|
|
|
"y = let {a = 7; b = f a 5} in b"
|
|
|
|
]
|
|
|
|
,
|
|
|
|
assertEqualSyntaxGraphs [
|
|
|
|
"y x = x",
|
|
|
|
"y x = let z = x in z"
|
|
|
|
]
|
|
|
|
,
|
|
|
|
assertEqualSyntaxGraphs [
|
|
|
|
"fibs = let {y = cons 0 (cons 1 (zipWith (+) y (tail y)))} in y",
|
|
|
|
"fibs = cons 0 (cons 1 (zipWith (+) fibs (tail fibs)))"
|
2016-12-14 02:26:24 +03:00
|
|
|
]
|
2016-12-14 10:13:43 +03:00
|
|
|
,
|
|
|
|
assertEqualSyntaxGraphs [
|
|
|
|
"y x = y x",
|
|
|
|
"y = let {z = (\\x -> y x)} in z",
|
|
|
|
"y = let {z x = y x} in z "
|
|
|
|
]
|
|
|
|
,
|
|
|
|
assertEqualSyntaxGraphs [
|
|
|
|
"y = f 3 y",
|
|
|
|
"y = x where x = f 3 y",
|
|
|
|
"y = let x = f 3 y in x"
|
|
|
|
]
|
|
|
|
,
|
|
|
|
assertEqualSyntaxGraphs [
|
2017-01-02 04:43:00 +03:00
|
|
|
"y x1 = f x1",
|
2016-12-14 10:13:43 +03:00
|
|
|
"y x1 = let {x2 = x1; x3 = x2; x4 = f x3} in x4"
|
|
|
|
]
|
|
|
|
,
|
|
|
|
-- TODO Fix this test. The second line has two apply icons instead of one.
|
|
|
|
-- See VisualTranslateTests/letTests
|
|
|
|
-- assertEqualSyntaxGraphs [
|
|
|
|
-- "y x1 = (f x1) x1",
|
|
|
|
-- "y x1 = let x2 = f x1 in x2 x1"
|
|
|
|
-- ]
|
|
|
|
|
|
|
|
assertEqualSyntaxGraphs [
|
|
|
|
"y x = 3",
|
|
|
|
"y x = let x = 3 in x"
|
|
|
|
]
|
|
|
|
|
|
|
|
-- TODO Fix test. Second line should use compose apply.
|
|
|
|
-- See VisualTranslateTests/letTests
|
|
|
|
-- assertEqualSyntaxGraphs [
|
|
|
|
-- "y = g $ f y",
|
|
|
|
-- "y = let {a = f b; b = g a} in b"
|
|
|
|
-- ]
|
2016-12-14 02:26:24 +03:00
|
|
|
]
|
|
|
|
|
2016-12-14 11:30:03 +03:00
|
|
|
negateTests :: Test
|
|
|
|
negateTests = TestList [
|
|
|
|
assertEqualSyntaxGraphs [
|
|
|
|
"y = negate 1",
|
|
|
|
"y = -1"
|
|
|
|
]
|
|
|
|
,
|
|
|
|
assertEqualSyntaxGraphs [
|
|
|
|
"y = negate ((/) 1 2)",
|
|
|
|
"y = -1/2"
|
|
|
|
]
|
|
|
|
,
|
|
|
|
assertEqualSyntaxGraphs [
|
|
|
|
"y = negate x",
|
|
|
|
"y = -x"
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
enumTests :: Test
|
|
|
|
enumTests = TestList [
|
|
|
|
assertEqualSyntaxGraphs [
|
|
|
|
"y = enumFrom 1",
|
|
|
|
"y = [1..]"
|
|
|
|
]
|
|
|
|
,
|
|
|
|
assertEqualSyntaxGraphs [
|
|
|
|
"y = enumFromThen 1 2",
|
|
|
|
"y = [1,2..]"
|
|
|
|
]
|
|
|
|
,
|
|
|
|
assertEqualSyntaxGraphs [
|
|
|
|
"y = enumFromTo 0 10",
|
|
|
|
"y = [0..10]"
|
|
|
|
]
|
|
|
|
,
|
|
|
|
assertEqualSyntaxGraphs [
|
|
|
|
"y = enumFromThenTo 0 1 10",
|
|
|
|
"y = [0,1..10]"
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
2016-12-14 12:10:18 +03:00
|
|
|
patternTests :: Test
|
2016-12-16 04:12:16 +03:00
|
|
|
patternTests = TestList [
|
2016-12-14 12:10:18 +03:00
|
|
|
assertEqualSyntaxGraphs [
|
|
|
|
"y (F x) = x",
|
|
|
|
"y = (\\(F x) -> x)"
|
|
|
|
]
|
|
|
|
,
|
|
|
|
assertEqualSyntaxGraphs [
|
|
|
|
"y = let {F x y = 3} in x y",
|
|
|
|
"y = let {g = 3; F x y = g} in x y"
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
2016-12-16 04:12:16 +03:00
|
|
|
lambdaTests :: Test
|
|
|
|
lambdaTests = TestList [
|
|
|
|
assertEqualSyntaxGraphs [
|
|
|
|
"y x = (\\z -> x)",
|
|
|
|
"y = (\\x -> (\\z -> x))"
|
|
|
|
]
|
|
|
|
,
|
2017-01-02 04:43:00 +03:00
|
|
|
-- TODO These tests fail since the lambda node has a " tempvar" param name.
|
|
|
|
-- assertEqualSyntaxGraphs [
|
|
|
|
-- "y x = case x of {0 -> 1; 3 -> 5}",
|
|
|
|
-- "{y 0 = 1; y 3 = 5}"
|
|
|
|
-- ]
|
|
|
|
-- ,
|
|
|
|
-- assertEqualSyntaxGraphs [
|
|
|
|
-- "y p = case p of {F x -> x; G x -> x}",
|
|
|
|
-- "{y (F x) = x; y (G x) = x}"
|
|
|
|
-- ]
|
|
|
|
-- ,
|
|
|
|
-- assertEqualSyntaxGraphs [
|
|
|
|
-- -- TODO Since there are no patterns for z, this should just be "case p of"
|
|
|
|
-- "y p z = case (p, z) of {((F x), z') -> x z'; ((G x), z') -> z' x}",
|
|
|
|
-- "{y (F x) z = x z; y (G x) z = z x}"
|
|
|
|
-- ]
|
|
|
|
-- ,
|
2016-12-16 04:12:16 +03:00
|
|
|
assertEqualSyntaxGraphs [
|
|
|
|
"y x = f x y",
|
|
|
|
"y x = z where z = f x y"
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
2016-12-19 08:15:59 +03:00
|
|
|
fmapTests :: Test
|
|
|
|
fmapTests = TestList [
|
|
|
|
assertEqualSyntaxGraphs [
|
2016-12-14 02:26:24 +03:00
|
|
|
"y = fmap f x",
|
|
|
|
"y = f <$> x"
|
|
|
|
]
|
|
|
|
,
|
2016-12-19 08:15:59 +03:00
|
|
|
assertEqualSyntaxGraphs [
|
|
|
|
"y = f1 (fmap f2 (f3 x))",
|
|
|
|
"y = f1 $ f2 <$> f3 x"
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
-- Yes, the commas get their own line
|
|
|
|
translateUnitTests :: Test
|
|
|
|
translateUnitTests = TestList [
|
|
|
|
TestLabel "fmapTest" fmapTests
|
|
|
|
,
|
2016-12-14 11:30:03 +03:00
|
|
|
TestLabel "applyTests" applyTests
|
2016-12-14 02:26:24 +03:00
|
|
|
,
|
|
|
|
TestLabel "composeApplyTests" composeApplyTests
|
|
|
|
,
|
|
|
|
TestLabel "infixTests" infixTests
|
|
|
|
, TestLabel "letTests" letTests
|
2016-12-14 11:30:03 +03:00
|
|
|
, TestLabel "negateTests" negateTests
|
|
|
|
, TestLabel "enumTests" enumTests
|
2016-12-14 12:10:18 +03:00
|
|
|
, TestLabel "patternTests" patternTests
|
2016-12-16 04:12:16 +03:00
|
|
|
, TestLabel "lambdaTests" lambdaTests
|
2016-12-14 02:26:24 +03:00
|
|
|
]
|
|
|
|
|
2016-12-13 05:47:12 +03:00
|
|
|
allUnitTests :: Test
|
|
|
|
allUnitTests = TestList[
|
|
|
|
TestLabel "collapseUnitTests" collapseUnitTests,
|
|
|
|
TestLabel "translateTests" translateUnitTests
|
|
|
|
]
|