{-# LANGUAGE OverloadedStrings #-}-- SPDX-FileCopyrightText: Copyright (c) 2025 Objectionary.com-- SPDX-License-Identifier: MITmodule CLIHelpersSpec (spec) whereimport AST (Expression (ExRoot))import CLI.Helpers (getRules, parseInput, printExpression)import CLI.Types (IOFormat (LATEX, PHI, XMIR), PrintContext (PrintCtx))import Control.Exception (SomeException, try)import Control.Monad (forM_)import Lining (LineFormat (MULTILINE))import Sugar (SugarType (SWEET))import Test.Hspec (Spec, describe, it, shouldBe, shouldSatisfy)import XMIR (defaultXmirContext)isLeft :: Either e a -> BoolisLeft (Left _) = TrueisLeft (Right _) = False{-# ANN testPrintContext ("HLint: ignore Eta reduce" :: String) #-}testPrintContext :: IOFormat -> PrintContexttestPrintContext format = PrintCtx SWEET False Nothing False MULTILINE 2 defaultXmirContext False False False False False 1 1 ExRoot Nothing Nothing Nothing formatspec :: Specspec = do describe "parseInput" $ it "fails when asked to parse LaTeX as an input format" $ do result <- try (parseInput "whatever" LATEX) :: IO (Either SomeException Expression) result `shouldSatisfy` isLeft describe "printExpression" $ forM_ [ ( "fails when asked to print with --output=xmir (only --output=phi/latex are supported here)" , XMIR , isLeft ) , ("succeeds when --output=phi is used", PHI, not . isLeft) ] ( \(desc, format, predicate) -> it desc $ do result <- try (printExpression (testPrintContext format) ExRoot) :: IO (Either SomeException String) result `shouldSatisfy` predicate ) describe "getRules" $ it "deduplicates the same --rule file listed twice" $ do rules <- getRules False False ["test-resources/cli/rules/simple.yaml", "test-resources/cli/rules/simple.yaml"] length rules `shouldBe` 1