@@ -182,7 +182,7 @@ spec = do
182182 UChar. isUpperCase `shouldBeEqualToV` Char. isUpperCase
183183#endif
184184 it " toLower" do
185- UChar. toLower `shouldBeEqualToV` Char. toLower
185+ UChar. toLower `shouldBeEqualToV' ` Char. toLower
186186 let caseCheck f (c, cs) = c `shouldSatisfy` (== cs) . f
187187 describe " toLowerString" do
188188 it " Examples" do
@@ -203,7 +203,7 @@ spec = do
203203 in cf == foldMap UChar. toLowerString cf
204204 traverse_ check [minBound .. maxBound ]
205205 it " toUpper" do
206- UChar. toUpper `shouldBeEqualToV` Char. toUpper
206+ UChar. toUpper `shouldBeEqualToV' ` Char. toUpper
207207 describe " toUpperString" do
208208 it " Examples" do
209209 let examples = [ ('\ 0 ', " \0" )
@@ -224,7 +224,7 @@ spec = do
224224 in cf == foldMap UChar. toUpperString cf
225225 traverse_ check [minBound .. maxBound ]
226226 it " toTitle" do
227- UChar. toTitle `shouldBeEqualToV` Char. toTitle
227+ UChar. toTitle `shouldBeEqualToV' ` Char. toTitle
228228 describe " toTitleString" do
229229 it " Examples" do
230230 let examples = [ ('\ 0 ', " \0" )
@@ -287,16 +287,33 @@ spec = do
287287 -- If we use `pendingWith` then the whole test is pending, not just
288288 -- the assertion.
289289 shouldBeEqualToV
290- :: forall b . (HasCallStack ) => ( Eq b , Show b )
290+ :: forall b . (HasCallStack , Eq b , Show b )
291291 => (Char -> b )
292292 -> (Char -> b )
293293 -> IO ()
294294 shouldBeEqualToV f g =
295295 let same x = f x == g x
296296 in traverse_ (`shouldSatisfyV` same) [minBound .. maxBound ]
297297
298+ -- This adds an additional fallback depending on the resulting characters
299+ shouldBeEqualToV'
300+ :: (HasCallStack )
301+ => (Char -> Char )
302+ -> (Char -> Char )
303+ -> IO ()
304+ shouldBeEqualToV' f g =
305+ let same x = f x == g x
306+ in traverse_ (\ c -> shouldSatisfyV' c (Just (f, g)) same) [minBound .. maxBound ]
307+
298308 shouldSatisfyV :: (HasCallStack ) => Char -> (Char -> Bool ) -> IO ()
299- shouldSatisfyV c h
309+ shouldSatisfyV = (`shouldSatisfyV'` Nothing )
310+
311+ shouldSatisfyV' :: (HasCallStack )
312+ => Char
313+ -> Maybe (Char -> Char , Char -> Char )
314+ -> (Char -> Bool )
315+ -> IO ()
316+ shouldSatisfyV' c cs h
300317 | hasSameUnicodeVersion = shouldSatisfy c h
301318 | h c = pure ()
302319 | not hasGhcUnicodeVersion = traceM . mconcat $
@@ -316,6 +333,15 @@ spec = do
316333 , showVersion UChar. unicodeVersion
317334 , " , but got: "
318335 , showVersion unicodeVersion ]
336+ -- In case we compared 2 functions (Char -> Char),
337+ -- skip if one of the resulting char is unassigned.
338+ | Just (f, g) <- cs, let c1 = f c, let c2 = g c
339+ , isUnassigned c1 || isUnassigned c2 = traceM . mconcat $
340+ [ " [WARNING] Cannot test " , show c
341+ , " : incompatible Unicode version (unassigned mapped char). Expected "
342+ , showVersion UChar. unicodeVersion
343+ , " , but got: "
344+ , showVersion unicodeVersion ]
319345 | otherwise = shouldSatisfy c h
320346 -- Check if the character is not assigned in exactly one Unicode version.
321347 isUnassigned c = (UChar. generalCategory c == UChar. NotAssigned )
0 commit comments