module Latte.FrontEnd.FunctionNameDuplicationSpec (main, spec) where

import qualified Data.Set as Set
import Test.Hspec

import Latte.Lang
import Latte.FrontEnd

mockFunction :: String -> TopDef
mockFunction name = FnDef Int (Ident name) [] (Block [])

main :: IO ()
main = hspec spec

spec :: Spec
spec = do
	describe "Passing" $ do
		it "No function" $ do
			(runFeFnd (Program [])) >>= (`shouldBe` (Right (Set.empty, Set.empty)))
		it "One function" $ do
			(runFeFnd (Program [mockFunction "main"])) >>= (`shouldBe` (Right (Set.empty, Set.fromList ["main"])))
		it "Many functions" $ do
			(runFeFnd (Program [mockFunction "main", mockFunction "a", mockFunction "b"])) >>= (`shouldBe` (Right (Set.empty, Set.fromList ["main", "a", "b"])))
	describe "Failing" $ do
		it "One Function" $ do
			(runFeFnd (Program [mockFunction "main", mockFunction "main"])) >>= (`shouldBe` (Right (Set.fromList ["main"], Set.fromList ["main"])))
		it "Many functions, only colisions" $ do
			(runFeFnd (Program [mockFunction "main", mockFunction "b", mockFunction "main", mockFunction "b", mockFunction "b"])) >>= (`shouldBe` (Right (Set.fromList ["main", "b"], Set.fromList ["main", "b"])))
		it "One function colision, one no colision" $ do
			(runFeFnd (Program [mockFunction "main", mockFunction "b", mockFunction "main"])) >>= (`shouldBe` (Right (Set.fromList ["main"], Set.fromList ["main", "b"])))
		
