content: module APL.Parser_Tests (tests) where
  
  import APL.AST (Exp (..))
  import APL.Parser (parseAPL)
  import Test.Tasty (TestTree, testGroup)
  import Test.Tasty.HUnit (assertFailure, testCase, (@?=))
  
  -- Test that some string parses to the provided Exp.
  parserTest :: String -> Exp -> TestTree
  parserTest s e =
    testCase s $
      case parseAPL "input" s of
        Left err -> assertFailure err
        Right e' -> e' @?= e
  
  -- Test that some string results in a parse error. The exact error
  -- message is not tested. Be careful when using this function, as it
  -- is easy to make a test that fails for some reason (such as a typo)
  -- than the case you are actually interested in. Generally, negative
  -- tests of parsers are often not very interesting.
  parserTestFail :: String -> TestTree
  parserTestFail s =
    testCase s $
      case parseAPL "input" s of
        Left _ -> pure ()
        Right e ->
          assertFailure $
            "Expected parse error but received this AST:\n" ++ show e
  
  tests :: TestTree
  tests =
    testGroup
      "Parsing"
      []
  