lentil-0.1.2.0: 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
"issue1" []]
let spt fp = [Issue fp 1 "single comment" [],
Issue fp 3 "single2" [],
Issue fp 8 "block1" [],
Issue fp 9 "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"
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 "palla" [],
Issue fp 3 "beta" [Tag "fixme"],
Issue fp 4 "gamma" [Tag "xxx"],
Issue fp 6 "qqq" [Tag "fixme", Tag "bug"]]