module FreeC.Environment.FreshTests where
import Test.Hspec
import FreeC.Environment.Fresh
import FreeC.Monad.Class.Testable
import FreeC.Monad.Converter
import FreeC.Test.Environment
testFreshIdentifiers :: Spec
testFreshIdentifiers = describe "FreeC.Environment.Fresh" $ do
context "freshCoqIdent" $ do
it "avoids collision with other fresh identifiers" $ shouldSucceedWith $ do
x0 <- freshCoqIdent "x"
x1 <- freshCoqIdent "x"
return ((x0, x1) `shouldBe` ("x", "x0"))
it "avoids collision with user defined identifiers" $ shouldSucceedWith $ do
"x" <- defineTestVar "x"
x1 <- freshCoqIdent "x"
x2 <- freshCoqIdent "x"
return ((x1, x2) `shouldBe` ("x0", "x1"))
it "is affected by local environments" $ shouldSucceedWith $ do
x1 <- localEnv $ do
"x" <- defineTestVar "x"
freshCoqIdent "x"
x0 <- localEnv $ freshCoqIdent "x"
return ((x1, x0) `shouldBe` ("x0", "x"))