From 2e7935d66e209549011b6b44790ef6e11fff7eaf Mon Sep 17 00:00:00 2001
From: Doug Coleman <doug.coleman@gmail.com>
Date: Sat, 27 Aug 2011 15:54:25 -0500
Subject: [PATCH] Change the way %coverage works, make coverage word use
 map-words to hit private vocabs, make %coverage only work on vocabs.

---
 basis/tools/coverage/coverage-docs.factor |  8 ++++----
 basis/tools/coverage/coverage.factor      | 25 ++++++++---------------
 2 files changed, 13 insertions(+), 20 deletions(-)

diff --git a/basis/tools/coverage/coverage-docs.factor b/basis/tools/coverage/coverage-docs.factor
index 0724e7f1c6..fcae9ae156 100644
--- a/basis/tools/coverage/coverage-docs.factor
+++ b/basis/tools/coverage/coverage-docs.factor
@@ -17,10 +17,10 @@ HELP: each-word
 }
 { $description "Calls a quotation on every word in the vocabulary and its private vocabulary, if there is one." } ;
 
-HELP: map-word
+HELP: map-words
 { $values
     { "string" string } { "quot" quotation }
-    { "seq" sequence }
+    { "sequence" sequence }
 }
 { $description "Calls a quotation on every word in the vocabulary and its private vocabulary, if there is one, and collects the results." } ;
 
@@ -57,7 +57,7 @@ HELP: coverage.
 
 HELP: %coverage
 { $values
-    { "object" object }
+    { "string" string }
     { "x" double }
 }
 { $description "Returns a fraction representing the number of quotations called compared to the number of quotations that exist in a vocabulary or word." } ;
@@ -69,6 +69,6 @@ ARTICLE: "tools.coverage" "Coverage tool"
 "Examining coverage data:"
 { $subsections coverage coverage. %coverage }
 "Combinators for iterating over words in a vocabulary:"
-{ $subsections each-word map-word } ;
+{ $subsections each-word map-words } ;
 
 ABOUT: "tools.coverage"
diff --git a/basis/tools/coverage/coverage.factor b/basis/tools/coverage/coverage.factor
index 791603583a..a655dfaab0 100644
--- a/basis/tools/coverage/coverage.factor
+++ b/basis/tools/coverage/coverage.factor
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors assocs fry io kernel math prettyprint
 quotations sequences sequences.deep splitting strings
-tools.annotations vocabs words ;
+tools.annotations vocabs words arrays ;
 IN: tools.coverage
 
 TUPLE: coverage < identity-tuple executed? ;
@@ -28,7 +28,7 @@ PRIVATE>
         [ [ words ] dip each ] 2bi
     ] if ; inline
 
-: map-word ( string quot -- seq )
+: map-words ( string quot -- sequence )
     over ".private" tail? [
         [ words ] dip map
     ] [
@@ -67,7 +67,7 @@ M: word toggle-coverage
 GENERIC: coverage ( object -- seq )
 
 M: string coverage
-    words [ dup coverage ] { } map>assoc ;
+    [ dup coverage 2array ] map-words ;
 
 M: word coverage ( word -- seq )
     "coverage" word-prop >alist
@@ -83,7 +83,7 @@ M: word coverage.
         drop
     ] [
         [ name>> ":" append print ]
-        [ [ bl bl bl bl . ] each ] bi*
+        [ [ "    " write . ] each ] bi*
     ] if-empty ;
 
 <PRIVATE
@@ -91,20 +91,13 @@ M: word coverage.
 GENERIC: count-callables ( object -- n )
 
 M: string count-callables
-    [ count-callables ] map-word sum ;
+    [ count-callables ] map-words sum ;
 
 M: word count-callables
-    def>> [ callable? ] deep-filter length ;
-
-: calculate-%coverage ( object quot -- x )
-    [ count-callables ] bi [ swap - ] keep /f ; inline
+    "coverage" word-prop assoc-size ;
 
 PRIVATE>
 
-GENERIC: %coverage ( object -- x )
-
-M: string %coverage
-    [ coverage values concat length ] calculate-%coverage ;
-
-M: word %coverage
-    [ coverage length ] calculate-%coverage ;
+: %coverage ( string -- x )
+    [ coverage values concat length ]
+    [ count-callables ] bi [ swap - ] keep /f ; inline