import Test.HUnit
import System.IO
import AbsRL
import AbsSRL hiding (Ident)
import qualified AbsSRL
import Control.Monad.State
import Compiler

--SRL文から翻訳されたRL文を表示する関数
tests = TestList
--リストの要素が２つ
    [ "fact 1" ~:trans (ESRL [Bstep (AbsSRL.Sskip) , Bstep (AbsSRL.Sskip)]) ~?= (ERL [Brlblk (Ident "l0") Fentry [] (Jgoto (Ident "l1")),Brlblk (Ident "l1") (Ffrom (Ident "l0")) [AbsRL.Sskip] (Jgoto (Ident "l4")),Brlblk (Ident "l4") (Ffrom (Ident "l1")) [] (Jgoto (Ident "l5")),Brlblk (Ident "l5") (Ffrom (Ident "l4")) [AbsRL.Sskip] (Jgoto (Ident "l2")),Brlblk (Ident "l2") (Ffrom (Ident "l5")) [] (Jgoto (Ident "l3")),Brlblk (Ident "l3") (Ffrom (Ident "l2")) [] Jexit],6)
    ,
--step文
      "fact 2" ~:trans(ESRL [Bstep (AbsSRL.Sskip)]) ~?= (ERL [Brlblk (Ident "l0") Fentry [] (Jgoto (Ident "l1")),Brlblk (Ident "l1") (Ffrom (Ident "l0")) [AbsRL.Sskip] (Jgoto (Ident "l2")),Brlblk (Ident "l2") (Ffrom (Ident "l1")) [] (Jgoto (Ident "l3")),Brlblk (Ident "l3") (Ffrom (Ident "l2")) [] Jexit],4)
    ,
--from文
      "fact 3" ~:trans (ESRL [Bfrom (AbsSRL.Eeq (AbsSRL.Evar (AbsSRL.Ident "k")) (AbsSRL.Evar (AbsSRL.Ident "n"))) [Bstep AbsSRL.Sskip] [Bstep (AbsSRL.SasnMin (AbsSRL.Ident "k") (AbsSRL.Econ 1))] (AbsSRL.Econ 1)]) ~?= (ERL [Brlblk (Ident "l0") Fentry [] (Jgoto (Ident "l1")),Brlblk (Ident "l1") (Ffi (AbsRL.Eeq (AbsRL.Evar (Ident "k")) (AbsRL.Evar (Ident "n"))) (Ident "l0") (Ident "l7")) [] (Jgoto (Ident "l4")),Brlblk (Ident "l2") (Ffrom (Ident "l5")) [] (Jif (AbsRL.Econ 1) (Ident "l3") (Ident "l6")),Brlblk (Ident "l4") (Ffrom (Ident "l1")) [AbsRL.Sskip] (Jgoto (Ident "l5")),Brlblk (Ident "l5") (Ffrom (Ident "l4")) [] (Jgoto (Ident "l2")),Brlblk (Ident "l6") (Ffrom (Ident "l2")) [AbsRL.SasnMin (Ident "k") (AbsRL.Econ 1)] (Jgoto (Ident "l7")),Brlblk (Ident "l7") (Ffrom (Ident "l6")) [] (Jgoto (Ident "l1")),Brlblk (Ident "l3") (Ffrom (Ident "l2")) [] Jexit],8)
     ,
--if文
      "fact 4" ~:trans (ESRL [Bif (AbsSRL.Eeq (AbsSRL.Evar (AbsSRL.Ident "k")) (AbsSRL.Evar (AbsSRL.Ident "n"))) [Bstep AbsSRL.Sskip] [Bstep (AbsSRL.SasnMin (AbsSRL.Ident "k") (AbsSRL.Econ 1))] (AbsSRL.Econ 1)]) ~?= (ERL [Brlblk (Ident "l0") Fentry [] (Jgoto (Ident "l1")),Brlblk (Ident "l1") (Ffrom (Ident "l0")) [] (Jif (AbsRL.Eeq (AbsRL.Evar (Ident "k")) (AbsRL.Evar (Ident "n"))) (Ident "l4") (Ident "l6")),Brlblk (Ident "l2") (Ffi (AbsRL.Econ 1) (Ident "l5") (Ident "l7")) [] (Jgoto (Ident "l3")),Brlblk (Ident "l4") (Ffrom (Ident "l1")) [AbsRL.Sskip] (Jgoto (Ident "l5")),Brlblk (Ident "l5") (Ffrom (Ident "l4")) [] (Jgoto (Ident "l2")),Brlblk (Ident "l6") (Ffrom (Ident "l1")) [AbsRL.SasnMin (Ident "k") (AbsRL.Econ 1)] (Jgoto (Ident "l7")),Brlblk (Ident "l7") (Ffrom (Ident "l6")) [] (Jgoto (Ident "l2")),Brlblk (Ident "l3") (Ffrom (Ident "l2")) [] Jexit],8)
      ]

main =
    runTestText (putTextToHandle stderr False) tests
