C0 code coverage information

Generated on Fri Jul 11 15:55:34 -0700 2008 with rcov 0.7.0


Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
Name Total lines Lines of code Total coverage Code coverage
lib/openid/kvform.rb 136 97
100.0% 
100.0% 
  1 
  2 module OpenID
  3 
  4   class KVFormError < Exception
  5   end
  6 
  7   module Util
  8 
  9     def Util.seq_to_kv(seq, strict=false)
 10       # Represent a sequence of pairs of strings as newline-terminated
 11       # key:value pairs. The pairs are generated in the order given.
 12       #
 13       # @param seq: The pairs
 14       #
 15       # returns a string representation of the sequence
 16       err = lambda { |msg|
 17         msg = "seq_to_kv warning: #{msg}: #{seq.inspect}"
 18         if strict
 19           raise KVFormError, msg
 20         else
 21           Util.log(msg)
 22         end
 23       }
 24 
 25       lines = []
 26       seq.each { |k, v|
 27         if !k.is_a?(String)
 28           err.call("Converting key to string: #{k.inspect}")
 29           k = k.to_s
 30         end
 31 
 32         if !k.index("\n").nil?
 33           raise KVFormError, "Invalid input for seq_to_kv: key contains newline: #{k.inspect}"
 34         end
 35 
 36         if !k.index(":").nil?
 37           raise KVFormError, "Invalid input for seq_to_kv: key contains colon: #{k.inspect}"
 38         end
 39 
 40         if k.strip() != k
 41           err.call("Key has whitespace at beginning or end: #{k.inspect}")
 42         end
 43 
 44         if !v.is_a?(String)
 45           err.call("Converting value to string: #{v.inspect}")
 46           v = v.to_s
 47         end
 48 
 49         if !v.index("\n").nil?
 50           raise KVFormError, "Invalid input for seq_to_kv: value contains newline: #{v.inspect}"
 51         end
 52 
 53         if v.strip() != v
 54           err.call("Value has whitespace at beginning or end: #{v.inspect}")
 55         end
 56 
 57         lines << k + ":" + v + "\n"
 58       }
 59 
 60       return lines.join("")
 61     end
 62 
 63     def Util.kv_to_seq(data, strict=false)
 64       # After one parse, seq_to_kv and kv_to_seq are inverses, with no
 65       # warnings:
 66       #
 67       # seq = kv_to_seq(s)
 68       # seq_to_kv(kv_to_seq(seq)) == seq
 69       err = lambda { |msg|
 70         msg = "kv_to_seq warning: #{msg}: #{data.inspect}"
 71         if strict
 72           raise KVFormError, msg
 73         else
 74           Util.log(msg)
 75         end
 76       }
 77 
 78       lines = data.split("\n")
 79       if data.length == 0
 80         return []
 81       end
 82 
 83       if data[-1].chr != "\n"
 84         err.call("Does not end in a newline")
 85         # We don't expect the last element of lines to be an empty
 86         # string because split() doesn't behave that way.
 87       end
 88 
 89       pairs = []
 90       line_num = 0
 91       lines.each { |line|
 92         line_num += 1
 93 
 94         # Ignore blank lines
 95         if line.strip() == ""
 96           next
 97         end
 98 
 99         pair = line.split(':', 2)
100         if pair.length == 2
101           k, v = pair
102           k_s = k.strip()
103           if k_s != k
104             msg = "In line #{line_num}, ignoring leading or trailing whitespace in key #{k.inspect}"
105             err.call(msg)
106           end
107 
108           if k_s.length == 0
109             err.call("In line #{line_num}, got empty key")
110           end
111 
112           v_s = v.strip()
113           if v_s != v
114             msg = "In line #{line_num}, ignoring leading or trailing whitespace in value #{v.inspect}"
115             err.call(msg)
116           end
117 
118           pairs << [k_s, v_s]
119         else
120           err.call("Line #{line_num} does not contain a colon")
121         end
122       }
123 
124       return pairs
125     end
126 
127     def Util.dict_to_kv(d)
128       return seq_to_kv(d.entries.sort)
129     end
130 
131     def Util.kv_to_dict(s)
132       seq = kv_to_seq(s)
133       return Hash[*seq.flatten]
134     end
135   end
136 end

Generated using the rcov code coverage analysis tool for Ruby version 0.7.0.

Valid XHTML 1.0! Valid CSS!