module Test.Week10 where

import Test.Tasty
import Test.Tasty.HUnit

import Week10

week10 :: TestTree
week10 = testGroup "Week 10 - Applicative functors, Part I"
  [
    exercise1
  , exercise2
  , exercise3
  , exercise4
  , exercise5
  ]

exercise1 =
  testGroup "Exercise 1 - Parser Functor" [
    testCase "Example 1 - fmap Parser Just" $
      runParser (fmap (+1) posInt) "1234 asdf" @?= Just (1235, " asdf")
  , testCase "Example 2 - fmap Parser Nothing" $
      runParser (fmap (+1) posInt) "ah34 asdf" @?= Nothing
  ]

exercise2 =
 testGroup "Exercise 2 - Parser Applicative" []

exercise3 =
  testGroup "Exercise 3 - Parser Applicative test" [
    testCase "Example 1 - abParser valid" $
      runParser abParser "abcdef" @?= Just (('a', 'b'), "cdef")
  , testCase "Example 2 - abParser Invalid" $
      runParser abParser "aebcdf" @?= Nothing
  , testCase "Example 3 - abParser_ valid" $
      runParser abParser_ "abcdef" @?= Just ((), "cdef")
  , testCase "Example 4 - abParser_ Invalid" $
      runParser abParser_ "aebcdf" @?= Nothing
  ]

exercise4 =
  testGroup "Exercise 4 - Parser Alternative" []

exercise5 =
  testGroup "Exercise 5 - intOrUppercase" [
    testCase "Example 1" $ runParser intOrUppercase "342abcd" @?= Just ((), "abcd")
  , testCase "Example 2" $ runParser intOrUppercase "XYZ" @?= Just ((), "YZ")
  , testCase "Example 3" $ runParser intOrUppercase "foo" @?= Nothing
  ]

