aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Faulhaber <git_net@infolace.com>2009-10-31 00:11:18 -0700
committerTom Faulhaber <git_net@infolace.com>2009-10-31 00:11:18 -0700
commit3f267049a38f205ac3c7d91173c63648f139e790 (patch)
treec7a61e812f3d0fdc3b7b62f49fbf1ab9ba774144 /src
parentd9c42218f493e7eb261677047008cedb67364ee8 (diff)
cl-format: ~$ wasn't handling negative numbers correctly
refs #40
Diffstat (limited to 'src')
-rw-r--r--src/clojure/contrib/pprint/cl-format.clj2
-rw-r--r--src/clojure/contrib/test_contrib/pprint/cl_format.clj17
2 files changed, 17 insertions, 2 deletions
diff --git a/src/clojure/contrib/pprint/cl-format.clj b/src/clojure/contrib/pprint/cl-format.clj
index 64fc4f30..b0531c14 100644
--- a/src/clojure/contrib/pprint/cl-format.clj
+++ b/src/clojure/contrib/pprint/cl-format.clj
@@ -759,7 +759,7 @@ Note this should only be used for the last one in the sequence"
d (:d params) ; digits after the decimal
n (:n params) ; minimum digits before the decimal
w (:w params) ; minimum field width
- add-sign (and (:at params) (not (neg? arg)))
+ add-sign (or (:at params) (neg? arg))
[rounded-mantissa scaled-exp _] (round-str mantissa exp d nil)
#^String fixed-repr (get-fixed rounded-mantissa scaled-exp d)
full-repr (str (apply str (repeat (- n (.indexOf fixed-repr (int \.))) \0)) fixed-repr)
diff --git a/src/clojure/contrib/test_contrib/pprint/cl_format.clj b/src/clojure/contrib/test_contrib/pprint/cl_format.clj
index 81d64c78..6684bff2 100644
--- a/src/clojure/contrib/test_contrib/pprint/cl_format.clj
+++ b/src/clojure/contrib/test_contrib/pprint/cl_format.clj
@@ -176,7 +176,22 @@
(cl-format nil "~3,5,14@$" 22.375) " +00022.375"
(cl-format nil "~3,5,14@$" 22.375) " +00022.375"
(cl-format nil "~3,5,14@:$" 22.375) "+ 00022.375"
- (cl-format nil "~3,,14@:$" 0.375) "+ 0.375")
+ (cl-format nil "~3,,14@:$" 0.375) "+ 0.375"
+ (cl-format nil "~1,1$" -12.0) "-12.0"
+ (cl-format nil "~1,1$" 12.0) "12.0"
+ (cl-format nil "~1,1$" 12.0) "12.0"
+ (cl-format nil "~1,1@$" 12.0) "+12.0"
+ (cl-format nil "~1,1,8,' @:$" 12.0) "+ 12.0"
+ (cl-format nil "~1,1,8,' @$" 12.0) " +12.0"
+ (cl-format nil "~1,1,8,' :$" 12.0) " 12.0"
+ (cl-format nil "~1,1,8,' $" 12.0) " 12.0"
+ (cl-format nil "~1,1,8,' @:$" -12.0) "- 12.0"
+ (cl-format nil "~1,1,8,' @$" -12.0) " -12.0"
+ (cl-format nil "~1,1,8,' :$" -12.0) "- 12.0"
+ (cl-format nil "~1,1,8,' $" -12.0) " -12.0")
+
+(simple-tests f-tests
+ (cl-format nil "~,1f" -12.0) "-12.0")
(simple-tests ampersand-tests
(cl-format nil "The quick brown ~a jumped over ~d lazy dogs" 'elephant 5)