Rspec Steps C0 Coverage Information - RCov

rcov/ruby/1.8/gems/diff-lcs-1.1.2/lib/diff/lcs/change.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
rcov/ruby/1.8/gems/diff-lcs-1.1.2/lib/diff/lcs/change.rb 169 110
54.44%
31.82%

Key

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.

Coverage Details

1 #! /usr/env/bin ruby
2 #--
3 # Copyright 2004 Austin Ziegler <diff-lcs@halostatue.ca>
4 #   adapted from:
5 #     Algorithm::Diff (Perl) by Ned Konz <perl@bike-nomad.com>
6 #     Smalltalk by Mario I. Wolczko <mario@wolczko.com>
7 #   implements McIlroy-Hunt diff algorithm
8 #
9 # This program is free software. It may be redistributed and/or modified under
10 # the terms of the GPL version 2 (or later), the Perl Artistic licence, or the
11 # Ruby licence.
12 # 
13 # $Id: change.rb,v 1.4 2004/08/08 20:33:09 austin Exp $
14 #++
15 # Provides Diff::LCS::Change and Diff::LCS::ContextChange.
16 
17   # Centralises the change test code in Diff::LCS::Change and
18   # Diff::LCS::ContextChange, since it's the same for both classes.
19 module Diff::LCS::ChangeTypeTests
20   def deleting?
21     @action == '-'
22   end
23 
24   def adding?
25     @action == '+'
26   end
27 
28   def unchanged?
29     @action == '='
30   end
31 
32   def changed?
33     @changed == '!'
34   end
35 
36   def finished_a?
37     @changed == '>'
38   end
39 
40   def finished_b?
41     @changed == '<'
42   end
43 end
44 
45   # Represents a simplistic (non-contextual) change. Represents the removal or
46   # addition of an element from either the old or the new sequenced enumerable.
47 class Diff::LCS::Change
48     # Returns the action this Change represents. Can be '+' (#adding?), '-'
49     # (#deleting?), '=' (#unchanged?), # or '!' (#changed?). When created by
50     # Diff::LCS#diff or Diff::LCS#sdiff, it may also be '>' (#finished_a?) or
51     # '<' (#finished_b?).
52   attr_reader :action
53   attr_reader :position
54   attr_reader :element
55 
56   include Comparable
57   def ==(other)
58     (self.action == other.action) and
59     (self.position == other.position) and
60     (self.element == other.element)
61   end
62 
63   def <=>(other)
64     r = self.action <=> other.action
65     r = self.position <=> other.position if r.zero?
66     r = self.element <=> other.element if r.zero?
67     r
68   end
69 
70   def initialize(action, position, element)
71     @action = action
72     @position = position
73     @element = element
74   end
75 
76     # Creates a Change from an array produced by Change#to_a.
77   def to_a
78     [@action, @position, @element]
79   end
80 
81   def self.from_a(arr)
82     Diff::LCS::Change.new(arr[0], arr[1], arr[2])
83   end
84 
85   include Diff::LCS::ChangeTypeTests
86 end
87 
88   # Represents a contextual change. Contains the position and values of the
89   # elements in the old and the new sequenced enumerables as well as the action
90   # taken.
91 class Diff::LCS::ContextChange
92     # Returns the action this Change represents. Can be '+' (#adding?), '-'
93     # (#deleting?), '=' (#unchanged?), # or '!' (#changed?). When
94     # created by Diff::LCS#diff or Diff::LCS#sdiff, it may also be '>'
95     # (#finished_a?) or '<' (#finished_b?).
96   attr_reader :action
97   attr_reader :old_position
98   attr_reader :old_element
99   attr_reader :new_position
100   attr_reader :new_element
101 
102   include Comparable
103 
104   def ==(other)
105     (@action == other.action) and
106     (@old_position == other.old_position) and
107     (@new_position == other.new_position) and
108     (@old_element == other.old_element) and
109     (@new_element == other.new_element)
110   end
111 
112   def inspect(*args)
113     %Q(#<#{self.class.name}:#{__id__} @action=#{action} positions=#{old_position},#{new_position} elements=#{old_element.inspect},#{new_element.inspect}>)
114   end
115 
116   def <=>(other)
117     r = @action <=> other.action
118     r = @old_position <=> other.old_position if r.zero?
119     r = @new_position <=> other.new_position if r.zero?
120     r = @old_element <=> other.old_element if r.zero?
121     r = @new_element <=> other.new_element if r.zero?
122     r
123   end
124 
125   def initialize(action, old_position, old_element, new_position, new_element)
126     @action = action
127     @old_position = old_position
128     @old_element = old_element
129     @new_position = new_position
130     @new_element = new_element
131   end
132 
133   def to_a
134     [@action, [@old_position, @old_element], [@new_position, @new_element]]
135   end
136 
137     # Creates a ContextChange from an array produced by ContextChange#to_a.
138   def self.from_a(arr)
139     if arr.size == 5
140       Diff::LCS::ContextChange.new(arr[0], arr[1], arr[2], arr[3], arr[4])
141     else
142       Diff::LCS::ContextChange.new(arr[0], arr[1][0], arr[1][1], arr[2][0],
143                                    arr[2][1])
144     end
145   end
146 
147     # Simplifies a context change for use in some diff callbacks. '<' actions
148     # are converted to '-' and '>' actions are converted to '+'. 
149   def self.simplify(event)
150     ea = event.to_a
151 
152     case ea[0]
153     when '-'
154       ea[2][1] = nil
155     when '<'
156       ea[0] = '-'
157       ea[2][1] = nil
158     when '+'
159       ea[1][1] = nil
160     when '>'
161       ea[0] = '+'
162       ea[1][1] = nil
163     end
164 
165     Diff::LCS::ContextChange.from_a(ea)
166   end
167 
168   include Diff::LCS::ChangeTypeTests
169 end

Generated on Fri Apr 22 17:22:41 -0700 2011 with rcov 0.9.8