packages feed

brok 0.1.3.0 → 0.1.4.0

raw patch · 7 files changed

+52/−20 lines, 7 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Brok.Parser.Attoparsec: concat4 :: Monoid a => a -> a -> a -> a -> a
+ Brok.Parser.Attoparsec: concat5 :: Monoid a => a -> a -> a -> a -> a -> a
+ Brok.Parser.Attoparsec: manyChars :: Parser Char -> Parser Text

Files

brok.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.12 name: brok-version: 0.1.3.0+version: 0.1.4.0 license: BSD3 license-file: LICENSE copyright: 2019 Small Hadron Collider
src/Brok/Parser/Attoparsec.hs view
@@ -8,7 +8,7 @@ import Data.Attoparsec.Text  lexeme :: Parser a -> Parser a-lexeme p = many' space *> p <* many' space+lexeme p = skipSpace *> p <* skipSpace  tchar :: Char -> Parser Text tchar ch = singleton <$> char ch@@ -16,11 +16,14 @@ chopt :: Char -> Parser Text chopt ch = option "" (tchar ch) +manyChars :: Parser Char -> Parser Text+manyChars p = pack <$> many1 p+ concat3 :: (Monoid a) => a -> a -> a -> a concat3 t1 t2 t3 = concat [t1, t2, t3] -concat4 :: (Monoid a) => a -> a -> a -> a -> a-concat4 t1 t2 t3 t4 = concat [t1, t2, t3, t4]+concat5 :: (Monoid a) => a -> a -> a -> a -> a -> a+concat5 t1 t2 t3 t4 t5 = concat [t1, t2, t3, t4, t5]  surround :: Char -> Char -> Parser Text -> Parser Text surround open close parser = concat3 <$> tchar open <*> parser <*> tchar close
src/Brok/Parser/DB.hs view
@@ -10,17 +10,10 @@ import Data.Attoparsec.Text  import Brok.Parser.Links (url)-import Brok.Types.Link+import Brok.Types.Link   (URL)  line :: Parser (URL, Integer)-line = do-    lnk <- url-    _ <- char ' '-    int <- many1 digit-    _ <- char '\n'-    case readMay int :: Maybe Integer of-        Just i  -> return (lnk, i)-        Nothing -> fail "Unable to parse timestamp"+line = (,) <$> (url <* char ' ') <*> (decimal <* endOfLine)  entries :: Parser [(URL, Integer)] entries = many1 line
src/Brok/Parser/Links.hs view
@@ -16,19 +16,30 @@  type Token = Maybe URL +preQueryChars :: String+preQueryChars = "-._~:/#%@"++queryBodyChars :: String+queryBodyChars = "-._~:/#%@!$&*+,;="++chars :: String -> Parser Char+chars chrs = digit <|> letter <|> choice (char <$> chrs)+ -- parentheses parens :: Parser Text -> Parser Text parens parser = surround '(' ')' parser <|> surround '[' ']' parser  -- urls-urlChar :: Parser Char-urlChar = digit <|> letter <|> choice (char <$> "-._~:/?#%@!$&*+,;=")+part :: String -> Parser Text+part str = concat <$> many' (parens (part str) <|> manyChars (chars str)) -urlChars :: Parser Text-urlChars = concat <$> many1 (parens urlChars <|> (pack <$> many1 urlChar))+query :: Parser Text+query = (++) <$> string "?" <*> part queryBodyChars  url :: Parser Text-url = concat4 <$> string "http" <*> chopt 's' <*> string "://" <*> urlChars+url =+    concat5 <$> string "http" <*> chopt 's' <*> string "://" <*> part preQueryChars <*>+    option "" query  noise :: Parser Token noise = anyChar >> return Nothing
src/Brok/Parser/Options.hs view
@@ -38,7 +38,7 @@ ignoreP = lexeme $ Ignore <$> (string "--ignore" *> char '\n' *> many1 urlP)  fileP :: Parser Text-fileP = lexeme $ pack <$> many1 (notChar '\n')+fileP = lexeme $ manyChars (notChar '\n')  optsToConfig :: [Option] -> Config optsToConfig = foldl' convert defaultConfig
test/Parser/DBTest.hs view
@@ -42,12 +42,15 @@                         ])                    (db content))         , testCase-              "big file"+              "big file (last)"               (assertEqual                    "Gives back final url"                    (Just                         "https://developmentarc.gitbooks.io/react-indepth/content/life_cycle/the_life_cycle_recap.html")                    (fst <$> (lastMay . fromRight [] $ db big)))+        , testCase+              "big file (length)"+              (assertEqual "Gives back length" 142 (length $ fromRight [] (db big)))         , testCase "invalid .brokdb" (assertEqual "Parse error" True (isLeft $ db invalid))         , testCase "parses empty" (assertEqual "Gives back empty array" (Right []) (db ""))         ]
test/Parser/LinksTest.hs view
@@ -42,6 +42,15 @@                          (Right ["https://google.com"])                          (links "https://google.com"))               , testCase+                    "just long link"+                    (assertEqual+                         "Gives back full URL"+                         (Right+                              [ "https://developmentarc.gitbooks.io/react-indepth/content/life_cycle/the_life_cycle_recap.html"+                              ])+                         (links+                              "https://developmentarc.gitbooks.io/react-indepth/content/life_cycle/the_life_cycle_recap.html"))+              , testCase                     "http link with surrounding text"                     (assertEqual                          "Gives back google.com"@@ -63,6 +72,13 @@                     "link with brackets"                     (assertEqual                          "Gives back google.com"+                         (Right ["https://en.wikipedia.org/wiki/Word_(computer_architecture)"])+                         (links+                              "[A link](https://en.wikipedia.org/wiki/Word_(computer_architecture))"))+              , testCase+                    "link with brackets in query"+                    (assertEqual+                         "Gives back google.com"                          (Right ["http://google.com?q=(fish)"])                          (links "[A link](http://google.com?q=(fish))"))               , testCase@@ -91,6 +107,12 @@                          "Gives back google.com"                          (Right ["http://google.com?q=fish"])                          (links "'http://google.com?q=fish'"))+              , testCase+                    "link with comma on end"+                    (assertEqual+                         "Gives back google.com"+                         (Right ["http://google.com"])+                         (links "testing http://google.com, here"))               ]         , testGroup               "multiple links"