lentil-0.1.2.7: test/Lentil/Parse/RunSpec.hs
module Lentil.Parse.RunSpec where
import Test.Hspec
import Text.Parsec ( runParser )
import Lentil.Types
import Lentil.Parse.Run
import Lentil.Parse.Source
import Prelude -- 7.8 hack
-- Parsing tests
-- simple parser (choosable if we are at begin of line or else)
sp :: ParSource a -> String -> Maybe a
sp p cs = either (const Nothing) Just
(runParser p () fp cs)
where fp = "<f>"
main :: IO ()
main = hspec spec
spec :: Spec
spec = do
describe "commentParser - specific" $ do
it "doesn't parse contiguous line/block as a single issue" $
fileParser "test/test-files/specific/contiguous.c"
`shouldReturn` [Issue "test/test-files/specific/contiguous.c" 1
(Just "issue1") []]
let spt fp = [Issue fp 1 (Just "single comment") [],
Issue fp 3 (Just "single2") [],
Issue fp 8 (Just "block1") [],
Issue fp 9 (Just "block2") [Tag "tog"]]
describe "commentParser - languages" $ do
it "parses a plain text source" $
fileParser "test/test-files/lang-comm/text.txt"
`shouldReturn` spt "test/test-files/lang-comm/text.txt"
it "parses a haskell source" $
fileParser "test/test-files/lang-comm/haskell.hs"
`shouldReturn` spt "test/test-files/lang-comm/haskell.hs"
it "parses a C source" $
fileParser "test/test-files/lang-comm/clang.c"
`shouldReturn` spt "test/test-files/lang-comm/clang.c"
it "parses a Pascal source" $
fileParser "test/test-files/lang-comm/pascal.pas"
`shouldReturn` spt "test/test-files/lang-comm/pascal.pas"
it "parses a javascript source" $
fileParser "test/test-files/lang-comm/javascript.js"
`shouldReturn` spt "test/test-files/lang-comm/javascript.js"
it "parses a python source" $
fileParser "test/test-files/lang-comm/python.py"
`shouldReturn` spt "test/test-files/lang-comm/python.py"
it "parses a ruby source" $
fileParser "test/test-files/lang-comm/ruby.rb"
`shouldReturn` spt "test/test-files/lang-comm/ruby.rb"
it "parses a perl source" $
fileParser "test/test-files/lang-comm/perl.pl"
`shouldReturn` spt "test/test-files/lang-comm/perl.pl"
it "parses a shell script source" $
fileParser "test/test-files/lang-comm/shell.sh"
`shouldReturn` spt "test/test-files/lang-comm/shell.sh"
describe "issueFinder" $ do
it "reads a file (code or txt) for issues" $
let fp = "test/test-files/lang-comm/test.txt" in
issueFinder [fp] >>= \i ->
i `shouldBe` [Issue fp 1 (Just "palla") [],
Issue fp 3 (Just "beta") [Tag "fixme"],
Issue fp 4 (Just "gamma") [Tag "xxx"],
Issue fp 6 (Just "qqq") [Tag "fixme", Tag "bug"]]