@@ -9,9 +9,9 @@ module Tests.Properties
11import Control.Applicative ((<$>), (<*>))
11import Control.Applicative ((<$>), (<*>))
12−import Control.Arrow ((***), second)
12+import Control.Arrow ((***), first, second)
13import Data.Bits ((.&.))
13import Data.Bits ((.&.))
14−import Data.Char (chr, isDigit, isHexDigit, isLower, isSpace, isUpper, ord)
14+import Data.Char (chr, isDigit, isHexDigit, isLower, isSpace, isLetter, isUpper, ord)
15import Data.Int (Int8, Int16, Int32, Int64)
15import Data.Int (Int8, Int16, Int32, Int64)
16import Data.Monoid (Monoid(..))
16import Data.Monoid (Monoid(..))
17import Data.String (IsString(fromString))
17import Data.String (IsString(fromString))
@@ -23,6 +23,7 @@ import Data.Text.Internal.Search (indices)
23import Data.Text.Lazy.Read as TL
23import Data.Text.Lazy.Read as TL
24import Data.Text.Read as T
24import Data.Text.Read as T
25import Data.Word (Word, Word8, Word16, Word32, Word64)
25import Data.Word (Word, Word8, Word16, Word32, Word64)
26+import Data.Maybe (mapMaybe)
26import Numeric (showEFloat, showFFloat, showGFloat, showHex)
27import Numeric (showEFloat, showFFloat, showGFloat, showHex)
27import Prelude hiding (replicate)
28import Prelude hiding (replicate)
28import Test.Framework (Test, testGroup)
29import Test.Framework (Test, testGroup)
@@ -229,6 +230,13 @@ sf_uncons p = (uncons . L.filter p) `eqP`
229 (fmap (second unpackS) . S.uncons . S.filter p)
230 (fmap (second unpackS) . S.uncons . S.filter p)
230t_uncons = uncons `eqP` (fmap (second unpackS) . T.uncons)
231t_uncons = uncons `eqP` (fmap (second unpackS) . T.uncons)
231tl_uncons = uncons `eqP` (fmap (second unpackS) . TL.uncons)
232tl_uncons = uncons `eqP` (fmap (second unpackS) . TL.uncons)
234+unsnoc xs@(_:_) = Just (init xs, last xs)
237+t_unsnoc = unsnoc `eqP` (fmap (first unpackS) . T.unsnoc)
238+tl_unsnoc = unsnoc `eqP` (fmap (first unpackS) . TL.unsnoc)
232s_head = head `eqP` S.head
240s_head = head `eqP` S.head
233sf_head p = (head . L.filter p) `eqP` (S.head . S.filter p)
241sf_head p = (head . L.filter p) `eqP` (S.head . S.filter p)
234t_head = head `eqP` T.head
242t_head = head `eqP` T.head
@@ -326,6 +334,14 @@ t_toUpper_upper t = p (T.toUpper t) >= p t
326 where p = T.length . T.filter isUpper
334 where p = T.length . T.filter isUpper
327tl_toUpper_upper t = p (TL.toUpper t) >= p t
335tl_toUpper_upper t = p (TL.toUpper t) >= p t
328 where p = TL.length . TL.filter isUpper
336 where p = TL.length . TL.filter isUpper
337+t_toTitle_title t = all (<= 1) (caps t)
338+ where caps = fmap (T.length . T.filter isUpper) . T.words . T.toTitle
339+t_toTitle_1stNotLower = and . notLow . T.toTitle . T.filter stable
340+ where notLow = mapMaybe (fmap (not . isLower) . (T.find isLetter)) . T.words
341+ -- Surprise! The Spanish/Portuguese ordinal indicators changed
342+ -- from category Ll (letter, lowercase) to Lo (letter, other)
344+ stable c = c /= '\170' && c /= '\186'
330justifyLeft k c xs = xs ++ L.replicate (k - length xs) c
346justifyLeft k c xs = xs ++ L.replicate (k - length xs) c
331justifyRight m n xs = L.replicate (m - length xs) n ++ xs
347justifyRight m n xs = L.replicate (m - length xs) n ++ xs
@@ -967,6 +983,8 @@ tests =
967 testProperty "sf_uncons" sf_uncons,
983 testProperty "sf_uncons" sf_uncons,
968 testProperty "t_uncons" t_uncons,
984 testProperty "t_uncons" t_uncons,
969 testProperty "tl_uncons" tl_uncons,
985 testProperty "tl_uncons" tl_uncons,
986+ testProperty "t_unsnoc" t_unsnoc,
987+ testProperty "tl_unsnoc" tl_unsnoc,
970 testProperty "s_head" s_head,
988 testProperty "s_head" s_head,
971 testProperty "sf_head" sf_head,
989 testProperty "sf_head" sf_head,
972 testProperty "t_head" t_head,
990 testProperty "t_head" t_head,
@@ -1030,7 +1048,9 @@ tests =
1030 testProperty "tl_toLower_lower" tl_toLower_lower,
1048 testProperty "tl_toLower_lower" tl_toLower_lower,
1031 testProperty "t_toUpper_length" t_toUpper_length,
1049 testProperty "t_toUpper_length" t_toUpper_length,
1032 testProperty "t_toUpper_upper" t_toUpper_upper,
1050 testProperty "t_toUpper_upper" t_toUpper_upper,
1033− testProperty "tl_toUpper_upper" tl_toUpper_upper
1051+ testProperty "tl_toUpper_upper" tl_toUpper_upper,
1052+ testProperty "t_toTitle_title" t_toTitle_title,
1053+ testProperty "t_toTitle_1stNotLower" t_toTitle_1stNotLower
1036 testGroup "justification" [
1056 testGroup "justification" [