-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- [x] Add random generation of values for `Module` type - [x] Add a spec that parsing and printing random `Module` values does't change them ADP-3140
- Loading branch information
Showing
5 changed files
with
137 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ on: | |
- synchronize | ||
- opened | ||
- reopened | ||
merge_group: | ||
push: | ||
branches: | ||
- main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{-# LANGUAGE NamedFieldPuns #-} | ||
{-# LANGUAGE RecordWildCards #-} | ||
|
||
module Language.FineTypes.Module.Gen where | ||
|
||
import Prelude | ||
|
||
import Language.FineTypes.Module (Declarations, Module (..)) | ||
import Language.FineTypes.Typ (Typ, TypName) | ||
import Language.FineTypes.Typ.Gen | ||
( Mode (Complete) | ||
, capitalise | ||
, genName | ||
, genTyp | ||
, shrinkTyp | ||
) | ||
import Test.QuickCheck | ||
( Gen | ||
, listOf | ||
) | ||
|
||
import qualified Data.Map as Map | ||
|
||
genModule :: Gen Module | ||
genModule = do | ||
moduleName <- genModuleName | ||
moduleDeclarations <- genDeclarations | ||
pure Module{..} | ||
|
||
genDeclarations :: Gen Declarations | ||
genDeclarations = Map.fromList <$> listOf genDeclaration | ||
|
||
genDeclaration :: Gen (TypName, Typ) | ||
genDeclaration = do | ||
typName <- genTypName | ||
typ <- genTyp Complete 6 | ||
pure (typName, typ) | ||
|
||
genTypName :: Gen TypName | ||
genTypName = capitalise <$> genName | ||
|
||
genModuleName :: Gen String | ||
genModuleName = capitalise <$> genName | ||
|
||
shrinkModule :: Module -> [Module] | ||
shrinkModule m = do | ||
moduleDeclarations <- shrinkDeclarations (moduleDeclarations m) | ||
pure $ m{moduleDeclarations} | ||
|
||
shrinkDeclarations :: Declarations -> [Declarations] | ||
shrinkDeclarations xs = do | ||
(k, v) <- Map.toList xs | ||
Map.singleton k <$> shrinkTyp v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters