22
33module Mutant
44 module Meta
5+ # rubocop:disable Metrics/ClassLength
56 class Example
67 # Example verification
78 class Verification
8- include Adamantium , Anima . new ( :example , :mutations )
9+ include Adamantium , Anima . new ( :example , :invalid , :valid )
10+
11+ def self . from_mutations ( example :, mutations :)
12+ valid , invalid = [ ] , [ ]
13+
14+ mutations . each do |mutation |
15+ mutation . either ( invalid . public_method ( :<< ) , valid . public_method ( :<< ) )
16+ end
17+
18+ new ( example :, invalid :, valid :)
19+ end
920
1021 # Test if mutation was verified successfully
1122 #
1223 # @return [Boolean]
1324 def success?
1425 [
15- original_verification ,
16- invalid ,
26+ invalid_report ,
1727 missing ,
1828 no_diffs ,
29+ original_verification_report ,
1930 unexpected
2031 ] . all? ( &:empty? )
2132 end
@@ -29,12 +40,12 @@ def error_report
2940
3041 def reports
3142 reports = [ example . location ]
32- reports . concat ( original )
33- reports . concat ( original_verification )
43+ reports . concat ( original_report )
44+ reports . concat ( original_verification_report )
3445 reports . concat ( make_report ( 'Missing mutations:' , missing ) )
3546 reports . concat ( make_report ( 'Unexpected mutations:' , unexpected ) )
3647 reports . concat ( make_report ( 'No-Diff mutations:' , no_diffs ) )
37- reports . concat ( invalid )
48+ reports . concat ( invalid_report )
3849 end
3950
4051 def make_report ( label , mutations )
@@ -52,15 +63,15 @@ def report_mutation(mutation)
5263 ]
5364 end
5465
55- def original
66+ def original_report
5667 [
5768 "Original: (operators: #{ example . operators . class . operators_name } )" ,
5869 example . node ,
5970 example . original_source
6071 ]
6172 end
6273
63- def original_verification
74+ def original_verification_report
6475 validation = Unparser ::Validation . from_string ( example . original_source )
6576 if validation . success?
6677 [ ]
@@ -77,30 +88,34 @@ def prefix(prefix, string)
7788 end . join
7889 end
7990
80- def invalid
81- mutations . each_with_object ( [ ] ) do |mutation , aggregate |
82- validation = Unparser ::Validation . from_node ( mutation . node )
83- aggregate << prefix ( '[invalid-mutation]' , validation . report ) unless validation . success?
91+ def invalid_report
92+ invalid . map do |validation |
93+ prefix ( '[invalid-mutation]' , validation . report )
8494 end
8595 end
86- memoize :invalid
96+ memoize :invalid_report
8797
8898 def unexpected
89- mutations . reject do |mutation |
99+ valid . reject do |mutation |
90100 example . expected . any? { |expected | expected . node . eql? ( mutation . node ) }
91101 end
92102 end
93103 memoize :unexpected
94104
95105 def missing
96- ( example . expected . map ( &:node ) - mutations . map ( &:node ) ) . map do |node |
97- Mutation ::Evil . new ( subject : example , node :)
106+ example . expected . each_with_object ( [ ] ) do |expected , aggregate |
107+ next if valid . any? { |mutation | expected . node . eql? ( mutation . node ) }
108+ aggregate << Mutation ::Evil . new (
109+ node : expected . node ,
110+ source : expected . original_source ,
111+ subject : example
112+ )
98113 end
99114 end
100115 memoize :missing
101116
102117 def no_diffs
103- mutations . select { |mutation | mutation . source . eql? ( example . original_source_generated ) }
118+ valid . select { |mutation | mutation . source . eql? ( example . source ) }
104119 end
105120 memoize :no_diffs
106121
0 commit comments