add newtypes for QuickCheck to avoid LANG=C issues
All properties changed to use them, except for prop_encode_c_decode_c_roundtrip, which already filtered to ascii for other reasons. A few modules had to be split out, because Setup does not build-depend on QuickCheck.
This commit is contained in:
parent
aad4129669
commit
885974be99
17 changed files with 211 additions and 130 deletions
|
@ -10,6 +10,7 @@ module Git.Filename where
|
|||
|
||||
import Common
|
||||
import Utility.Format (decode_c, encode_c)
|
||||
import Utility.QuickCheck
|
||||
|
||||
import Data.Char
|
||||
import Data.Word
|
||||
|
@ -35,21 +36,14 @@ decode b = case S.uncons b of
|
|||
encode :: RawFilePath -> S.ByteString
|
||||
encode s = encodeBS $ "\"" ++ encode_c (decodeBS s) ++ "\""
|
||||
|
||||
prop_encode_decode_roundtrip :: FilePath -> Bool
|
||||
prop_encode_decode_roundtrip s = s' ==
|
||||
fromRawFilePath (decode (encode (toRawFilePath s')))
|
||||
-- Encoding and then decoding roundtrips only when the string does not
|
||||
-- contain high unicode, because eg, both "\12345" and "\227\128\185"
|
||||
-- are encoded to "\343\200\271".
|
||||
--
|
||||
-- That is not a real-world problem, and using TestableFilePath
|
||||
-- limits what's tested to ascii, so avoids running into it.
|
||||
prop_encode_decode_roundtrip :: TestableFilePath -> Bool
|
||||
prop_encode_decode_roundtrip ts =
|
||||
s == fromRawFilePath (decode (encode (toRawFilePath s)))
|
||||
where
|
||||
s' = nonul (nohigh s)
|
||||
-- Encoding and then decoding roundtrips only when
|
||||
-- the string does not contain high unicode, because eg,
|
||||
-- both "\12345" and "\227\128\185" are encoded to
|
||||
-- "\343\200\271".
|
||||
--
|
||||
-- This property papers over the problem, by only
|
||||
-- testing ascii
|
||||
nohigh = filter isAscii
|
||||
-- A String can contain a NUL, but toRawFilePath
|
||||
-- truncates on the NUL, which is generally fine
|
||||
-- because unix filenames cannot contain NUL.
|
||||
-- So the encoding only roundtrips when there is no nul.
|
||||
nonul = filter (/= '\NUL')
|
||||
s = fromTestableFilePath ts
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue