packages feed

tuple-classes-1.0.0: test/Spec.hs

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GHC2021 #-}

module Main (main) where

import Control.Exception  (SomeException, catch, evaluate)
import Data.Tuple.Classes

import DocTest01 qualified
import DocTest02 qualified

main :: IO ()
main = do
    DocTest01.main
    DocTest02.main

    testUncurryNLaziness
    testTupleInsertLaziness

testUncurryNLaziness :: IO ()
testUncurryNLaziness = do
    let f _ _ _ _ = putStrLn "OK"
        test method = method f $ error "not lazy enough"

    test $ uncurryN  @4
    test $ uncurryN' @4

testTupleInsertLaziness :: IO ()
testTupleInsertLaziness = do
    let test x = (True <$ evaluate x) `catch` \(_ :: SomeException) ->
            return False

    lazyConverged <- test $
        ith @2 $ tupleInsert @2 () (undefined :: Solo Int)
    if lazyConverged then putStrLn "OK" else error "too strict"

    strictConverged <- test $
        ith @2 $ tupleInsert @2 () (undefined :: Identity Int)
    if strictConverged then error "not strict enough" else putStrLn "OK"