seonbi 0.2.1 → 0.2.2
raw patch · 6 files changed
+72/−12 lines, 6 filesdep +Diff
Dependencies added: Diff
Files
- CHANGES.md +11/−0
- README.md +2/−2
- seonbi.cabal +3/−2
- src/Text/Seonbi/Punctuation.hs +3/−2
- test/Text/Seonbi/FacadeSpec.hs +30/−4
- test/Text/Seonbi/PunctuationSpec.hs +23/−2
CHANGES.md view
@@ -1,6 +1,17 @@ Seonbi changelog ================ +Version 0.2.2+-------------++Released on September 25, 2021.++ - Fixed stops normalizer's bug where unnecessary trailing spaces following+ stops had been left even after normalized.+ - Fixed stops normalizer's bug where commas followed by tag boundaries had+ been not normalized.++ Version 0.2.1 -------------
README.md view
@@ -48,7 +48,7 @@ [hackage]: https://hackage.haskell.org/package/seonbi [hackage-badge]: https://img.shields.io/hackage/v/seonbi [dockerhub]: https://hub.docker.com/r/dahlia/seonbi-[dockerhub-badge]: https://img.shields.io/microbadger/image-size/dahlia/seonbi+[dockerhub-badge]: https://img.shields.io/docker/v/dahlia/seonbi?label=docker%20image&sort=semver [ci]: https://github.com/dahlia/seonbi/actions [ci-status-badge]: https://github.com/dahlia/seonbi/workflows/build/badge.svg [demo web app]: https://dahlia.github.io/seonbi/@@ -128,7 +128,7 @@ HTTP/1.1 200 OK Content-Type: application/json- Server: Seonbi/0.2.1+ Server: Seonbi/0.2.2 { "success": true,
seonbi.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: seonbi-version: 0.2.1+version: 0.2.2 synopsis: SmartyPants for Korean language description: Please see the README.md on GitHub at <https://github.com/dahlia/seonbi>. category: Text@@ -234,7 +234,8 @@ test ghc-options: -Wno-incomplete-uni-patterns -threaded -rtsopts -with-rtsopts=-N build-depends:- aeson >=1.3.1 && <1.5+ Diff >=0.3.4 && <0.4+ , aeson >=1.3.1 && <1.5 , base >=4.7 && <5 , bytestring , containers
src/Text/Seonbi/Punctuation.hs view
@@ -36,6 +36,7 @@ import Prelude hiding (takeWhile) +import Control.Applicative ((<|>)) import Control.Monad import Data.Char (isSpace) import Data.Either@@ -315,7 +316,7 @@ , Data.Text.singleton <$> anyChar ] endOfInput- return $ Data.Text.concat chunks+ return $ Data.Text.dropWhileEnd (' ' ==) $ Data.Text.concat chunks stops' :: Parser Text stops' = choice [ period' >> return (toEntity $ period stops)@@ -340,7 +341,7 @@ comma' :: Parser () comma' = void $ choice [ char '、' >> return ""- , string ", "+ , string "," >> (takeWhile isSpace <|> (endOfInput >> return "")) , string ", " , string ", " , string "、"
test/Text/Seonbi/FacadeSpec.hs view
@@ -4,6 +4,8 @@ import Control.Monad +import Data.Algorithm.Diff+import Data.Text.Lazy import Data.Text.Lazy.IO import System.Directory import System.FilePath@@ -23,6 +25,27 @@ , (".ko-KP.html", ko_KP) ] +shouldHaveSameText :: (HasCallStack) => Text -> Text -> Expectation+actual `shouldHaveSameText` expected =+ unless (actual == expected) (expectationFailure msg)+ where+ expectedLines :: [Text]+ expectedLines = Data.Text.Lazy.lines expected+ actualLines :: [Text]+ actualLines = Data.Text.Lazy.lines actual+ diffLines :: [Diff Text]+ diffLines = getDiff expectedLines actualLines+ diff :: Text+ diff = Data.Text.Lazy.unlines+ [ case d of+ First line -> "- " <> line+ Second line -> "+ " <> line+ Both line _ -> " " <> line+ | d <- diffLines+ ]+ msg :: String+ msg = "Two values are not equal:\n\n--- expected\n+++ actual\n\n" +++ unpack diff spec :: Spec spec = do@@ -39,10 +62,13 @@ inputData <- Data.Text.Lazy.IO.readFile (dataDirPath </> input) outputData <- Data.Text.Lazy.IO.readFile (dataDirPath </> output) return (input, output, inputData, outputData, cfg)- forM_ testData $ \ (iname, oname, input, output, cfg) ->- specify ("transformHtmlLazyText: " ++ iname ++ " -> " ++ oname) $ do- transformHtmlLazyText noOp input `shouldBe` Just input- transformHtmlLazyText cfg input `shouldBe` Just output+ describe "transformHtmlLazyText" $+ forM_ testData $ \ (iname, oname, input, output, cfg) ->+ specify (iname ++ " -> " ++ oname) $ do+ let Just noOpResult = transformHtmlLazyText noOp input+ noOpResult `shouldHaveSameText` input+ let Just cfgResult = transformHtmlLazyText cfg input+ cfgResult `shouldHaveSameText` output where noOp :: Monad m => Configuration m a noOp = Configuration
test/Text/Seonbi/PunctuationSpec.hs view
@@ -498,7 +498,7 @@ normalizeStops horizontalStops input `shouldBe` [ HtmlStartTag [] P "" , HtmlText [P]- "봄·여름·가을·겨울. 어제, 오늘. "+ "봄·여름·가을·겨울. 어제, 오늘." , HtmlEndTag [] P ] normalizeStops verticalStops input `shouldBe`@@ -509,6 +509,27 @@ ] normalizeStops horizontalStopsWithSlashes input `shouldBe` [ HtmlStartTag [] P ""- , HtmlText [P] "봄/여름/가을/겨울. 어제, 오늘. "+ , HtmlText [P] "봄/여름/가을/겨울. 어제, 오늘."+ , HtmlEndTag [] P+ ]+ it "normalizes stops followed by boundaries as well" $ do+ let input =+ [ HtmlStartTag [] P ""+ , HtmlStartTag [P] Span ""+ , HtmlText [P, Span] "쉼표,"+ , HtmlEndTag [P] Span+ , HtmlStartTag [P] Span ""+ , HtmlText [P, Span] "마침표."+ , HtmlEndTag [P] Span+ , HtmlEndTag [] P+ ] :: [HtmlEntity]+ normalizeStops verticalStops input `shouldBe`+ [ HtmlStartTag [] P ""+ , HtmlStartTag [P] Span ""+ , HtmlText [P, Span] "쉼표、"+ , HtmlEndTag [P] Span+ , HtmlStartTag [P] Span ""+ , HtmlText [P, Span] "마침표。"+ , HtmlEndTag [P] Span , HtmlEndTag [] P ]