<commit_before>{-# LANGUAGE FlexibleContexts #-}


import HTML
import Text.Blaze.Html.Renderer.Utf8 (renderHtml)
import Data.ByteString.Lazy.Internal (ByteString)
import Data.ByteString.Lazy.Char8 (pack)
import Test.Tasty
  ( TestTree
  , defaultMain
  , testGroup)

import Test.Tasty.HUnit
  ( (@?=)
  , assertEqual
  , testCase)


main = defaultMain tests


tests :: TestTree
tests = testGroup "Tests" [email]


email = testGroup "Email formatting tests"
  [ testCase "Available status is formatted green"
      $ assertFormatting
          "In stock, usually dispatched in 1 business day"
          "color:green"

  , testCase "More than five items are formatted green"
      $ assertFormatting
          "Only 10 units,dispatched in 1 business day"
          "color:green"

  , testCase "Less than five items are formatted orange"
      $ assertFormatting
          "Only 5 units,dispatched in 1 business day"
          "color:orange"

  , testCase "No availability is formatted red"
      $ assertFormatting "Currently out of stock" "color:red"

  , testCase "Unexpected availability is formatted blue"
      $ assertFormatting "Status" "color:blue"]


assertFormatting status color =
    assertEqual
        ""
        (renderHtml $ formatBlock (pageTemplate status))
        (resultTemplate status color)


pageTemplate :: String -> ByteString
pageTemplate status = pack $
    "<!DOCTYPE html><html><title>Title</title></head><body><div class=\"status\">"<commit_msg>[DPP-28] Added comments and type annotations to test.<commit_after>{-# LANGUAGE FlexibleContexts #-}


import HTML
import Text.Blaze.Html.Renderer.Utf8 (renderHtml)
import Data.ByteString.Lazy.Internal (ByteString)
import Data.ByteString.Lazy.Char8 (pack)
import Test.Tasty
  ( TestTree
  , defaultMain
  , testGroup)

import Test.Tasty.HUnit
  ( (@?=)
  , assertEqual
  , testCase)


main :: IO ()
main = defaultMain tests


tests :: TestTree
tests = testGroup "Tests" [email]


email :: TestTree
email = testGroup "Email formatting tests"
  [ testCase "Available status is formatted green"
      $ assertFormatting
          "In stock, usually dispatched in 1 business day"
          "color:green"

  , testCase "More than five items are formatted green"
      $ assertFormatting
          "Only 10 units,dispatched in 1 business day"
          "color:green"

  , testCase "Less than five items are formatted orange"
      $ assertFormatting
          "Only 5 units,dispatched in 1 business day"
          "color:orange"

  , testCase "No availability is formatted red"
      $ assertFormatting "Currently out of stock" "color:red"

  , testCase "Unexpected availability is formatted blue"
      $ assertFormatting "Status" "color:blue"]


-- | Assert that availability string is formatted with the right colour.
assertFormatting status color =
    assertEqual
        ""
        (renderHtml $ formatBlock (pageTemplate status))
        (resultTemplate status color)


pageTemplate :: String -> ByteString
pageTemplate status = pack $
    "<!DOCTYPE html><html><title>Title</title></head><body><div class=\"status\">"
{'fraction_non_alphanumeric': 0.09569996766892984, 'fraction_numerical': 0.005819592628516004, 'mean_word_length': 3.3824362606232294, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6045292', 'n_tokens_mistral': 923, 'n_tokens_neox': 857, 'n_words': 276}