{-# 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 programs by FQN expressions.-}module FilterSpec whereimport Control.Monad (forM_, when)import Data.Aesonimport Data.Yaml qualified as Yamlimport Encoding (Encoding (UNICODE))import Filter qualified as Fimport GHC.Generics (Generic)import Lining (LineFormat (MULTILINE))import Margin (defaultMargin)import Miscimport Parser (parseExpressionThrows, parseProgramThrows)import Printer (printProgram')import Sugar (SugarType (SALTY))import System.FilePathimport Test.Hspecdata YamlPack = YamlPack { program :: 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 prog <- parseProgramThrows program included <- traverse parseExpressionThrows shown excluded <- traverse parseExpressionThrows hidden res <- parseProgramThrows result let [(prog', _)] = F.exclude (F.include [(prog, Nothing)] included) excluded cfg = (SALTY, UNICODE, MULTILINE, defaultMargin) prog' `shouldBe` res when (prog' /= res) ( expectationFailure ( "Expected:\n" ++ printProgram' res cfg ++ "\nbut got:\n" ++ printProgram' prog' cfg ) ) )