skylighting 0.5 → 0.5.0.1
raw patch · 3 files changed
+37/−20 lines, 3 filesdep ~aeson
Dependency ranges changed: aeson
Files
- changelog.md +9/−0
- skylighting.cabal +4/−4
- test/test-skylighting.hs +24/−16
changelog.md view
@@ -1,5 +1,14 @@ # Revision history for skylighting +## 0.5.0.1 -- 2017-12-18++ * Small improvements to fuzz tests in test suite. We now+ ensure that we print the random text on test failure. Also,+ we now run the test with many smaller samples rather than+ one big one.++ * Add aeson lower bound (because of toEncoding) (#28).+ ## 0.5 -- 2017-12-10 * Fix line spacing and overflowing content in generated HTML
skylighting.cabal view
@@ -1,5 +1,5 @@ name: skylighting-version: 0.5+version: 0.5.0.1 synopsis: syntax highlighting library description: Skylighting is a syntax highlighting library with support for over one hundred languages. It derives@@ -234,7 +234,7 @@ bytestring, directory, filepath,- aeson,+ aeson >= 1.0, case-insensitive, attoparsec, utf8-string,@@ -279,7 +279,7 @@ hxt, utf8-string, case-insensitive,- aeson,+ aeson >= 1.0, binary, containers, directory@@ -345,7 +345,7 @@ Diff, text, pretty-show,- aeson,+ aeson >= 1.0, bytestring, directory, filepath,
test/test-skylighting.hs view
@@ -2,6 +2,7 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} module Main where+import qualified Control.Exception as E import Data.Aeson (decode, encode) import Data.Monoid ((<>)) import Data.Algorithm.Diff@@ -33,16 +34,14 @@ main :: IO () main = do stdgen <- newStdGen- let randomText = Text.unlines $ Text.chunksOf 31- $ Text.pack $ take 5000 $ randomRs ('\0','\127') stdgen+ let randomTexts = (Text.chunksOf 250 . Text.unlines . Text.chunksOf 31 .+ Text.pack . take 10000) $ randomRs ('\0','\160') stdgen inputs <- filter (\fp -> take 1 fp /= ".") <$> getDirectoryContents ("test" </> "cases")- allcases <- mconcat <$>- mapM (Text.readFile . (("test" </> "cases") </>)) inputs+ allcases <- mapM (Text.readFile . (("test" </> "cases") </>)) inputs args <- getArgs let regen = "--accept" `elem` args defaultTheme <- BL.readFile ("test" </> "default.theme")- putStrLn $ "randomText = " ++ show randomText defaultMain $ testGroup "skylighting tests" $ [ testGroup "tokenizer tests" $ map (tokenizerTest regen) inputs@@ -74,7 +73,7 @@ , testGroup "Doesn't hang or drop text on a mixed syntax sample" $ map (noDropTest allcases) syntaxes , testGroup "Doesn't hang or drop text on fuzz" $- map (noDropTest randomText) syntaxes+ map (noDropTest randomTexts) syntaxes , testGroup "Regression tests" $ let perl = maybe (error "could not find Perl syntax") id (lookupSyntax "Perl" defaultSyntaxMap)@@ -153,16 +152,25 @@ where notBoth (Both _ _ ) = False notBoth _ = True -noDropTest :: Text -> Syntax -> TestTree-noDropTest inp syntax = localOption (mkTimeout 6000000) $- testCase (Text.unpack (sName syntax)) $- case tokenize defConfig syntax inp of- Right ts -> assertBool ("Text has been dropped:\n" ++ diffs)- (inplines == toklines)- where inplines = Text.lines inp- toklines = map (mconcat . map tokToText) ts- diffs = makeDiff "expected" inplines toklines- Left e -> assert ("Unexpected error: " ++ e)+noDropTest :: [Text] -> Syntax -> TestTree+noDropTest inps syntax =+ localOption (mkTimeout 6000000)+ $ testCase (Text.unpack (sName syntax))+ $ mapM_ go inps+ where go inp =+ E.catch+ (case tokenize defConfig syntax inp of+ Right ts -> assertBool ("Text has been dropped:\n" ++ diffs)+ (inplines == toklines)+ where inplines = Text.lines inp+ toklines = map (mconcat . map tokToText) ts+ diffs = makeDiff "expected" inplines toklines+ Left e -> do+ assert ("Unexpected error: " ++ e)+ assert ("input = " ++ show inp))+ (\(e :: RegexException) -> do+ assert (show e)+ assert ("input = " ++ show inp)) tokenizerTest :: Bool -> FilePath -> TestTree tokenizerTest regen inpFile = localOption (mkTimeout 6000000) $