File tree Expand file tree Collapse file tree 3 files changed +15
-1
lines changed Expand file tree Collapse file tree 3 files changed +15
-1
lines changed Original file line number Diff line number Diff line change 2222 "purescript-maybe" : " ^3.0.0" ,
2323 "purescript-partial" : " ^1.2.0" ,
2424 "purescript-unfoldable" : " ^3.0.0" ,
25- "purescript-arrays" : " ^4.0.1"
25+ "purescript-arrays" : " ^4.0.1" ,
26+ "purescript-integers" : " ^3.2.0"
2627 },
2728 "devDependencies" : {
2829 "purescript-assert" : " ^3.0.0" ,
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ import Prelude
2929
3030import Data.Array as Array
3131import Data.Char as Char
32+ import Data.Int (hexadecimal , toStringAs )
3233import Data.Maybe (Maybe (Just, Nothing))
3334import Data.String as String
3435import Data.String.Unsafe as Unsafe
@@ -50,6 +51,9 @@ newtype CodePoint = CodePoint Int
5051derive instance eqCodePoint :: Eq CodePoint
5152derive instance ordCodePoint :: Ord CodePoint
5253
54+ instance showCodePoint :: Show CodePoint where
55+ show (CodePoint i) = " (CodePoint 0x" <> String .toUpper (toStringAs hexadecimal i) <> " )"
56+
5357-- I would prefer that this smart constructor not need to exist and instead
5458-- CodePoint just implements Enum, but the Enum module already depends on this
5559-- one. To avoid the circular dependency, we just expose these two functions.
Original file line number Diff line number Diff line change @@ -15,6 +15,15 @@ str = "a\xDC00\xD800\xD800\x16805\x16A06\&z"
1515
1616testStringCodePoints :: forall eff . Eff (console :: CONSOLE , assert :: ASSERT | eff ) Unit
1717testStringCodePoints = do
18+ log " show"
19+ assert $ map show (codePointAt 0 str) == Just " (CodePoint 0x61)"
20+ assert $ map show (codePointAt 1 str) == Just " (CodePoint 0xDC00)"
21+ assert $ map show (codePointAt 2 str) == Just " (CodePoint 0xD800)"
22+ assert $ map show (codePointAt 3 str) == Just " (CodePoint 0xD800)"
23+ assert $ map show (codePointAt 4 str) == Just " (CodePoint 0x16805)"
24+ assert $ map show (codePointAt 5 str) == Just " (CodePoint 0x16A06)"
25+ assert $ map show (codePointAt 6 str) == Just " (CodePoint 0x7A)"
26+
1827 log " codePointAt"
1928 assert $ codePointAt (-1 ) str == Nothing
2029 assert $ codePointAt 0 str == (codePointFromInt 0x61 )
You can’t perform that action at this time.
0 commit comments