[Pkg-haskell-commits] [SCM] haskell-testpack branch, master, updated. debian/1.0.2-1-4-gb0d6b36

John Goerzen jgoerzen at complete.org
Fri Apr 23 14:47:09 UTC 2010


The following commit has been merged in the master branch:
commit d90d93a051876887ec9e1ec81974db43519eab81
Author: John Goerzen <jgoerzen at complete.org>
Date:   Tue Nov 16 04:05:53 2004 +0100

    Checkpointing
    
    Keywords:
    
    
    (jgoerzen at complete.org--projects/missingh--head--0.5--patch-64)

diff --git a/ChangeLog b/ChangeLog
index 4c0b3cd..311ed29 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,18 @@
 # arch-tag: automatic-ChangeLog--jgoerzen at complete.org--projects/missingh--head--0.5
 #
 
+2004-11-15 21:05:53 GMT	John Goerzen <jgoerzen at complete.org>	patch-64
+
+    Summary:
+      Checkpointing
+    Revision:
+      missingh--head--0.5--patch-64
+
+
+    modified files:
+     ChangeLog libsrc/MissingH/Printf.hs testsrc/Printftest.hs
+
+
 2004-11-15 20:48:27 GMT	John Goerzen <jgoerzen at complete.org>	patch-63
 
     Summary:
diff --git a/libsrc/MissingH/Printf.hs b/libsrc/MissingH/Printf.hs
index 171a6b7..3b944d8 100644
--- a/libsrc/MissingH/Printf.hs
+++ b/libsrc/MissingH/Printf.hs
@@ -57,6 +57,7 @@ module MissingH.Printf(-- * Introduction
                        printf,
                        fprintf,
                        sprintfAL,
+                       sprintfFM,
                        -- ** Utility Function
                        v,
                        -- * Differences from C
@@ -82,6 +83,7 @@ import System.IO
 import MissingH.Printf.Types
 import MissingH.Printf.Printer(get_conversion_func, fix_width)
 import Text.Regex
+import Data.FiniteMap(lookupFM)
 
 v :: PFType a => a -> Value
 v = toValue
@@ -153,7 +155,7 @@ sprintf ('%' : xs) y =
         this ++ sprintf remainder ys
 sprintf (x:xs) y = x : sprintf xs y
 
-{- | Association list printing -}
+{- | Association list version of 'sprintf'. -}
 sprintfAL :: String -> PrintfAL -> String
 sprintfAL [] _ = []
 sprintfAL ('%' : '%' : xs) y = '%' : sprintfAL xs y
@@ -163,6 +165,16 @@ sprintfAL ('%' : xs) y =
         this ++ sprintfAL remainder y
 sprintfAL (x:xs) y = x : sprintfAL xs y
 
+{- | Finite map version of 'sprintf'. -}
+sprintfFM :: String -> PrintfFM -> String
+sprintfFM [] _ = []
+sprintfFM ('%' : '%' : xs) y = '%' : sprintfFM xs y
+sprintfFM ('%' : xs) y =
+    let (this, remainder) = (gLookup (flip lookupFM)) xs y
+        in
+        this ++ sprintfFM remainder y
+sprintfFM (x:xs) y = x : sprintfFM xs y
+
 {- | Given a format string and zero or more arguments, return a string
 that has formatted them appropriately.  This is the variable argument version
 of 'sprintf'. -}
diff --git a/testsrc/Printftest.hs b/testsrc/Printftest.hs
index 5b10691..ebdcba1 100644
--- a/testsrc/Printftest.hs
+++ b/testsrc/Printftest.hs
@@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 module Printftest(tests) where
 import HUnit
 import MissingH.Printf
+import Data.FiniteMap
 
 test_vsprintf = 
     do
@@ -40,23 +41,29 @@ test_vsprintf =
     "John, your age is 10\n" @=? sprintf "%s, your age is %d\n" [v "John",
                                                                  v (10::Integer)]
 
-test_al =
+test_al_fm =
     let testal = [("foo", v (1::Int)),
                   ("bar", v "asdf"),
                   ("baz", v (3.14::Double))]
-        f exp inp = exp @=? sprintfAL inp testal
+        testfm = listToFM testal
+        f exp inp = do 
+                    exp @=? sprintfAL inp testal
+                    exp @=? sprintfFM inp testfm
         in do
            f "" ""
+           f "%" "%%"
            f "asdf" "%(bar)s"
            f "001" "%(foo)03d"
            f "asdf " "%(bar)-5s"
            f "3.140" "%(baz).3f"
+           f "%asdf%" "%%%(bar)s%%"
+           f "Str: asdf % Int: 1" "Str: %(bar)s %% Int: %(foo)d"
 
 test_vsprintf_generics =
     do
     "foo: 5" @=? vsprintf "%s: %d" "foo" (5::Int)
     "%foo%:% %-1%\n%" @=? vsprintf "%%%s%%:%% %%%d%%\n%%" "foo" (-1::Integer)
-                          "baz: 3.140000" @=? vsprintf "%s: %f" "baz" (3.14::Rational)
+    "baz: 3.140000" @=? vsprintf "%s: %f" "baz" (3.14::Rational)
     "quux: 3.140000e+02" @=? vsprintf "%s: %e" "quux" (314::Double)
     "fe" @=? vsprintf "%x" (254::Int)
     "FE" @=? vsprintf "%X" (254::Int)
@@ -82,5 +89,5 @@ test_vsprintf_strings =
 tests = TestList [TestLabel "vsprintf" (TestCase test_vsprintf),
                   TestLabel "vsprintf generics" (TestCase test_vsprintf_generics),
                   TestLabel "vsprintf strings" (TestCase test_vsprintf_strings),
-                  TestLabel "vsprintf AL" (TestCase test_al)
+                  TestLabel "vsprintf AL&FM" (TestCase test_al_fm)
                  ]
\ No newline at end of file

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list