-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
TrivialCaseEliminationSpec.hs
52 lines (45 loc) · 1.25 KB
/
TrivialCaseEliminationSpec.hs
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
41
42
43
44
45
46
47
48
49
50
51
52
{-# LANGUAGE OverloadedStrings, QuasiQuotes, ViewPatterns #-}
module Transformations.Optimising.TrivialCaseEliminationSpec where
import Transformations.Optimising.TrivialCaseElimination
import Test.Hspec
import Grin.TH
import Test.Test hiding (newVar)
import Test.Assertions
runTests :: IO ()
runTests = hspec spec
spec :: Spec
spec = do
testExprContextE $ \ctx -> do
it "Figure 4.24" $ do
let before = [expr|
case v of
(Ffun a1 a2 a3) -> fun a1 a2 a3
|]
let after = [expr|
do
(Ffun a1 a2 a3) <- pure v
fun a1 a2 a3
|]
trivialCaseElimination (ctx before) `sameAs` (ctx after)
it "bypass" $ do
let before = [expr|
case v of
(Ffun1 a1 a2 a3) -> fun1 a1 a2 a3
#default -> pure 2
|]
let after = [expr|
case v of
(Ffun1 a1 a2 a3) -> fun1 a1 a2 a3
#default -> pure 2
|]
trivialCaseElimination (ctx before) `sameAs` (ctx after)
it "default alternative" $ do
let before = [expr|
case v of
#default -> pure 2
|]
let after = [expr|
do
pure 2
|]
trivialCaseElimination (ctx before) `sameAs` (ctx after)