A cli database for some FFX stuff
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications  #-}

module Main where

import           Test.Tasty
import           Test.Tasty.HUnit
import           Test.Tasty.QuickCheck

import qualified Data.NonEmptyList     as NonEmptyList
import qualified Data.PrintableText    as PrintableText

main :: IO ()
main = defaultMain tests

tests :: TestTree
tests = testGroup "Conversions and Constructors"
    [ testGroup "PrintableText"
        [ printableTextFromTest
        , printableTextSingletonTest
        ]
    , testGroup "NonEmptyList"
        [ nonEmptyListFromTest
        , nonEmptyListSingletonProperty
        ]
    ]

printableTextFromTest :: TestTree
printableTextFromTest = testGroup "fromText conversions"
    [ testCase "Empty String" $
        Nothing @=? PrintableText.fromText ""
    , testCase "All whitespaces" $
        Nothing @=? PrintableText.fromText " \t\r\n"
    , testCase "Valid string" $
        Just "  this is valid" @=? PrintableText.unPrintableText <$> PrintableText.fromText "  this is valid"
    ]

printableTextSingletonTest :: TestTree
printableTextSingletonTest = testGroup "singleton constructor"
    [ testCase "Whitespace character" $
        Nothing @=? PrintableText.singleton ' '
    , testCase "Valid character" $
        Just "f" @=? PrintableText.unPrintableText <$> PrintableText.singleton 'f'
    ]

nonEmptyListFromTest :: TestTree
nonEmptyListFromTest = testGroup "fromList conversions"
    [ testCase "Empty List" $
        Nothing @=? NonEmptyList.fromList ([] @Int)
    , testCase "Single item" $
        Just (5, []) @=? NonEmptyList.uncons <$> NonEmptyList.fromList [5]
    , testCase "Several items" $
        Just (5, [4,3]) @=? NonEmptyList.uncons <$> NonEmptyList.fromList [5,4,3]
    ]

nonEmptyListSingletonProperty :: TestTree
nonEmptyListSingletonProperty = testGroup "singleton property"
    [ testProperty "[a] == toList $ singleton a" $
        \num -> [num] == (NonEmptyList.toList . NonEmptyList.singleton @Int $ num)
    ]