diff options
author | sternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org> | 2020-08-29 13:35:07 +0200 |
---|---|---|
committer | sternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org> | 2020-08-29 13:35:40 +0200 |
commit | 2a065c40d9225d04644d7b3413ac81effe52f108 (patch) | |
tree | 995f4e1fa48328de7b68be2bb60b0657c659fe9a | |
parent | 3754846208d3ed7ee0161c70ab3fb5f8168ca1aa (diff) |
test(emoji-generic): check wether all lines of emoji-test.txt get parsed
-rw-r--r-- | src/Text/Emoji/DataFiles.hs | 8 | ||||
-rw-r--r-- | test/Main.hs | 22 |
2 files changed, 20 insertions, 10 deletions
diff --git a/src/Text/Emoji/DataFiles.hs b/src/Text/Emoji/DataFiles.hs index 1937fdb..72f37ca 100644 --- a/src/Text/Emoji/DataFiles.hs +++ b/src/Text/Emoji/DataFiles.hs @@ -123,11 +123,3 @@ emojiTestCommentLine = do emojiTestFile :: Parser EmojiTest emojiTestFile = many1 $ emojiTestGroup EmojiTestGroup <|> emojiTestEntryLine <|> emojiTestCommentLine - --- | Helper Function that counts number of lines used to parse 'EmojiTest'. --- Useful to check against LoC of @emoji-test.txt@ for parser sanity check. -countLines :: EmojiTest -> Integer -countLines ((Group _ _ x):xs) = 1 + countLines x + countLines xs -countLines ((Comment _):xs) = 1 + countLines xs -countLines ((Entry _ _ _ _):xs) = 1 + countLines xs -countLines [] = 0 diff --git a/test/Main.hs b/test/Main.hs index e277139..76942e2 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -14,7 +14,8 @@ import Text.Emoji.DataFiles import Data.Attoparsec.Text (parseOnly) import Data.Either (fromRight) import Data.Text (Text) -import qualified Data.Text as T (unpack) +import qualified Data.Text as T +import qualified Data.Text.IO as T main :: IO () main = defaultMain tests @@ -38,7 +39,9 @@ instance Monad m => Serial m EmojiVersion parserTests :: TestTree parserTests = testGroup "Emoji Data File Parser Tests" - [ HU.testCase "EmojiVersion Parser parses all versions up till now correctly" emojiVersionParserTest ] + [ HU.testCase "EmojiVersion parser parses all versions up till now correctly" emojiVersionParserTest + , HU.testCase "emoji-test.txt parser collects all entries" emojiTestParserLinesTest + ] emojiVersionParserTest :: HU.Assertion emojiVersionParserTest = do @@ -56,3 +59,18 @@ emojiVersionParserTest = do vt "E13.0" (EmojiVersion 13 0) where vt :: Text -> EmojiVersion -> HU.Assertion vt str exp = parseOnly emojiVersionColumn str @?= Right exp + +-- | Helper Function that counts number of lines used to parse 'EmojiTest'. +-- Useful to check against LoC of @emoji-test.txt@ for parser sanity check. +countLines :: EmojiTest -> Int +countLines ((Group _ _ x):xs) = 1 + countLines x + countLines xs +countLines ((Comment _):xs) = 1 + countLines xs +countLines ((Entry _ _ _ _):xs) = 1 + countLines xs +countLines [] = 0 + +emojiTestParserLinesTest :: HU.Assertion +emojiTestParserLinesTest = + T.readFile "./data/emoji-test.txt" >>= \emojiTestTxt -> + let lines = countLines <$> parseOnly emojiTestFile emojiTestTxt + expectedLines = length . filter (/= "") $ T.lines emojiTestTxt + in lines @?= Right expectedLines |