packages feed

language-puppet-1.5.1: tests/Interpreter/IfSpec.hs

{-# LANGUAGE OverloadedLists #-}

-- |  Directly ported from puppet specs
module Interpreter.IfSpec (spec) where

import Control.Lens
import qualified Data.Text as Text
import Helpers
import Test.Hspec

shouldFail :: [Text] -> Expectation
shouldFail content =
  let cat = pureCatalog (Text.unlines content)
   in cat `shouldSatisfy` has _Left

shouldNotFail :: [Text] -> Expectation
shouldNotFail content =
  let cat = pureCatalog (Text.unlines content)
   in cat `shouldSatisfy` has _Right

spec :: Spec
spec = do
  describe "If" $ do
    it "doesn't enter false conditions" $
      shouldNotFail
        ["if (false) { fail ':(' }"]
    it "enters true conditions" $
      shouldFail
        ["if (true) { fail ':(' }"]
    it "enters empty string conditions" $
      shouldFail
        ["if '' { fail ':(' }"]
    it "not (unknown variable) is true" $
      shouldFail
        ["if (!$::unknown123) { fail ':(' }"]