-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add coverage for parsing nested parens/lists in field types (#1376)
* Add coverage for nested parens/lists * Add TH spec * Add test modules to cabal file * Fix indentation and add to changelog
- Loading branch information
1 parent
b8484fa
commit f2e930f
Showing
6 changed files
with
81 additions
and
0 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
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
44 changes: 44 additions & 0 deletions
44
persistent/test/Database/Persist/TH/NestedSymbolsInTypeSpec.hs
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,44 @@ | ||
{-# OPTIONS_GHC -Wno-unused-local-binds #-} | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE DerivingStrategies #-} | ||
{-# LANGUAGE FlexibleInstances #-} | ||
{-# LANGUAGE GADTs #-} | ||
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | ||
{-# LANGUAGE OverloadedLabels #-} | ||
{-# LANGUAGE QuasiQuotes #-} | ||
{-# LANGUAGE StandaloneDeriving #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
{-# LANGUAGE UndecidableInstances #-} | ||
|
||
module Database.Persist.TH.NestedSymbolsInTypeSpec where | ||
|
||
import Data.Map | ||
import Database.Persist.TH.NestedSymbolsInTypeSpecImports | ||
import TemplateTestImports | ||
|
||
mkPersist sqlSettings [persistLowerCase| | ||
PathEntitySimple | ||
readOnly (Maybe (SomePath ReadOnly)) | ||
|
||
PathEntityNested | ||
paths (Maybe (Map Text [SomePath ReadWrite])) | ||
|] | ||
|
||
spec :: Spec | ||
spec = describe "NestedSymbolsInType" $ do | ||
it "should support nested parens" $ do | ||
let mkPathEntitySimple :: Maybe (SomePath ReadOnly) -> PathEntitySimple | ||
mkPathEntitySimple = PathEntitySimple | ||
pathEntitySimpleReadOnly' :: PathEntitySimple -> Maybe (SomePath ReadOnly) | ||
pathEntitySimpleReadOnly' = pathEntitySimpleReadOnly | ||
compiles | ||
|
||
it "should support deeply nested parens + square brackets" $ do | ||
let mkPathEntityNested :: Maybe (Map Text [SomePath ReadWrite]) -> PathEntityNested | ||
mkPathEntityNested = PathEntityNested | ||
pathEntityNestedPaths' :: PathEntityNested -> Maybe (Map Text [SomePath ReadWrite]) | ||
pathEntityNestedPaths' = pathEntityNestedPaths | ||
compiles | ||
|
||
compiles :: Expectation | ||
compiles = True `shouldBe` True |
21 changes: 21 additions & 0 deletions
21
persistent/test/Database/Persist/TH/NestedSymbolsInTypeSpecImports.hs
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,21 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE LambdaCase #-} | ||
|
||
module Database.Persist.TH.NestedSymbolsInTypeSpecImports where | ||
|
||
import Data.Proxy | ||
import TemplateTestImports | ||
|
||
data ReadOnly | ||
data ReadWrite | ||
|
||
newtype SomePath a = SomePath Text | ||
|
||
instance PersistFieldSql (SomePath a) where | ||
sqlType _ = SqlString | ||
|
||
instance PersistField (SomePath a) where | ||
toPersistValue (SomePath n) = | ||
toPersistValue n | ||
fromPersistValue v = | ||
SomePath <$> fromPersistValue 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