

{-# LANGUAGE OverloadedStrings #-}


{-# LANGUAGE CPP #-}

-- {-# OPTIONS_GHC -cpp -DPiForallInstalled #-}


--------------------------------------------------------------------
-- |
-- Copyright :  (c) Andreas Reuleaux 2015
-- License   :  BSD2
-- Maintainer:  Andreas Reuleaux <rx@a-rx.info>
-- Stability :  experimental
-- Portability: non-portable
--
-- This module tests Pire's parser, forget, and untie functionality
--------------------------------------------------------------------



{-
     toggle w/ opts in cabal file

     cpp-options: -DPiForallInstalled

cf
http://stackoverflow.com/questions/6361846/where-can-i-learn-about-ifdef



+ setting ghc/ghci cmd line options (from man ghci)
-cpp  -Dsymbol=value -U  -Usymbol ...


thus eg.
ghci -cpp -DPiForallInstalled


these seem not to work (?)
cabal repl --ghc-options="-cpp -DPiForallInstalled"
anyway NOT cabal repl --ghc-options="--cpp-options=-DPiForallInstalled"


can the -cpp be set on the cabal repl cmd line at all?


but better just toggle w/
-- {-# OPTIONS_GHC -cpp -DPiForallInstalled #-}




-}




{-

usage

./tests.hs
./tests.hs -p sorting
etc

./tests.hs -h

resp.

Pire.Tests.main'

eg.
  :l Pire.Tests
  main' "*"
  or
  main' "basic"
  main' "nat"



meanwhile just
runhaskell -package-db=.cabal-sandbox/x86_64-linux-ghc-7.6.3-packages.conf.d tests.hs -p parsing


-}

module ParserTests.If where


import Test.Tasty


import Test.Tasty.HUnit

import Pire.Syntax.Token
import Pire.Syntax.Ws
import Pire.Syntax

import Pire.NoPos

import Pire.Parser.Expr

import Pire.Forget

import Data.Either.Combinators (fromRight')




import Pire.Untie

import Pire.Parser.ParseUtils
import Pire.Parser.PiParseUtils


#ifdef PiForallInstalled
import qualified PiForall.Parser as P
#endif









-- main' "if -"

ifU = testGroup "parsing if - unit tests" $ tail [

  undefined
  
  , let s = "if{-i-}a{-i'-}then{-t-}b{-t'-}else{-e-}c{-e'-}"
    in
      testGroup ("parsing '"++s++"'...") $ tail [
        
        undefined
        
        
        -- if
            

            
        , testCase ("parse ifExpr '"++s++"'")
          $ (nopos $ parse ifExpr s) @?=  If (V "a") (V "b") (V "c") (Annot Nothing)
              
              
        , testCase ("parse ifExpr_ '"++s++"'")
          $ (nopos $ parse ifExpr_ s)
          -- @?= If_ (IfTok "if" $ Ws "{-i-}") (V_ "a" (Ws "{-i'-}")) (ThenTok $ Ws "{-t-}") (V_ "b" (Ws "{-t'-}")) (ElseTok $ Ws "{-e-}") (V_ "c" (Ws "{-e'-}")) (Annot_ Nothing (Ws ""))
          @?= If_ (IfTok "if" $ Ws "{-i-}") (Ws_ (V "a") (Ws "{-i'-}")) (ThenTok "then" $ Ws "{-t-}") (Ws_ (V "b") (Ws "{-t'-}")) (ElseTok "else" $ Ws "{-e-}") (Ws_ (V "c") (Ws "{-e'-}")) (Annot_ Nothing (Ws ""))
              
              
        , testCase ("parse & forget ifExpr_ '"++s++"'")
          $ (forget $ parse ifExpr_ s) @?= (parse ifExpr s)
              
        ]


#ifdef PiForallInstalled
  ++ tail [

    undefined

    , testCase ("parse & untie ifExpr_ '"++s++"'")
      $ (untie $ parse ifExpr_ s) @?= (piParse P.ifExpr s)
      
    , testCase ("parse & untie expr_ '"++s++"'")
      $ (untie $ parse expr_ s) @?= (piParse P.expr s)
      
    , testCase ("parse & untie expr '"++s++"'")
      $ (untie $ parse expr s) @?= (fromRight' $ P.parseExpr s)
    ]
  
#endif
  





  , let s = "\\ x . if a then b else c  "
    in
      testGroup (">>= for If/If_: \""++s++"\"") $ tail [

        undefined

        
        
        --   make sure, the bind op for If/If_ is defined
        --   trivial equality
        
        , testCase ("parsing expr  '"++s++"'")
          $ (parseP expr s) @?= (parseP expr s)
          
          
        , testCase ("parsing expr_  '"++s++"'")
          $ (parseP expr_ s) @?= (parseP expr_ s)

        ]          
      


#ifdef PiForallInstalled
#endif

  -- indentation!
  ]
