/Psp/FileInfoTest.hs

http://hdbc.googlecode.com/ · Haskell · 60 lines · 34 code · 9 blank · 17 comment · 1 complexity · 42e0f6931d9202c351a3d51765ee7714 MD5 · raw file

  1. module FileInfoTest where
  2. import Test.HUnit
  3. import Text.Regex
  4. import FileInfo
  5. runTests :: IO Counts
  6. runTests = runTestTT allTests
  7. allTests :: Test
  8. allTests = TestList [TestLabel "testLinesOfCode1" testLinesOfCode1,
  9. TestLabel "testLinesOfCode2" testLinesOfCode2,
  10. TestLabel "testLinesOfCode3" testLinesOfCode3,
  11. TestLabel "testMultLnCmntBegin1" testMultLnCmntBegin1,
  12. TestLabel "testMultLnCmntBegin2" testMultLnCmntBegin2,
  13. TestLabel "testSngLnCmnt" testSngLnCmnt,
  14. TestLabel "testEmptyLn1" testEmptyLn1]
  15. -- test that we are not counting empty spaces
  16. testLinesOfCode1 :: Test
  17. testLinesOfCode1 = TestCase (do
  18. let input = ["line1","","line2"]
  19. assertEqual "expect 2 lines of code" 2 (linesOfCode input AtEmpty 0))
  20. -- test that we are not counting haskell comments
  21. testLinesOfCode2 :: Test
  22. testLinesOfCode2 = TestCase (do
  23. let input = ["-- and some comments","some code","some more code",
  24. "{- and a comment","and more comments"," end of comment -}"]
  25. assertEqual "expect 2 lines of code" 2 (linesOfCode input AtEmpty 0))
  26. -- test that we are not counting java comments
  27. testLinesOfCode3 :: Test
  28. testLinesOfCode3 = TestCase (do
  29. let input = ["// and some comments","some code","some more code",
  30. "/* and a comment","and more comments","end of comment"," */ "]
  31. assertEqual "expect 2 lines of code" 2 (linesOfCode input AtEmpty 0))
  32. -- test java comments
  33. testMultLnCmntBegin1 :: Test
  34. testMultLnCmntBegin1 = TestCase (do
  35. assertBool "expect match" ((matchRegex multiLnCmntBegin " /* ddnddndd") /= Nothing))
  36. -- test haskell comments
  37. testMultLnCmntBegin2 :: Test
  38. testMultLnCmntBegin2 = TestCase (do
  39. assertBool "expect match" ((matchRegex multiLnCmntBegin "{- ddnddndd") /= Nothing))
  40. -- test java single comments
  41. testSngLnCmnt :: Test
  42. testSngLnCmnt = TestCase (do
  43. assertBool "expect match" ((matchRegex sngLnCmnt "//this is a comnt") /= Nothing))
  44. --test no content, spaces, tab
  45. testEmptyLn1 :: Test
  46. testEmptyLn1 = TestCase (do
  47. assertBool "empty should match" ((matchRegex emptyLn "") /= Nothing)
  48. assertBool "spaces should match" ((matchRegex emptyLn " ") /= Nothing)
  49. assertBool "tab should match" ((matchRegex emptyLn "\t") /= Nothing))