<commit_before>{-# LANGUAGE CPP             #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -dsuppress-idinfo -dsuppress-coercions -dsuppress-type-applications -dsuppress-module-prefixes -dsuppress-type-signatures #-}
-- {-# OPTIONS_GHC -dsuppress-uniques #-}
{-# OPTIONS_GHC -fplugin=Test.Inspection.Plugin #-}
module Main where

import           Test.Inspection
import           Test.Tasty
import           Test.Tasty.HUnit

import qualified Database.PostgreSQL.LibPQ                  as PQ
import           Database.PostgreSQL.Simple.FromField
import           Database.PostgreSQL.Simple.TypeInfo        as TI
import           Database.PostgreSQL.Simple.TypeInfo.Macro
import qualified Database.PostgreSQL.Simple.TypeInfo.Static as TI

-------------------------------------------------------------------------------
-- Inspection tests
-------------------------------------------------------------------------------

-- # doesn't work :(
#define TH_MKCOMPATS3(a,b,c) $(mkCompats [TI.a,TI.b,TI.c])
#define IN_MKCOMPATS3(a,b,c) (eq TI.a \/ eq TI.b \/ eq TI.c)

#define TH_INLINETYPOID(n) eq $(inlineTypoid TI.n)
#define IN_INLINETYPOID(n) eq TI.n

-- eta-expansion is required
lhs01, rhs01 :: PQ.Oid -> Bool
lhs01 = TH_MKCOMPATS3(name,text,char)
rhs01 = IN_MKCOMPATS3(nameOid,textOid,charOid)

lhs02, rhs02 :: PQ.Oid -> Bool
lhs02 = TH_INLINETYPOID(name)
rhs02 = IN_INLINETYPOID(nameOid)

eq :: PQ.Oid -> PQ.Oid -> Bool
eq = (==)
{-# INLINE eq #-}

infixr 2 \/
(\/) :: (PQ.Oid -> Bool)
     -> (PQ.Oid -> Bool)
     -> (PQ.Oid -> Bool)
f \/ g = \x -> f x || g x
{-# INLINE (\/) #-}

inspectionTests :: TestTree
inspectionTests = testGroup "inspection"
    [ testCase "mkCompats" $
        assertSuccess $(inspectTest $ 'lhs01 === 'rhs01)
    
    -- byteaOid isn't inlined?
    , testCase "inlineTypoid" $
        assertFailure' $(inspectTest $ 'lhs02 ==- 'rhs02)
    ]

assertSuccess :: Result -> IO ()
assertSuccess (Success _)   = return ()
assertSuccess (Failure err) = assertFailure err

assertFailure' :: Result -> IO ()
assertFailure' (Success err) = assertFailure err
assertFailure' (Failure _)   = return ()

-------------------------------------------------------------------------------
-- Main
-------------------------------------------------------------------------------

main :: IO ()
main = defaultMain $ testGroup "tests"
    [ inspectionTests
    ]<commit_msg>Seems that inspection tests pass on GHC-8.8.1<commit_after>{-# LANGUAGE CPP             #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -dsuppress-idinfo -dsuppress-coercions -dsuppress-type-applications -dsuppress-module-prefixes -dsuppress-type-signatures #-}
-- {-# OPTIONS_GHC -dsuppress-uniques #-}
{-# OPTIONS_GHC -fplugin=Test.Inspection.Plugin #-}
module Main where

import           Test.Inspection
import           Test.Tasty
import           Test.Tasty.HUnit

import qualified Database.PostgreSQL.LibPQ                  as PQ
import           Database.PostgreSQL.Simple.FromField
import           Database.PostgreSQL.Simple.TypeInfo        as TI
import           Database.PostgreSQL.Simple.TypeInfo.Macro
import qualified Database.PostgreSQL.Simple.TypeInfo.Static as TI

-------------------------------------------------------------------------------
-- Inspection tests
-------------------------------------------------------------------------------

-- # doesn't work :(
#define TH_MKCOMPATS3(a,b,c) $(mkCompats [TI.a,TI.b,TI.c])
#define IN_MKCOMPATS3(a,b,c) (eq TI.a \/ eq TI.b \/ eq TI.c)

#define TH_INLINETYPOID(n) eq $(inlineTypoid TI.n)
#define IN_INLINETYPOID(n) eq TI.n

-- eta-expansion is required
lhs01, rhs01 :: PQ.Oid -> Bool
lhs01 = TH_MKCOMPATS3(name,text,char)
rhs01 = IN_MKCOMPATS3(nameOid,textOid,charOid)

lhs02, rhs02 :: PQ.Oid -> Bool
lhs02 = TH_INLINETYPOID(name)
rhs02 = IN_INLINETYPOID(nameOid)

eq :: PQ.Oid -> PQ.Oid -> Bool
eq = (==)
{-# INLINE eq #-}

infixr 2 \/
(\/) :: (PQ.Oid -> Bool)
     -> (PQ.Oid -> Bool)
     -> (PQ.Oid -> Bool)
f \/ g = \x -> f x || g x
{-# INLINE (\/) #-}

inspectionTests :: TestTree
inspectionTests = testGroup "inspection"
    [ testCase "mkCompats" $
        assertSuccess $(inspectTest $ 'lhs01 === 'rhs01)
    
    -- byteaOid isn't inlined?
    , testCase "inlineTypoid" $
#if __GLASGOW_HASKELL__ >= 808
        assertSuccess
#else
        assertFailure'
#endif
          $(inspectTest $ 'lhs02 ==- 'rhs02)
    ]

assertSuccess :: Result -> IO ()
assertSuccess (Success _)   = return ()
assertSuccess (Failure err) = assertFailure err

assertFailure' :: Result -> IO ()
assertFailure' (Success err) = assertFailure err
assertFailure' (Failure _)   = return ()

-------------------------------------------------------------------------------
-- Main
-------------------------------------------------------------------------------

main :: IO ()
main = defaultMain $ testGroup "tests"
    [ inspectionTests
    ]
{'fraction_non_alphanumeric': 0.25297252972529727, 'fraction_numerical': 0.013120131201312012, 'mean_word_length': 1.868312757201646, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2926901', 'n_tokens_mistral': 1671, 'n_tokens_neox': 1587, 'n_words': 330}