@@ -45,6 +45,9 @@ import Data.Constraint
4545import GHC.Types
4646import Type.Reflection (SomeTypeRep (.. ), TypeRep , typeRepKind , typeRep , pattern TypeRep )
4747
48+ import Test.Hspec
49+ import Test.QuickCheck
50+
4851--------------------------------------------------------------------------------
4952-- Untyped AST
5053
@@ -413,17 +416,17 @@ applyTypes (SomeTypeRep f) (SomeTypeRep a) = do
413416 pure $ SomeTypeRep $ Type. App f a
414417 | otherwise -> Nothing
415418
416- -- desugarTypeSpec :: Spec
417- -- desugarTypeSpec = do
418- -- it "desugarType" $ do
419- -- shouldBe (try "Bool") (Right (SomeStarType $ typeRep @Bool))
420- -- shouldBe (try "Int") (Right (SomeStarType $ typeRep @Int))
421- -- shouldBe (try "Bool -> Int") (Right (SomeStarType $ typeRep @(Bool -> Int)))
422- -- shouldBe (try "()") (Right (SomeStarType $ typeRep @()))
423- -- shouldBe (try "[Int]") (Right (SomeStarType $ typeRep @[Int]))
424- -- where try e = case fmap desugarType $ HSE.parseType e of
425- -- HSE.ParseOk r -> r
426- -- _ -> error "Parse failed."
419+ desugarTypeSpec :: Spec
420+ desugarTypeSpec = do
421+ it " desugarType" $ do
422+ shouldBe (try " Bool" ) (Right (SomeStarType $ typeRep @ Bool ))
423+ shouldBe (try " Int" ) (Right (SomeStarType $ typeRep @ Int ))
424+ shouldBe (try " Bool -> Int" ) (Right (SomeStarType $ typeRep @ (Bool -> Int )))
425+ shouldBe (try " ()" ) (Right (SomeStarType $ typeRep @ () ))
426+ shouldBe (try " [Int]" ) (Right (SomeStarType $ typeRep @ [Int ]))
427+ where try e = case fmap desugarType $ HSE. parseType e of
428+ HSE. ParseOk r -> r
429+ _ -> error " Parse failed."
427430
428431--------------------------------------------------------------------------------
429432-- Desugar all bindings
@@ -454,19 +457,19 @@ stronglyConnected =
454457 Graph. stronglyConnComp .
455458 map \ thing@ (name, e) -> (thing, name, freeVariables e)
456459
457- -- anyCyclesSpec :: Spec
458- -- anyCyclesSpec = do
459- -- it "anyCycles" do
460- -- shouldBe (try [("foo","\\z -> x * Z.y"), ("bar","\\z -> Main.bar * Z.y")]) True
461- -- shouldBe (try [("foo","\\z -> Main.bar * Z.y"), ("bar","\\z -> Main.foo * Z.y")]) True
462- -- shouldBe (try [("foo","\\z -> x * Z.y"), ("bar","\\z -> Main.mu * Z.y")]) False
463- -- shouldBe (try [("foo","\\z -> x * Z.y"), ("bar","\\z -> Main.foo * Z.y")]) False
460+ anyCyclesSpec :: Spec
461+ anyCyclesSpec = do
462+ it " anyCycles" do
463+ shouldBe (try [(" foo" ," \\ z -> x * Z.y" ), (" bar" ," \\ z -> Main.bar * Z.y" )]) True
464+ shouldBe (try [(" foo" ," \\ z -> Main.bar * Z.y" ), (" bar" ," \\ z -> Main.foo * Z.y" )]) True
465+ shouldBe (try [(" foo" ," \\ z -> x * Z.y" ), (" bar" ," \\ z -> Main.mu * Z.y" )]) False
466+ shouldBe (try [(" foo" ," \\ z -> x * Z.y" ), (" bar" ," \\ z -> Main.foo * Z.y" )]) False
464467
465- -- where
466- -- try named =
467- -- case traverse (\(n, e) -> (n, ) <$> HSE.parseExp e) named of
468- -- HSE.ParseOk decls -> anyCycles decls
469- -- _ -> error "Parse failed."
468+ where
469+ try named =
470+ case traverse (\ (n, e) -> (n, ) <$> HSE. parseExp e) named of
471+ HSE. ParseOk decls -> anyCycles decls
472+ _ -> error " Parse failed."
470473
471474--------------------------------------------------------------------------------
472475-- Get free variables of an HSE expression
@@ -480,21 +483,21 @@ freeVariables =
480483 HSE. Qual _ (HSE. ModuleName _ " Main" ) (HSE. Ident _ name) -> pure name
481484 _ -> Nothing
482485
483- -- freeVariablesSpec :: Spec
484- -- freeVariablesSpec = do
485- -- it "freeVariables" $ shouldBe (try "\\z -> Main.x * Z.y") ["x"]
486- -- where try e = case fmap freeVariables $ HSE.parseExp e of
487- -- HSE.ParseOk names -> names
488- -- _ -> error "Parse failed."
486+ freeVariablesSpec :: Spec
487+ freeVariablesSpec = do
488+ it " freeVariables" $ shouldBe (try " \\ z -> Main.x * Z.y" ) [" x" ]
489+ where try e = case fmap freeVariables $ HSE. parseExp e of
490+ HSE. ParseOk names -> names
491+ _ -> error " Parse failed."
489492
490493--------------------------------------------------------------------------------
491494-- Test everything
492495
493- -- spec :: Spec
494- -- spec = do
495- -- anyCyclesSpec
496- -- freeVariablesSpec
497- -- desugarTypeSpec
496+ spec :: Spec
497+ spec = do
498+ anyCyclesSpec
499+ freeVariablesSpec
500+ desugarTypeSpec
498501
499502--------------------------------------------------------------------------------
500503-- Supported type constructors
0 commit comments