[commit: ghc] wip/nfs-locking: Document and test encode/decodeModule. (5e32c91)

git at git.haskell.org git at git.haskell.org
Fri Oct 27 00:52:07 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/nfs-locking
Link       : http://ghc.haskell.org/trac/ghc/changeset/5e32c9147ba23b886ae6154200fc7961481f4bd9/ghc

>---------------------------------------------------------------

commit 5e32c9147ba23b886ae6154200fc7961481f4bd9
Author: Andrey Mokhov <andrey.mokhov at gmail.com>
Date:   Sat Feb 20 22:40:41 2016 +0000

    Document and test encode/decodeModule.
    
    See #197, #210.


>---------------------------------------------------------------

5e32c9147ba23b886ae6154200fc7961481f4bd9
 src/Base.hs           |  7 +++++--
 src/Rules/Selftest.hs | 14 ++++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/src/Base.hs b/src/Base.hs
index 7d63fa0..7217834 100644
--- a/src/Base.hs
+++ b/src/Base.hs
@@ -98,13 +98,16 @@ versionToInt s = major * 1000 + minor * 10 + patch
 
 -- | Given a module name extract the directory and file name, e.g.:
 --
--- > decodeModule "Data.Functor.Identity" = ("Data/Functor/", "Identity")
+-- > decodeModule "Data.Functor.Identity" == ("Data/Functor/", "Identity")
+-- > decodeModule "Prelude"               == ("./", "Prelude")
 decodeModule :: String -> (FilePath, String)
 decodeModule = splitFileName . replaceEq '.' '/'
 
 -- | Given the directory and file name find the corresponding module name, e.g.:
 --
--- > encodeModule "Data/Functor/" "Identity.hs" = "Data.Functor.Identity"
+-- > encodeModule "Data/Functor/" "Identity.hs" == "Data.Functor.Identity"
+-- > encodeModule "./" "Prelude"                == "Prelude"
+-- > uncurry encodeModule (decodeModule name)   == name
 encodeModule :: FilePath -> String -> String
 encodeModule dir file = replaceEq '/' '.' $ dir -/- takeBaseName file
 
diff --git a/src/Rules/Selftest.hs b/src/Rules/Selftest.hs
index 70a4023..c156b44 100644
--- a/src/Rules/Selftest.hs
+++ b/src/Rules/Selftest.hs
@@ -24,6 +24,7 @@ selftestRules =
         testWays
         testChunksOfSize
         testMatchVersionedFilePath
+        testModuleNames
 
 testWays :: Action ()
 testWays = do
@@ -54,3 +55,16 @@ testMatchVersionedFilePath = do
         matchVersionedFilePath prefix suffix (prefix ++ version ++ suffix)
   where
     versions = listOf . elements $ '-' : '.' : ['0'..'9']
+
+testModuleNames :: Action ()
+testModuleNames = do
+    putBuild $ "==== Encode/decode module name"
+    test $ encodeModule "Data/Functor/" "Identity.hs" == "Data.Functor.Identity"
+    test $ encodeModule "./" "Prelude"                == "Prelude"
+
+    test $ decodeModule "Data.Functor.Identity" == ("Data/Functor/", "Identity")
+    test $ decodeModule "Prelude"               == ("./", "Prelude")
+
+    test $ forAll names $ \n -> uncurry encodeModule (decodeModule n) == n
+  where
+    names = intercalate "." <$> listOf1 (listOf1 $ elements "abcABC123_'")



More information about the ghc-commits mailing list