<commit_before>{-# LANGUAGE TypeSynonymInstances #-}

import Test.QuickCheck
import Data.Monoid
import Text.BlazeHtml.Text (Text)
import qualified Text.BlazeHtml.Text as T
import Text.BlazeHtml.Internal.Html
import Text.BlazeHtml.Render.HtmlText

-- Must implement an Eq instance for each Html instance we test
instance Eq HtmlText where
    a == b = renderHtmlText a == renderHtmlText b

instance Arbitrary Char where
    arbitrary     = oneof [choose ('\0','\55295'), choose ('\57344','\1114111')]
    coarbitrary c = variant (fromEnum c `rem` 4)

instance Arbitrary Text where
    arbitrary     = T.pack `fmap` arbitrary
    coarbitrary s = coarbitrary (T.unpack s)

-- Tests for equalities detailed in Html typeclass

prop_RenderEmpty :: (Html h, Eq h) => h -> Bool
prop_RenderEmpty h = renderUnescapedText mempty == h

-- Distributivity (?)
prop_RenderDistrib :: (Html h, Eq h) => h -> Text -> Text -> Bool
prop_RenderDistrib h t1 t2 = left == right
  where
    left = h `mappend` renderUnescapedText t1 `mappend` renderUnescapedText t2
    right = renderUnescapedText (t1 `mappend` t2)

prop_ModAttrDistrib :: (Html h, Eq h) => 
    h -> (AttributeManipulation -> AttributeManipulation) -> Text -> Text -> Bool
prop_ModAttrDistrib h f t1 t2 = left == right
  where
    
--    modifyUnescapedAttributes f (t1 `mappend` t2) = 
--    modifyUnescapedAttributes t1 `mappend` modifyUnescapedAttributes t2<commit_msg>Updated property tests to work with >= QuickCheck 2<commit_after>{-# LANGUAGE TypeSynonymInstances #-}

import Test.QuickCheck
import Data.Monoid
import Text.BlazeHtml.Text (Text)
import qualified Text.BlazeHtml.Text as T
import Text.BlazeHtml.Internal.Html
import Text.BlazeHtml.Render.HtmlText

-- Must implement an Eq instance for each Html instance we test
instance Eq HtmlText where
    a == b = renderHtmlText a == renderHtmlText b

newtype SpecialChar = SC { unSC :: Char } deriving Show
instance Arbitrary SpecialChar where
   arbitrary = do 
      x <- oneof [choose ('\0','\55295'), choose ('\57344','\1114111')]
      return (SC x)

instance Arbitrary Text where
    arbitrary     = T.pack `fmap` arbitrary

-- Tests for equalities detailed in Html typeclass

prop_RenderEmpty :: (Html h, Eq h) => h -> Bool
prop_RenderEmpty h = renderUnescapedText mempty == h

-- Distributivity (?)
prop_RenderDistrib :: (Html h, Eq h) => h -> Text -> Text -> Bool
prop_RenderDistrib h t1 t2 = left == right
  where
    left = h `mappend` renderUnescapedText t1 `mappend` renderUnescapedText t2
    right = h `mappend` renderUnescapedText (t1 `mappend` t2)

prop_NoAttribUnescaped :: (Html h, Eq h) => h -> Attributes -> Text -> Bool
prop_NoAttribUnescaped h a t = left == right
  where
    left = h `mappend` setUnescapedAttributes a (renderUnescapedText t)
    right = h `mappend` (renderUnescapedText t)

runTests = do
    quickCheck $ prop_RenderEmpty (mempty :: HtmlText)
    quickCheck $ prop_RenderDistrib (mempty :: HtmlText)
{'fraction_non_alphanumeric': 0.099830220713073, 'fraction_numerical': 0.019015280135823428, 'mean_word_length': 3.9346733668341707, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 26, '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': '2608471', 'n_tokens_mistral': 994, 'n_tokens_neox': 955, 'n_words': 313}