Skip to content

Commit 32feea0

Browse files
committed
test: new passing test
1 parent f37af07 commit 32feea0

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import Test.QuickCheck (
2525
)
2626
import Test.Samples.Proto.CompilerInput (
2727
compilerInput'doubleDeclaration,
28+
compilerInput'doubleDeclarationDiffMod,
2829
compilerInput'incoherent,
2930
compilerInput'maybe,
3031
)
@@ -43,13 +44,18 @@ test = testGroup "Compiler tests" [testCheck, testFolds, testRefl, testMultipleD
4344
-- Multiple declaration test
4445

4546
testMultipleDec :: TestTree
46-
testMultipleDec = testGroup "Multiple declaration tests." [doubleDeclaration]
47+
testMultipleDec = testGroup "Multiple declaration tests." [doubleDeclaration, passingDoubleDeclaration]
4748

4849
doubleDeclaration :: TestTree
4950
doubleDeclaration =
50-
testCase "Two declarations of the same type was not detected." $
51+
testCase "Two declarations of Maybe within the same module are caught." $
5152
check_ compilerInput'doubleDeclaration @?= Left (P.CompReaderError $ P.MultipleDeclaration (_tyName "Maybe") (_tyName "Maybe"))
5253

54+
passingDoubleDeclaration :: TestTree
55+
passingDoubleDeclaration =
56+
testCase "Two declarations of Maybe within different modules are fine." $
57+
check_ compilerInput'doubleDeclarationDiffMod @?= Right ()
58+
5359
--------------------------------------------------------------------------------
5460
-- Module tests
5561

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
module Test.Samples.Proto.CompilerInput (compilerInput'incoherent, compilerInput'maybe, compilerInput'doubleDeclaration) where
1+
module Test.Samples.Proto.CompilerInput (compilerInput'incoherent, compilerInput'maybe, compilerInput'doubleDeclaration, compilerInput'doubleDeclarationDiffMod) where
22

3-
import Control.Lens ((&), (.~))
3+
import Control.Lens ((%~), (&), (.~))
44
import LambdaBuffers.Compiler.ProtoCompat qualified as P
55
import Test.Samples.Proto.Module (module'incoherent, module'maybe)
6+
import Test.Samples.Proto.SourceInfo
7+
8+
_CompilerInput x = P.CompilerInput {P.modules = x}
69

710
-- | Compiler Input containing 1 module with 1 definition - Maybe.
811
compilerInput'maybe :: P.CompilerInput
9-
compilerInput'maybe = P.CompilerInput {P.modules = [module'maybe]}
12+
compilerInput'maybe = _CompilerInput [module'maybe]
1013

1114
-- | Contains 2 definitions - 1 wrong one.
1215
compilerInput'incoherent :: P.CompilerInput
@@ -15,3 +18,11 @@ compilerInput'incoherent = compilerInput'maybe & #modules .~ [module'incoherent]
1518
-- | Declares maybe twice.
1619
compilerInput'doubleDeclaration :: P.CompilerInput
1720
compilerInput'doubleDeclaration = compilerInput'maybe <> compilerInput'maybe
21+
22+
-- | Declares maybe twice - in different modules
23+
compilerInput'doubleDeclarationDiffMod :: P.CompilerInput
24+
compilerInput'doubleDeclarationDiffMod =
25+
compilerInput'maybe
26+
<> _CompilerInput
27+
[ module'maybe & #moduleName . #parts %~ (P.ModuleNamePart "Module" sourceInfo'empty :)
28+
]

lambda-buffers-compiler/test/Test/Samples/Proto/Module.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ import LambdaBuffers.Compiler.ProtoCompat qualified as P
55
import Test.Samples.Proto.SourceInfo (sourceInfo'empty)
66
import Test.Samples.Proto.TyDef (tyDef'incoherent, tyDef'maybe)
77

8+
_Module mn tds cds ins =
9+
P.Module
10+
{ P.moduleName = mn
11+
, P.typeDefs = tds
12+
, P.classDefs = cds
13+
, P.instances = ins
14+
, P.sourceInfo = sourceInfo'empty
15+
}
16+
817
module'maybe :: P.Module
918
module'maybe =
1019
P.Module

0 commit comments

Comments
 (0)