Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelpj authored and bitonic committed Sep 21, 2023
1 parent 58cf6bc commit 318901b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions inline-c/inline-c.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ test-suite tests
, inline-c
, parsers
, QuickCheck
, prettyprinter
, raw-strings-qq
, regex-posix
, template-haskell
Expand Down
11 changes: 6 additions & 5 deletions inline-c/test/Language/C/Types/ParseSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import qualified Test.Hspec.QuickCheck
import qualified Test.QuickCheck as QC
import Text.Parser.Char
import Text.Parser.Combinators
import qualified Text.PrettyPrint.ANSI.Leijen as PP
import qualified Prettyprinter as PP
import qualified Prettyprinter.Render.String as PP
import Data.Typeable (Typeable)
import qualified Data.HashSet as HashSet
import Data.List (intercalate)
Expand Down Expand Up @@ -43,7 +44,7 @@ spec = Test.Hspec.QuickCheck.modifyMaxDiscardRatio (const 20) $ do
ParameterDeclarationWithTypeNames typeNames ty <-
arbitraryParameterDeclarationWithTypeNames unCIdentifier
return $ isGoodType ty QC.==>
let ty' = assertParse (cCParserContext True typeNames) parameter_declaration (prettyOneLine ty)
let ty' = assertParse (cCParserContext True typeNames) parameter_declaration (prettyOneLine (PP.pretty ty))
in Types.untangleParameterDeclaration ty == Types.untangleParameterDeclaration ty'
Hspec.it "parses everything which is pretty-printable (Haskell)" $ do
#if MIN_VERSION_QuickCheck(2,9,0)
Expand All @@ -54,7 +55,7 @@ spec = Test.Hspec.QuickCheck.modifyMaxDiscardRatio (const 20) $ do
ParameterDeclarationWithTypeNames typeNames ty <-
arbitraryParameterDeclarationWithTypeNames unHaskellIdentifier
return $ isGoodHaskellIdentifierType typeNames ty QC.==>
let ty' = assertParse (haskellCParserContext True typeNames) parameter_declaration (prettyOneLine ty)
let ty' = assertParse (haskellCParserContext True typeNames) parameter_declaration (prettyOneLine (PP.pretty ty))
in Types.untangleParameterDeclaration ty == Types.untangleParameterDeclaration ty'

------------------------------------------------------------------------
Expand All @@ -68,8 +69,8 @@ assertParse ctx p s =
Left err -> error $ "Parse error (assertParse): " ++ show err ++ " parsed string " ++ show s ++ " with type names " ++ show (cpcTypeNames ctx)
Right x -> x

prettyOneLine :: PP.Pretty a => a -> String
prettyOneLine x = PP.displayS (PP.renderCompact (PP.pretty x)) ""
prettyOneLine :: PP.Doc ann -> String
prettyOneLine x = PP.renderString $ PP.layoutCompact x

isGoodType :: ParameterDeclaration i -> Bool
isGoodType ty =
Expand Down

0 comments on commit 318901b

Please sign in to comment.