Skip to content
Snippets Groups Projects
TIRParser.hs 1.23 KiB
Newer Older
  • Learn to ignore specific revisions
  • Orestis Melkonian's avatar
    Orestis Melkonian committed
    {-# LANGUAGE OverloadedStrings #-}
    module TIRParser where
    
    import System.IO.Unsafe (unsafePerformIO)
    import Test.HUnit
    
    import LogicIR.Expr
    import LogicIR.Parser
    
    parserTests =
    
      [ "1 + 1" @?= n 1 .+ n 1
      , "(1 == 1 ? 1 : 2)" @?=
    
    Orestis Melkonian's avatar
    Orestis Melkonian committed
          LIf (n 1 .== n 1) (n 1) (n 2)
    
      , "true \\/ (1 == 1 ? 1 : 2)" @?=
    
    Orestis Melkonian's avatar
    Orestis Melkonian committed
          b True .|| LIf (n 1 .== n 1) (n 1) (n 2)
    
      , "true \\/ (1 == 1 ? 1 : 2)" @?=
    
    Orestis Melkonian's avatar
    Orestis Melkonian committed
          b True .|| LIf (n 1 .== n 1) (n 1) (n 2)
    
      , "(forall x:int :: x:int >= 1 -> x:int + 1 > 1)" @?=
    
    Orestis Melkonian's avatar
    Orestis Melkonian committed
          forall x (v x .>= n 1) (x' .+ n 1 .> n 1)
    
      , "(exists x:int :: x:int >= 1 -> x:int + 1 > 1)" @?=
    
    Orestis Melkonian's avatar
    Orestis Melkonian committed
          exists x (v x .>= n 1) (x' .+ n 1 .> n 1)
    
      , "(exists x:[int] :: true -> x:[int][5] > 1)" @?=
    
    Orestis Melkonian's avatar
    Orestis Melkonian committed
          exists xArr (b True) ((xArr .! n 5) .> n 1)
    
      , "len(x:[int]) > 1 + 1" @?=
    
    Orestis Melkonian's avatar
    Orestis Melkonian committed
          LLen xArr .> n 1 .+ n 1
    
      , "len(x:[int]) == 0 /\\ ! x:[int] == null" @?=
    
    Orestis Melkonian's avatar
    Orestis Melkonian committed
          LLen xArr .== n 0 .&& lnot (LIsnull xArr)
    
      , "len(x:[real]) == 0 /\\ ! x:[real] == null" @?=
          LLen xArr' .== n 0 .&& lnot (LIsnull xArr')
    
      , "len(x:[[real]]) == 0 /\\ ! x:[[real]] == null" @?=
          LLen xArr'' .== n 0 .&& lnot (LIsnull xArr'')
    
    Orestis Melkonian's avatar
    Orestis Melkonian committed
      ]
      where x = var "x" "int"
            x' = v x
            xArr = var "x" "[int]"
    
            xArr' = var "x" "[real]"
    
            xArr'' = var "x" "[[real]]"