packages feed

morley-0.4.0: test/Test/Preprocess.hs

-- | Tests for preprocessing.

module Test.Preprocess
  ( unit_Sample_preprocess
  ) where

import Prelude hiding (EQ)

import Test.HUnit (Assertion, (@?=))

import Michelson.Preprocess
import Michelson.Text
import qualified Michelson.Typed as T
import Michelson.Typed.Instr
import Michelson.Untyped (CT(..))

unit_Sample_preprocess :: Assertion
unit_Sample_preprocess = transformStrings False f sample @?= expected
  where
    f s
      | s == str1 = str5
      | s == str2 = str4
      | s == str4 = str2
      | s == str5 = str1
      | otherwise = s

str1, str2, str3, str4, str5 :: MText
str1 = [mt|aa|]
str2 = [mt|ls|]
str3 = [mt|gulya|]
str4 = [mt|naiks|]
str5 = [mt|eek|]

sample :: T.Contract ('T.Tc 'CString) ('T.Tc 'CString)
sample =
  CAR `Seq`
  PUSH (toStr str1) `Seq`
  DIP (PUSH (toStr str2)) `Seq`
  LEFT @('T.TKey) `Seq` IF_LEFT Nop (PUSH (toStr str4)  `Seq` FAILWITH) `Seq`
  DIP (DIP (PUSH (toStr str5))) `Seq`
  PUSH (toStr str3) `Seq`
  DROP `Seq` DROP `Seq` DROP `Seq` DROP `Seq`
  NIL `Seq` PAIR
  where
    toStr = T.VC . T.CvString

expected :: T.Contract ('T.Tc 'CString) ('T.Tc 'CString)
expected =
  CAR `Seq`
  PUSH (toStr str5) `Seq`
  DIP (PUSH (toStr str4)) `Seq`
  LEFT @('T.TKey) `Seq` IF_LEFT Nop (PUSH (toStr str2)  `Seq` FAILWITH) `Seq`
  DIP (DIP (PUSH (toStr str1))) `Seq`
  PUSH (toStr str3) `Seq`
  DROP `Seq` DROP `Seq` DROP `Seq` DROP `Seq`
  NIL `Seq` PAIR
  where
    toStr = T.VC . T.CvString