Skip to content

Commit 992a5e1

Browse files
committed
refactor: small format & naming
1 parent 1d94905 commit 992a5e1

File tree

5 files changed

+183
-89
lines changed

5 files changed

+183
-89
lines changed

lambda-buffers-compiler/test/Test/KindCheck.hs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import Test.Tasty (TestTree, testGroup)
1212
import Test.Tasty.HUnit (assertBool, testCase, (@?=))
1313
import Test.Tasty.QuickCheck (testProperty)
1414
import Test.Utils.CompilerInput (
15+
compilerInput'either,
1516
compilerInput'incoherent,
1617
compilerInput'maybe,
18+
compilerInput'recDef,
1719
)
1820
import Test.Utils.Constructors (_CompilerInput)
1921

@@ -34,18 +36,41 @@ test =
3436

3537
testCheck :: TestTree
3638
testCheck =
37-
testGroup "KindChecker Tests" [trivialKCTest, kcTestMaybe, kcTestFailing]
39+
testGroup
40+
"KindChecker Tests"
41+
[ trivialKCTest
42+
, kcTestMaybe
43+
, kcTestFailing
44+
, kcTestEither
45+
, kcTestMaybe'n'Either
46+
, kcTestFix
47+
]
3848

3949
trivialKCTest :: TestTree
4050
trivialKCTest =
41-
testCase "Empty CompInput should check" $
51+
testCase "Empty Compiler Input kind checks." $
4252
check_ (_CompilerInput []) @?= Right ()
4353

4454
kcTestMaybe :: TestTree
4555
kcTestMaybe =
46-
testCase "Maybe should pass" $
56+
testCase "Kind check Maybe." $
4757
check_ compilerInput'maybe @?= Right ()
4858

59+
kcTestEither :: TestTree
60+
kcTestEither =
61+
testCase "Kind check Either." $
62+
check_ compilerInput'either @?= Right ()
63+
64+
kcTestMaybe'n'Either :: TestTree
65+
kcTestMaybe'n'Either =
66+
testCase "Kind check Maybe and Either." $
67+
check_ (compilerInput'maybe <> compilerInput'either) @?= Right ()
68+
69+
kcTestRec :: TestTree
70+
kcTestRec =
71+
testCase "Kind check recursive def." $
72+
check_ compilerInput'recDef @?= Right ()
73+
4974
kcTestFailing :: TestTree
5075
kcTestFailing =
5176
testCase "This should fail" $

lambda-buffers-compiler/test/Test/Utils/CompilerInput.hs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,35 @@ module Test.Utils.CompilerInput (
33
compilerInput'maybe,
44
compilerInput'undefinedVariable,
55
compilerInput'undefinedLocalTyRef,
6+
compilerInput'either,
67
compilerInput'undefinedForeignTyRef,
8+
compilerInput'recDef,
79
) where
810

911
import LambdaBuffers.Compiler.ProtoCompat qualified as P
1012
import Test.Utils.Constructors (_CompilerInput)
11-
import Test.Utils.Module (module'incoherent, module'maybe, module'undefinedForeignTyRef, module'undefinedLocalTyRef, module'undefinedVar)
13+
import Test.Utils.Module (
14+
module'either,
15+
module'incoherent,
16+
module'maybe,
17+
module'recDef,
18+
module'undefinedForeignTyRef,
19+
module'undefinedLocalTyRef,
20+
module'undefinedVar,
21+
)
1222

1323
-- | Compiler Input containing 1 module with 1 definition - Maybe.
1424
compilerInput'maybe :: P.CompilerInput
1525
compilerInput'maybe = _CompilerInput [module'maybe]
1626

27+
-- | Compiler Input containing 1 module with 1 definition - Either.
28+
compilerInput'either :: P.CompilerInput
29+
compilerInput'either = _CompilerInput [module'either]
30+
31+
-- | Compiler Input containing 1 module with 1 definition - Either.
32+
compilerInput'recDef :: P.CompilerInput
33+
compilerInput'recDef = _CompilerInput [module'recDef]
34+
1735
-- | Contains 2 definitions - 1 wrong one.
1836
compilerInput'incoherent :: P.CompilerInput
1937
compilerInput'incoherent = _CompilerInput [module'maybe, module'incoherent]

