kanji 3.2.0 → 3.2.1
raw patch · 4 files changed
+13/−13 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Data.Kanji.Types: [_kanji] :: Kanji -> Char
+ Data.Kanji.Types: _kanji :: Kanji -> Char
Files
- CHANGELOG.md +5/−0
- kanji.cabal +2/−2
- lib/Data/Kanji/Types.hs +4/−11
- test/Test.hs +2/−0
CHANGELOG.md view
@@ -1,3 +1,8 @@+## 3.2.1++- `ToJSON` and `FromJSON` instances for `Kanji` derived via `Generic`+ instead of being hand-written.+ ## 3.2.0 - `averageLevel` isn't total, and so now returns in `Maybe`
kanji.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 66205a8908712746bbacb83edcf1cdf567c460ec2178e9a0ef9ddfc10b0c5ec3+-- hash: 151854e92d22569c786a39e97c1a9922bfe2a86908bb691351fe7c16d8095572 name: kanji-version: 3.2.0+version: 3.2.1 synopsis: Perform 漢字検定 (Japan Kanji Aptitude Test) level analysis on Japanese Kanji description: Perform 漢字検定 (Japan Kanji Aptitude Test) level analysis on Japanese Kanji. category: Data
lib/Data/Kanji/Types.hs view
@@ -35,18 +35,11 @@ -- * 畑 (a type of rice field) -- * 峠 (a narrow mountain pass) -- * 働 (to do physical labour)-newtype Kanji = Kanji {- _kanji :: Char -- ^ The original `Char` of a `Kanji`.- } deriving (Eq, Ord, Show, Generic, Hashable, NFData)--instance ToJSON Kanji where- toJSON (Kanji c) = String $ T.singleton c+newtype Kanji = Kanji Char deriving (Eq, Ord, Show, Generic, ToJSON, FromJSON, Hashable, NFData) -instance FromJSON Kanji where- parseJSON = withText "Kanji" $ \t -> case T.uncons t of- Nothing -> fail "No Kanji given"- Just (c, t') | not (T.null t') -> fail "More than one Kanji given in a single String"- | otherwise -> pure $ Kanji c+-- | The original `Char` of a `Kanji`.+_kanji :: Kanji -> Char+_kanji (Kanji k) = k -- | Construct a `Kanji` value from some `Char` if it falls in the correct UTF8 range. kanji :: Char -> Maybe Kanji
test/Test.hs view
@@ -31,6 +31,8 @@ , testCase "String w/ multiple Kanji should fail" $ assertBool "A String of multiple Kanji somehow parsed" . isError $ fromJSON @Kanji (String "泥棒猫") , testCase "String w/ one Kanji should succeed" $ fromJSON (String "猫") @?= Success (Kanji '猫')+ , testCase "Isomorphism" $ fromJSON (toJSON $ Kanji '猫') @?= Success (Kanji '猫')+ , testCase "newtype generic encoding" $ toJSON (Kanji '猫') @?= String "猫" ] ] where ?epsilon = 0.001