-- | Turns `Examples` into a `Test`
module Test.Encoding (examplesToTest) where

import qualified Examples
import qualified Expect
import NriPrelude
import System.FilePath ((</>))
import qualified System.FilePath as FilePath
import Test (Test, test)
import qualified Text

-- | Creates tests for some examples
examplesToTest :: Text -> Text -> Examples.Examples -> Test
examplesToTest :: Text -> Text -> Examples -> Test
examplesToTest Text
name Text
fileName Examples
examples =
  HasCallStack => Text -> (() -> Expectation) -> Test
Text -> (() -> Expectation) -> Test
test Text
name ((() -> Expectation) -> Test) -> (() -> Expectation) -> Test
forall a b. (a -> b) -> a -> b
<| \() ->
    HasCallStack => Text -> Text -> Expectation
Text -> Text -> Expectation
Expect.equalToContentsOf
      ( FilePath
"test" FilePath -> FilePath -> FilePath
</> FilePath
"golden-results" FilePath -> FilePath -> FilePath
</> Text -> FilePath
Text.toList Text
fileName
          FilePath -> (FilePath -> FilePath) -> FilePath
forall a b. a -> (a -> b) -> b
|> FilePath -> FilePath
FilePath.makeValid
          FilePath -> (FilePath -> Text) -> Text
forall a b. a -> (a -> b) -> b
|> FilePath -> Text
Text.fromList
      )
      (Examples -> Text
Examples.render Examples
examples)