PageRenderTime 24ms CodeModel.GetById 15ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/Psp/FileInfoTest.hs

http://hdbc.googlecode.com/
Haskell | 60 lines | 34 code | 9 blank | 17 comment | 0 complexity | 42e0f6931d9202c351a3d51765ee7714 MD5 | raw file
 1
 2module FileInfoTest where
 3
 4import Test.HUnit
 5import Text.Regex
 6import FileInfo
 7
 8runTests :: IO Counts
 9runTests = runTestTT allTests
10
11allTests :: Test
12allTests = TestList [TestLabel "testLinesOfCode1" testLinesOfCode1,
13                     TestLabel "testLinesOfCode2" testLinesOfCode2,
14                     TestLabel "testLinesOfCode3" testLinesOfCode3,
15                     TestLabel "testMultLnCmntBegin1" testMultLnCmntBegin1,
16                     TestLabel "testMultLnCmntBegin2" testMultLnCmntBegin2,
17                     TestLabel "testSngLnCmnt" testSngLnCmnt,
18                     TestLabel "testEmptyLn1" testEmptyLn1]
19
20-- test that we are not counting empty spaces
21testLinesOfCode1 :: Test
22testLinesOfCode1 = TestCase (do 
23     let input = ["line1","","line2"]
24     assertEqual "expect 2 lines of code" 2 (linesOfCode input AtEmpty 0))
25
26-- test that we are not counting haskell comments
27testLinesOfCode2 :: Test
28testLinesOfCode2 = 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
33-- test that we are not counting java comments
34testLinesOfCode3 :: Test
35testLinesOfCode3 = TestCase (do
36     let input = ["// and some comments","some code","some more code",
37                 "/* and a comment","and more comments","end of comment"," */ "]
38     assertEqual "expect 2 lines of code" 2 (linesOfCode input AtEmpty 0))
39
40-- test java comments
41testMultLnCmntBegin1 :: Test
42testMultLnCmntBegin1 = TestCase (do
43     assertBool "expect match" ((matchRegex multiLnCmntBegin " /* ddnddndd") /= Nothing))
44
45-- test haskell comments
46testMultLnCmntBegin2 :: Test
47testMultLnCmntBegin2 = TestCase (do
48     assertBool "expect match" ((matchRegex multiLnCmntBegin "{- ddnddndd") /= Nothing))
49
50-- test java single comments
51testSngLnCmnt :: Test
52testSngLnCmnt = TestCase (do
53     assertBool "expect match" ((matchRegex sngLnCmnt "//this is a comnt") /= Nothing))
54
55--test no content, spaces, tab
56testEmptyLn1 :: Test
57testEmptyLn1 = TestCase (do
58     assertBool "empty should match" ((matchRegex emptyLn "") /= Nothing)
59     assertBool "spaces should match" ((matchRegex emptyLn "   ") /= Nothing)
60     assertBool "tab should match" ((matchRegex emptyLn "\t") /= Nothing))