summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-11-02 16:49:35 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-11-02 16:49:35 -0400
commitd93a37289406fbeb0cedf05f1c8009f68cdb2570 (patch)
tree91743836be32ceceaa361b5fd1640c12c480ab41
parentc7b0f60fba9f53ed97c43f3ad9a48e7698b97760 (diff)
add a stupid test harness
-rw-r--r--GitRepo.hs18
-rw-r--r--Makefile3
-rw-r--r--test.hs8
3 files changed, 20 insertions, 9 deletions
diff --git a/GitRepo.hs b/GitRepo.hs
index d9dd086f2..7d5291ff1 100644
--- a/GitRepo.hs
+++ b/GitRepo.hs
@@ -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
diff --git a/Makefile b/Makefile
index 5e27c1e90..eb74bb727 100644
--- a/Makefile
+++ b/Makefile
@@ -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 \
diff --git a/test.hs b/test.hs
new file mode 100644
index 000000000..e9ea68459
--- /dev/null
+++ b/test.hs
@@ -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