{-# LANGUAGE DeriveAnyClass #-}{-# LANGUAGE DeriveGeneric #-}{-# LANGUAGE RecordWildCards #-}{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}-- SPDX-FileCopyrightText: Copyright (c) 2025 Objectionary.com-- SPDX-License-Identifier: MIT{- | Tests for the Filter module that provides include and excludefunctions for filtering phi-calculus expressions by FQN expressions.-}module FilterSpec whereimport Control.Monad (forM_, when)import Data.Aesonimport Data.Yaml qualified as Yamlimport Encoding (Encoding (UNICODE))import Files (allPathsIn)import Filter qualified as Fimport GHC.Generics (Generic)import Lining (LineFormat (MULTILINE))import Margin (defaultMargin)import Parser (parseExpressionThrows)import Printer (printExpression')import Sugar (SugarType (SALTY))import System.FilePathimport Test.Hspecdata YamlPack = YamlPack { expression :: String , shown :: [String] , hidden :: [String] , result :: String } deriving (Generic, Show, FromJSON)yamlPack :: FilePath -> IO YamlPackyamlPack = Yaml.decodeFileThrowspec :: Specspec = describe "filter packs" $ do let resources = "test-resources/filter-packs" packs <- runIO (allPathsIn resources) forM_ packs ( \pth -> it (makeRelative resources pth) $ do YamlPack{..} <- yamlPack pth expr <- parseExpressionThrows expression included <- traverse parseExpressionThrows shown excluded <- traverse parseExpressionThrows hidden res <- parseExpressionThrows result let [(expr', _)] = F.exclude (F.include [(expr, Nothing)] included) excluded cfg = (SALTY, UNICODE, MULTILINE, defaultMargin) expr' `shouldBe` res when (expr' /= res) ( expectationFailure ( "Expected:\n" ++ printExpression' res cfg ++ "\nbut got:\n" ++ printExpression' expr' cfg ) ) )