add a stupid test harness

This commit is contained in:
Joey Hess 2010-11-02 16:49:35 -04:00
parent c7b0f60fba
commit d93a372894
3 changed files with 20 additions and 9 deletions

View file

@ -40,7 +40,7 @@ module GitRepo (
decodeGitFile,
encodeGitFile,
prop_idempotent_encode
prop_idempotent_deencode
) where
import Monad (unless)
@ -351,10 +351,10 @@ decodeGitFile f@(c:s)
pair = span (/= e) v
beginning = fst pair
rest = snd pair
isescape c = c == e
isescape x = x == e
-- \NNN is an octal encoded character
decode (e:n1:n2:n3:rest)
| isescape e && alloctal = (fromoctal, rest)
decode (x:n1:n2:n3:rest)
| isescape x && alloctal = (fromoctal, rest)
where
alloctal = isOctDigit n1 &&
isOctDigit n2 &&
@ -362,8 +362,8 @@ decodeGitFile f@(c:s)
fromoctal = [chr $ readoctal (n1:n2:n3:[])]
readoctal o = read $ "0o" ++ o :: Int
-- \C is used for a few special characters
decode (e:nc:rest)
| isescape e = ([echar nc], rest)
decode (x:nc:rest)
| isescape x = ([echar nc], rest)
where
echar 'a' = '\a'
echar 'b' = '\b'
@ -372,7 +372,7 @@ decodeGitFile f@(c:s)
echar 'r' = '\r'
echar 't' = '\t'
echar 'v' = '\v'
echar x = x
echar a = a
decode n = ("", n)
{- Should not need to use this, except for testing decodeGitFile. -}
@ -404,8 +404,8 @@ encodeGitFile s = (foldl (++) "\"" (map echar s)) ++ "\""
{- for quickcheck -}
prop_idempotent_encode :: String -> Bool
prop_idempotent_encode s = s == (decodeGitFile $ encodeGitFile s)
prop_idempotent_deencode :: String -> Bool
prop_idempotent_deencode s = s == (decodeGitFile $ encodeGitFile s)
{- Finds the current git repository, which may be in a parent directory. -}
repoFromCwd :: IO Repo

View file

@ -16,6 +16,9 @@ else
IKIWIKI=ikiwiki
endif
test:
runghc test.hs
docs:
./mdwn2man git-annex 1 doc/git-annex.mdwn > git-annex.1
$(IKIWIKI) doc html -v --wikiname git-annex --plugin=goodstuff \

8
test.hs Normal file
View file

@ -0,0 +1,8 @@
-- TODO find a test harness that is actually in Debian and use it.
import Test.QuickCheck
import GitRepo
main = do
putStr "prop_idempotent_deencode "
quickCheck prop_idempotent_deencode