add a stupid test harness
This commit is contained in:
parent
c7b0f60fba
commit
d93a372894
3 changed files with 20 additions and 9 deletions
18
GitRepo.hs
18
GitRepo.hs
|
@ -40,7 +40,7 @@ module GitRepo (
|
||||||
decodeGitFile,
|
decodeGitFile,
|
||||||
encodeGitFile,
|
encodeGitFile,
|
||||||
|
|
||||||
prop_idempotent_encode
|
prop_idempotent_deencode
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Monad (unless)
|
import Monad (unless)
|
||||||
|
@ -351,10 +351,10 @@ decodeGitFile f@(c:s)
|
||||||
pair = span (/= e) v
|
pair = span (/= e) v
|
||||||
beginning = fst pair
|
beginning = fst pair
|
||||||
rest = snd pair
|
rest = snd pair
|
||||||
isescape c = c == e
|
isescape x = x == e
|
||||||
-- \NNN is an octal encoded character
|
-- \NNN is an octal encoded character
|
||||||
decode (e:n1:n2:n3:rest)
|
decode (x:n1:n2:n3:rest)
|
||||||
| isescape e && alloctal = (fromoctal, rest)
|
| isescape x && alloctal = (fromoctal, rest)
|
||||||
where
|
where
|
||||||
alloctal = isOctDigit n1 &&
|
alloctal = isOctDigit n1 &&
|
||||||
isOctDigit n2 &&
|
isOctDigit n2 &&
|
||||||
|
@ -362,8 +362,8 @@ decodeGitFile f@(c:s)
|
||||||
fromoctal = [chr $ readoctal (n1:n2:n3:[])]
|
fromoctal = [chr $ readoctal (n1:n2:n3:[])]
|
||||||
readoctal o = read $ "0o" ++ o :: Int
|
readoctal o = read $ "0o" ++ o :: Int
|
||||||
-- \C is used for a few special characters
|
-- \C is used for a few special characters
|
||||||
decode (e:nc:rest)
|
decode (x:nc:rest)
|
||||||
| isescape e = ([echar nc], rest)
|
| isescape x = ([echar nc], rest)
|
||||||
where
|
where
|
||||||
echar 'a' = '\a'
|
echar 'a' = '\a'
|
||||||
echar 'b' = '\b'
|
echar 'b' = '\b'
|
||||||
|
@ -372,7 +372,7 @@ decodeGitFile f@(c:s)
|
||||||
echar 'r' = '\r'
|
echar 'r' = '\r'
|
||||||
echar 't' = '\t'
|
echar 't' = '\t'
|
||||||
echar 'v' = '\v'
|
echar 'v' = '\v'
|
||||||
echar x = x
|
echar a = a
|
||||||
decode n = ("", n)
|
decode n = ("", n)
|
||||||
|
|
||||||
{- Should not need to use this, except for testing decodeGitFile. -}
|
{- Should not need to use this, except for testing decodeGitFile. -}
|
||||||
|
@ -404,8 +404,8 @@ encodeGitFile s = (foldl (++) "\"" (map echar s)) ++ "\""
|
||||||
|
|
||||||
|
|
||||||
{- for quickcheck -}
|
{- for quickcheck -}
|
||||||
prop_idempotent_encode :: String -> Bool
|
prop_idempotent_deencode :: String -> Bool
|
||||||
prop_idempotent_encode s = s == (decodeGitFile $ encodeGitFile s)
|
prop_idempotent_deencode s = s == (decodeGitFile $ encodeGitFile s)
|
||||||
|
|
||||||
{- Finds the current git repository, which may be in a parent directory. -}
|
{- Finds the current git repository, which may be in a parent directory. -}
|
||||||
repoFromCwd :: IO Repo
|
repoFromCwd :: IO Repo
|
||||||
|
|
3
Makefile
3
Makefile
|
@ -16,6 +16,9 @@ else
|
||||||
IKIWIKI=ikiwiki
|
IKIWIKI=ikiwiki
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
test:
|
||||||
|
runghc test.hs
|
||||||
|
|
||||||
docs:
|
docs:
|
||||||
./mdwn2man git-annex 1 doc/git-annex.mdwn > git-annex.1
|
./mdwn2man git-annex 1 doc/git-annex.mdwn > git-annex.1
|
||||||
$(IKIWIKI) doc html -v --wikiname git-annex --plugin=goodstuff \
|
$(IKIWIKI) doc html -v --wikiname git-annex --plugin=goodstuff \
|
||||||
|
|
8
test.hs
Normal file
8
test.hs
Normal 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
|
Loading…
Reference in a new issue