mutant 0.9.9 → 0.9.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,97 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Mutant
4
- # Class to create diffs from source code
5
- class Diff
6
- include Adamantium::Flat, Concord.new(:old, :new)
7
-
8
- ADDITION = '+'
9
- DELETION = '-'
10
- NEWLINE = "\n"
11
-
12
- # Unified source diff between old and new
13
- #
14
- # @return [String]
15
- # if there is exactly one diff
16
- #
17
- # @return [nil]
18
- # otherwise
19
- def diff
20
- return if diffs.empty?
21
-
22
- minimized_hunk.diff(:unified) + NEWLINE
23
- end
24
- memoize :diff
25
-
26
- # Colorized unified source diff between old and new
27
- #
28
- # @return [String]
29
- # if there is a diff
30
- #
31
- # @return [nil]
32
- # otherwise
33
- def colorized_diff
34
- return unless diff
35
- diff.lines.map(&self.class.method(:colorize_line)).join
36
- end
37
- memoize :colorized_diff
38
-
39
- # Build new object from source strings
40
- #
41
- # @param [String] old
42
- # @param [String] new
43
- #
44
- # @return [Diff]
45
- def self.build(old, new)
46
- new(lines(old), lines(new))
47
- end
48
-
49
- # Break up source into lines
50
- #
51
- # @param [String] source
52
- #
53
- # @return [Array<String>]
54
- def self.lines(source)
55
- source.lines.map(&:chomp)
56
- end
57
- private_class_method :lines
58
-
59
- private
60
-
61
- def diffs
62
- ::Diff::LCS.diff(old, new)
63
- end
64
-
65
- def hunks
66
- diffs.map do |diff|
67
- ::Diff::LCS::Hunk.new(old.map(&:dup), new, diff, max_length, 0)
68
- end
69
- end
70
-
71
- def minimized_hunk
72
- head, *tail = hunks
73
-
74
- tail.reduce(head) do |left, right|
75
- right.merge(left)
76
- right
77
- end
78
- end
79
-
80
- def max_length
81
- [old, new].map(&:length).max
82
- end
83
-
84
- def self.colorize_line(line)
85
- case line[0]
86
- when ADDITION
87
- Color::GREEN
88
- when DELETION
89
- Color::RED
90
- else
91
- Color::NONE
92
- end.format(line)
93
- end
94
- private_class_method :colorize_line
95
-
96
- end # Diff
97
- end # Mutant
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.shared_examples 'no block evaluation' do
4
- context 'with block' do
5
- let(:block) { -> { fail } }
6
-
7
- it 'does not evaluate block' do
8
- apply
9
- end
10
- end
11
- end
12
-
13
- RSpec.shared_examples 'requires block' do
14
- context 'without block' do
15
- let(:block) { nil }
16
-
17
- specify do
18
- expect { apply }.to raise_error(LocalJumpError)
19
- end
20
- end
21
- end
22
-
23
- RSpec.shared_examples 'returns self' do
24
- it 'returns self' do
25
- expect(apply).to be(subject)
26
- end
27
- end
28
-
29
- RSpec.shared_examples '#apply block evaluation' do
30
- it 'evaluates block and returns its wrapped result' do
31
- expect { expect(apply).to eql(block_result) }
32
- .to change(yields, :to_a)
33
- .from([])
34
- .to([value])
35
- end
36
- end
37
-
38
- RSpec.shared_examples 'Functor#fmap block evaluation' do
39
- it 'evaluates block and returns its wrapped result' do
40
- expect { expect(apply).to eql(described_class.new(block_result)) }
41
- .to change(yields, :to_a)
42
- .from([])
43
- .to([value])
44
- end
45
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module TestApp
4
- def self.root
5
- File.expand_path('../../test_app', __dir__)
6
- end
7
- end # TestApp
@@ -1,6 +0,0 @@
1
- ---
2
- - "lib/mutant/subject/method/instance.rb:9: warning: undefining `initialize' may cause serious problems"
3
- - 'lib/parallel.rb:222: warning: shadowing outer local variable - args'
4
- - 'lib/parallel.rb:227: warning: shadowing outer local variable - args'
5
- - 'lib/parser/lexer.rb:10836: warning: assigned but unused variable - testEof'
6
- - 'lib/regexp_parser/scanner.rb:1146: warning: assigned but unused variable - testEof'
@@ -1,189 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe Mutant::Diff do
4
- let(:object) { described_class }
5
-
6
- describe '.build' do
7
-
8
- subject { object.build(old_string, new_string) }
9
-
10
- let(:old_string) { "foo\nbar" }
11
- let(:new_string) { "bar\nbaz" }
12
-
13
- it { should eql(Mutant::Diff.new(%w[foo bar], %w[bar baz])) }
14
-
15
- end
16
-
17
- describe '#colorized_diff' do
18
- let(:object) { described_class.new(old, new) }
19
-
20
- subject { object.colorized_diff }
21
-
22
- context 'when there is a diff at begin of hunk' do
23
- let(:old) { %w[foo bar] }
24
- let(:new) { %w[baz bar] }
25
-
26
- let(:expectation) do
27
- [
28
- "@@ -1,3 +1,3 @@\n",
29
- Mutant::Color::RED.format("-foo\n"),
30
- Mutant::Color::GREEN.format("+baz\n"),
31
- " bar\n"
32
- ].join
33
- end
34
-
35
- it { should eql(expectation) }
36
-
37
- it_should_behave_like 'an idempotent method'
38
- end
39
-
40
- context 'when there is no diff' do
41
- let(:old) { '' }
42
- let(:new) { '' }
43
-
44
- it { should be(nil) }
45
-
46
- it_should_behave_like 'an idempotent method'
47
- end
48
- end
49
-
50
- describe '#diff' do
51
- let(:object) { described_class.new(old, new) }
52
-
53
- subject { object.diff }
54
-
55
- context 'when there is a diff at begin and end' do
56
- let(:old) { %w[foo bar foo] }
57
- let(:new) { %w[baz bar baz] }
58
-
59
- let(:expectation) do
60
- <<~STR
61
- @@ -1,4 +1,4 @@
62
- -foo
63
- +baz
64
- bar
65
- -foo
66
- +baz
67
- STR
68
- end
69
-
70
- it { should eql(expectation) }
71
-
72
- it_should_behave_like 'an idempotent method'
73
- end
74
-
75
- context 'when there is a diff at begin of hunk' do
76
- let(:old) { %w[foo bar] }
77
- let(:new) { %w[baz bar] }
78
-
79
- let(:expectation) do
80
- <<~STR
81
- @@ -1,3 +1,3 @@
82
- -foo
83
- +baz
84
- bar
85
- STR
86
- end
87
-
88
- it { should eql(expectation) }
89
-
90
- it_should_behave_like 'an idempotent method'
91
- end
92
-
93
- context 'when there is a diff NOT at begin of hunk' do
94
- let(:old) { %w[foo bar] }
95
- let(:new) { %w[foo baz bar] }
96
-
97
- let(:expectation) do
98
- <<~STR
99
- @@ -1,3 +1,4 @@
100
- foo
101
- +baz
102
- bar
103
- STR
104
- end
105
-
106
- it { should eql(expectation) }
107
-
108
- it_should_behave_like 'an idempotent method'
109
- end
110
-
111
- context 'when the diff has a long context at begin' do
112
- let(:old) { %w[foo bar baz boz a b c] }
113
- let(:new) { %w[foo bar baz boz a b c other] }
114
-
115
- let(:expectation) do
116
- <<~STR
117
- @@ -1,8 +1,9 @@
118
- foo
119
- bar
120
- baz
121
- boz
122
- a
123
- b
124
- c
125
- +other
126
- STR
127
- end
128
-
129
- it { should eql(expectation) }
130
-
131
- it_should_behave_like 'an idempotent method'
132
- end
133
-
134
- context 'when the diff has a long context at end, deleting' do
135
- let(:old) { %w[other foo bar baz boz a b c] }
136
- let(:new) { %w[foo bar baz boz a b c] }
137
-
138
- let(:expectation) do
139
- <<~STR
140
- @@ -1,9 +1,8 @@
141
- -other
142
- foo
143
- bar
144
- baz
145
- boz
146
- a
147
- b
148
- c
149
- STR
150
- end
151
-
152
- it { should eql(expectation) }
153
-
154
- it_should_behave_like 'an idempotent method'
155
- end
156
-
157
- context 'when the diff has a long context at end, inserting' do
158
- let(:old) { %w[foo bar baz boz a b c] }
159
- let(:new) { %w[other foo bar baz boz a b c] }
160
-
161
- let(:expectation) do
162
- <<~STR
163
- @@ -1,8 +1,9 @@
164
- +other
165
- foo
166
- bar
167
- baz
168
- boz
169
- a
170
- b
171
- c
172
- STR
173
- end
174
-
175
- it { should eql(expectation) }
176
-
177
- it_should_behave_like 'an idempotent method'
178
- end
179
-
180
- context 'when there is no diff' do
181
- let(:old) { '' }
182
- let(:new) { '' }
183
-
184
- it { should be(nil) }
185
-
186
- it_should_behave_like 'an idempotent method'
187
- end
188
- end
189
- end