lambda-buffers-compiler/test/Test/Utils/Constructors.hs

Lines changed: 85 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -27,138 +27,141 @@ module Test.Utils.Constructors (
2727
import Control.Lens ((^.))
2828
import Data.Map qualified as Map
2929
import Data.Text (Text)
30-
import LambdaBuffers.Compiler.ProtoCompat qualified as P
30+
import LambdaBuffers.Compiler.ProtoCompat qualified as PC
3131
import LambdaBuffers.Compiler.ProtoCompat.Types (SourceInfo)
3232

33-
_CompilerInput :: [P.Module] -> P.CompilerInput
33+
_CompilerInput :: [PC.Module] -> PC.CompilerInput
3434
_CompilerInput ms =
35-
P.CompilerInput
36-
{ P.modules = Map.fromList [(m ^. #moduleName, m) | m <- ms]
35+
PC.CompilerInput
36+
{ PC.modules = Map.fromList [(m ^. #moduleName, m) | m <- ms]
3737
}
3838

39-
_Module :: P.ModuleName -> [P.TyDef] -> [P.ClassDef] -> [P.InstanceClause] -> P.Module
39+
_Module :: PC.ModuleName -> [PC.TyDef] -> [PC.ClassDef] -> [PC.InstanceClause] -> PC.Module
4040
_Module mn tds cds ins =
41-
P.Module
42-
{ P.moduleName = mn
43-
, P.typeDefs = Map.fromList [(td ^. #tyName, td) | td <- tds]
44-
, P.classDefs = Map.fromList [(cd ^. #className, cd) | cd <- cds]
45-
, P.instances = ins
46-
, P.imports = mempty
47-
, P.sourceInfo = P.defSourceInfo
41+
PC.Module
42+
{ PC.moduleName = mn
43+
, PC.typeDefs = Map.fromList [(td ^. #tyName, td) | td <- tds]
44+
, PC.classDefs = Map.fromList [(cd ^. #className, cd) | cd <- cds]
45+
, PC.instances = ins
46+
, PC.imports = mempty
47+
, PC.sourceInfo = PC.defSourceInfo
4848
}
4949

50-
_ModuleName :: [Text] -> P.ModuleName
50+
_ModuleName :: [Text] -> PC.ModuleName
5151
_ModuleName ps =
52-
P.ModuleName
53-
{ P.parts = _ModuleNamePart <$> ps
54-
, P.sourceInfo = P.defSourceInfo
52+
PC.ModuleName
53+
{ PC.parts = _ModuleNamePart <$> ps
54+
, PC.sourceInfo = PC.defSourceInfo
5555
}
5656

57-
_ModuleNamePart :: Text -> P.ModuleNamePart
58-
_ModuleNamePart n = P.ModuleNamePart n P.defSourceInfo
57+
_ModuleNamePart :: Text -> PC.ModuleNamePart
58+
_ModuleNamePart n = PC.ModuleNamePart n PC.defSourceInfo
5959

60-
_TyName :: Text -> P.TyName
61-
_TyName x = P.TyName x P.defSourceInfo
60+
_TyName :: Text -> PC.TyName
61+
_TyName x = PC.TyName x PC.defSourceInfo
6262

63-
_VarName :: Text -> P.VarName
64-
_VarName = flip _VarName' P.defSourceInfo
63+
_VarName :: Text -> PC.VarName
64+
_VarName = flip _VarName' PC.defSourceInfo
6565

66-
_VarName' :: Text -> P.SourceInfo -> P.VarName
67-
_VarName' x s = P.VarName {P.name = x, P.sourceInfo = s}
66+
_VarName' :: Text -> PC.SourceInfo -> PC.VarName
67+
_VarName' x s = PC.VarName {PC.name = x, PC.sourceInfo = s}
6868

69-
_TyVar :: Text -> P.TyVar
70-
_TyVar = P.TyVar . _VarName
69+
_TyVar :: Text -> PC.TyVar
70+
_TyVar = PC.TyVar . _VarName
7171

7272
-- | TyVar with Source Info - for error precision testing.
73-
_TyVar' :: Text -> P.SourceInfo -> P.TyVar
74-
_TyVar' x s = P.TyVar {P.varName = _VarName' x s}
73+
_TyVar' :: Text -> PC.SourceInfo -> PC.TyVar
74+
_TyVar' x s = PC.TyVar {PC.varName = _VarName' x s}
7575

76-
_TyVarI :: Text -> P.Ty
77-
_TyVarI = P.TyVarI . _TyVar
76+
_TyVarI :: Text -> PC.Ty
77+
_TyVarI = PC.TyVarI . _TyVar
7878

7979
-- | TyVar with Source Info - for error precision testing.
80-
_TyVarI' :: Text -> SourceInfo -> P.Ty
81-
_TyVarI' x s = P.TyVarI $ P.TyVar {P.varName = _VarName' x s}
80+
_TyVarI' :: Text -> SourceInfo -> PC.Ty
81+
_TyVarI' x s = PC.TyVarI $ PC.TyVar {PC.varName = _VarName' x s}
8282

83-
_SourceInfo :: Int -> Int -> P.SourceInfo
84-
_SourceInfo x y = P.SourceInfo {P.file = "DefaultFile", P.posFrom = _SourcePosition x, P.posTo = _SourcePosition y}
83+
_SourceInfo :: Int -> Int -> PC.SourceInfo
84+
_SourceInfo x y = PC.SourceInfo {PC.file = "DefaultFile", PC.posFrom = _SourcePosition x, PC.posTo = _SourcePosition y}
8585

86-
_SourcePosition :: Int -> P.SourcePosition
87-
_SourcePosition x = P.SourcePosition x (x + 1)
86+
_SourcePosition :: Int -> PC.SourcePosition
87+
_SourcePosition x = PC.SourcePosition x (x + 1)
8888

89-
_TupleI :: [P.Ty] -> P.Product
89+
_TupleI :: [PC.Ty] -> PC.Product
9090
_TupleI x =
91-
P.TupleI $
92-
P.Tuple
93-
{ P.fields = x
94-
, P.sourceInfo = P.defSourceInfo
91+
PC.TupleI $
92+
PC.Tuple
93+
{ PC.fields = x
94+
, PC.sourceInfo = PC.defSourceInfo
9595
}
9696

97-
_Constructor :: Text -> P.Product -> P.Constructor
97+
_Constructor :: Text -> PC.Product -> PC.Constructor
9898
_Constructor c f =
99-
P.Constructor
100-
{ P.constrName = _ConstrName c
101-
, P.product = f
99+
PC.Constructor
100+
{ PC.constrName = _ConstrName c
101+
, PC.product = f
102102
}
103103

104-
_ConstrName :: Text -> P.ConstrName
104+
_ConstrName :: Text -> PC.ConstrName
105105
_ConstrName x =
106-
P.ConstrName
107-
{ P.name = x
108-
, P.sourceInfo = P.defSourceInfo
106+
PC.ConstrName
107+
{ PC.name = x
108+
, PC.sourceInfo = PC.defSourceInfo
109109
}
110110

111-
_Sum :: [(Text, P.Product)] -> P.TyBody
111+
_Sum :: [(Text, PC.Product)] -> PC.TyBody
112112
_Sum cs =
113-
P.SumI $
114-
P.Sum
113+
PC.SumI $
114+
PC.Sum
115115
{ constructors = Map.fromList [(ctor ^. #constrName, ctor) | (cn, cp) <- cs, ctor <- [_Constructor cn cp]]
116-
, sourceInfo = P.defSourceInfo
116+
, sourceInfo = PC.defSourceInfo
117117
}
118118

119-
_TyAbs :: [(Text, P.KindType)] -> [(Text, P.Product)] -> P.TyAbs
119+
_TyApp :: PC.Ty
120+
_TyApp = PC.TyAppI
121+
122+
_TyAbs :: [(Text, PC.KindType)] -> [(Text, PC.Product)] -> PC.TyAbs
120123
_TyAbs args body =
121-
P.TyAbs
122-
{ P.tyArgs = Map.fromList [(ta ^. #argName, ta) | ta <- _TyArg <$> args]
123-
, P.tyBody = _Sum body
124-
, sourceInfo = P.defSourceInfo
124+
PC.TyAbs
125+
{ PC.tyArgs = Map.fromList [(ta ^. #argName, ta) | ta <- _TyArg <$> args]
126+
, PC.tyBody = _Sum body
127+
, sourceInfo = PC.defSourceInfo
125128
}
126129

127-
_TyArg :: (Text, P.KindType) -> P.TyArg
130+
_TyArg :: (Text, PC.KindType) -> PC.TyArg
128131
_TyArg (a, k) =
129-
P.TyArg
130-
{ P.argName = P.VarName a P.defSourceInfo
131-
, P.argKind = P.Kind {P.kind = k}
132-
, P.sourceInfo = P.defSourceInfo
132+
PC.TyArg
133+
{ PC.argName = PC.VarName a PC.defSourceInfo
134+
, PC.argKind = PC.Kind {PC.kind = k}
135+
, PC.sourceInfo = PC.defSourceInfo
133136
}
134137

135-
_Type :: P.KindType
136-
_Type = P.KindRef P.KType
138+
_Type :: PC.KindType
139+
_Type = PC.KindRef PC.KType
137140

138-
_TyDef :: P.TyName -> P.TyAbs -> P.TyDef
139-
_TyDef name ab = P.TyDef {P.tyName = name, P.tyAbs = ab, sourceInfo = P.defSourceInfo}
141+
_TyDef :: PC.TyName -> PC.TyAbs -> PC.TyDef
142+
_TyDef name ab = PC.TyDef {PC.tyName = name, PC.tyAbs = ab, sourceInfo = PC.defSourceInfo}
140143

141-
_TyRefILocal :: Text -> P.Ty
142-
_TyRefILocal x = P.TyRefI $ P.LocalI $ _LocalRef x
144+
_TyRefILocal :: Text -> PC.Ty
145+
_TyRefILocal x = PC.TyRefI $ PC.LocalI $ _LocalRef x
143146

144-
_LocalRef :: Text -> P.LocalRef
145-
_LocalRef = flip _LocalRef' P.defSourceInfo
147+
_LocalRef :: Text -> PC.LocalRef
148+
_LocalRef = flip _LocalRef' PC.defSourceInfo
146149

147150
-- | LocalRef with Source Info - for error precision testing.
148-
_LocalRef' :: Text -> P.SourceInfo -> P.LocalRef
151+
_LocalRef' :: Text -> PC.SourceInfo -> PC.LocalRef
149152
_LocalRef' x s =
150-
P.LocalRef
151-
{ P.tyName = P.TyName {P.name = x, sourceInfo = s}
152-
, P.sourceInfo = s
153+
PC.LocalRef
154+
{ PC.tyName = PC.TyName {PC.name = x, sourceInfo = s}
155+
, PC.sourceInfo = s
153156
}
154157

155-
_ForeignRef :: Text -> [Text] -> P.ForeignRef
156-
_ForeignRef n m = _ForeignRef' n (_ModuleName m) P.defSourceInfo
158+
_ForeignRef :: Text -> [Text] -> PC.ForeignRef
159+
_ForeignRef n m = _ForeignRef' n (_ModuleName m) PC.defSourceInfo
157160

158-
_ForeignRef' :: Text -> P.ModuleName -> P.SourceInfo -> P.ForeignRef
161+
_ForeignRef' :: Text -> PC.ModuleName -> PC.SourceInfo -> PC.ForeignRef
159162
_ForeignRef' x m s =
160-
P.ForeignRef
161-
{ P.tyName = P.TyName {P.name = x, sourceInfo = s}
162-
, P.moduleName = m
163-
, P.sourceInfo = s
163+
PC.ForeignRef
164+
{ PC.tyName = PC.TyName {PC.name = x, sourceInfo = s}
165+
, PC.moduleName = m
166+
, PC.sourceInfo = s
164167
}

lambda-buffers-compiler/test/Test/Utils/Module.hs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,35 @@
1-
module Test.Utils.Module (module'maybe, module'incoherent, module'undefinedVar, module'undefinedLocalTyRef, module'undefinedForeignTyRef) where
1+
module Test.Utils.Module (
2+
module'maybe,
3+
module'incoherent,
4+
module'undefinedVar,
5+
module'undefinedLocalTyRef,
6+
module'undefinedForeignTyRef,
7+
module'either,
8+
module'recDef,
9+
) where
210

311
import LambdaBuffers.Compiler.ProtoCompat qualified as P
412
import Test.Utils.Constructors (_Module, _ModuleName)
5-
import Test.Utils.TyDef (tyDef'incoherent, tyDef'maybe, tyDef'undefinedForeignTyRef, tyDef'undefinedLocalTyRef, tyDef'undefinedVar)
13+
import Test.Utils.TyDef (
14+
tyDef'either,
15+
tyDef'incoherent,
16+
tyDef'maybe,
17+
tyDef'recDef,
18+
tyDef'undefinedForeignTyRef,
19+
tyDef'undefinedLocalTyRef,
20+
tyDef'undefinedVar,
21+
)
622

723
-- _Module mn tds cds ins =
824

925
module'maybe :: P.Module
10-
module'maybe = _Module (_ModuleName ["Module"]) [tyDef'maybe] mempty mempty
26+
module'maybe = _Module (_ModuleName ["Prelude"]) [tyDef'maybe] mempty mempty
27+
28+
module'either :: P.Module
29+
module'either = _Module (_ModuleName ["Prelude"]) [tyDef'either] mempty mempty
30+
31+
module'recDef :: P.Module
32+
module'recDef = _Module (_ModuleName ["Prelude"]) [tyDef'recDef] mempty mempty
1133

1234
{- | 1 Module containing
1335
Maybe = ...

lambda-buffers-compiler/test/Test/Utils/TyDef.hs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ module Test.Utils.TyDef (
77
tyDef'undefinedLocalTyRef'TyRef,
88
tyDef'undefinedForeignTyRef,
99
tyDef'undefinedForeignTyRef'TyRef,
10+
tyDef'recDef,
11+
tyDef'either,
1012
) where
1113

1214
import LambdaBuffers.Compiler.ProtoCompat.Types (Ty (TyVarI))
@@ -38,6 +40,30 @@ tyDef'maybe =
3840
]
3941
)
4042

43+
tyDef'either :: P.TyDef
44+
tyDef'either =
45+
_TyDef
46+
(_TyName "Either")
47+
( _TyAbs
48+
[ ("a", _Type)
49+
, ("b", _Type)
50+
]
51+
[ ("Left", _TupleI [_TyVarI "a"])
52+
, ("Right", _TupleI [_TyVarI "b"])
53+
]
54+
)
55+
56+
tyDef'recDef :: P.TyDef
57+
tyDef'recDef =
58+
_TyDef
59+
(_TyName "F")
60+
( _TyAbs
61+
[ ("a", _Type)
62+
]
63+
[ ("Rec", _TupleI [_TyRefILocal "F"])
64+
]
65+
)
66+
4167
-- | B a = B Maybe
4268
tyDef'incoherent :: P.TyDef
4369
tyDef'incoherent =

0 commit comments

Comments
 (0)