ninja-differ 1.0.0
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.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +32 -0
- data/LICENSE +23 -0
- data/README.md +149 -0
- data/Rakefile +29 -0
- data/Vagrantfile +47 -0
- data/differ.gemspec +22 -0
- data/lib/differ/change.rb +30 -0
- data/lib/differ/diff.rb +97 -0
- data/lib/differ/format/ascii.rb +27 -0
- data/lib/differ/format/color.rb +27 -0
- data/lib/differ/format/html.rb +27 -0
- data/lib/differ/format/patch.rb +28 -0
- data/lib/differ/string.rb +24 -0
- data/lib/differ/version.rb +3 -0
- data/lib/differ.rb +97 -0
- data/provision.sh +74 -0
- data/spec/differ/change_spec.rb +82 -0
- data/spec/differ/diff_spec.rb +298 -0
- data/spec/differ/format/ascii_spec.rb +18 -0
- data/spec/differ/format/color_spec.rb +18 -0
- data/spec/differ/format/html_spec.rb +18 -0
- data/spec/differ/format/patch_spec.rb +18 -0
- data/spec/differ/string_spec.rb +59 -0
- data/spec/differ_spec.rb +512 -0
- data/spec/spec_helper.rb +32 -0
- metadata +86 -0
data/provision.sh
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
# Shell user settings.
|
4
|
+
USER_NAME=vagrant
|
5
|
+
USER_HOME=/home/$USER_NAME
|
6
|
+
DEFAULT_RUBY='3.1.2'
|
7
|
+
|
8
|
+
###############################################################################
|
9
|
+
# Functions
|
10
|
+
###############################################################################
|
11
|
+
# Most of the time we can get by with this DRY wrapper for sudo commands.
|
12
|
+
as_user() {
|
13
|
+
echo "$USER_NAME:~$ > ${*}"
|
14
|
+
su -l $USER_NAME -c "$*"
|
15
|
+
}
|
16
|
+
|
17
|
+
###############################################################################
|
18
|
+
# Base System
|
19
|
+
###############################################################################
|
20
|
+
apt-get -y update
|
21
|
+
apt-get -yfV dist-upgrade
|
22
|
+
|
23
|
+
###############################################################################
|
24
|
+
# rbenv & ruby-build, and Rubies
|
25
|
+
# From https://github.com/sstephenson/rbenv
|
26
|
+
# and https://github.com/sstephenson/ruby-build
|
27
|
+
###############################################################################
|
28
|
+
|
29
|
+
# Install dependencies.
|
30
|
+
apt-get install -yfV \
|
31
|
+
build-essential \
|
32
|
+
curl \
|
33
|
+
git-core \
|
34
|
+
libcurl4-openssl-dev \
|
35
|
+
libreadline-dev \
|
36
|
+
libsqlite3-dev \
|
37
|
+
libssl-dev \
|
38
|
+
libxml2-dev \
|
39
|
+
libxslt1-dev \
|
40
|
+
libyaml-dev \
|
41
|
+
software-properties-common \
|
42
|
+
sqlite3 \
|
43
|
+
zlib1g-dev \
|
44
|
+
autoconf \
|
45
|
+
bison \
|
46
|
+
libreadline6-dev \
|
47
|
+
libncurses5-dev \
|
48
|
+
libffi-dev \
|
49
|
+
libgdbm6 \
|
50
|
+
libgdbm-dev \
|
51
|
+
libdb-dev \
|
52
|
+
libgmp-dev \
|
53
|
+
patch \
|
54
|
+
rustc \
|
55
|
+
uuid-dev
|
56
|
+
|
57
|
+
# Install rbenv and ruby-build.
|
58
|
+
as_user "git clone https://github.com/sstephenson/rbenv.git $USER_HOME/.rbenv"
|
59
|
+
as_user "git clone https://github.com/sstephenson/ruby-build.git $USER_HOME/.rbenv/plugins/ruby-build"
|
60
|
+
|
61
|
+
# Setup bash to use rbenv for $USER_NAME.
|
62
|
+
truncate -s 0 $USER_HOME/.bashrc
|
63
|
+
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> $USER_HOME/.bashrc
|
64
|
+
echo 'eval "$(rbenv init -)"' >> $USER_HOME/.bashrc
|
65
|
+
echo 'cd /vagrant' >> $USER_HOME/.bashrc
|
66
|
+
|
67
|
+
as_user "mkdir ~/.gem"
|
68
|
+
echo 'gem: --no-document' > $USER_HOME/.gemrc
|
69
|
+
|
70
|
+
# Install the requested version of Ruby, with Bundler.
|
71
|
+
as_user "rbenv install -s $DEFAULT_RUBY"
|
72
|
+
as_user "rbenv global $DEFAULT_RUBY"
|
73
|
+
as_user "RBENV_VERSION=$DEFAULT_RUBY gem install bundler"
|
74
|
+
as_user "cd /vagrant && bundle"
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Differ::Change do
|
4
|
+
before(:each) do
|
5
|
+
@format = Module.new { def self.call(c); end }
|
6
|
+
Differ.format = @format
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '(empty)' do
|
10
|
+
before(:each) do
|
11
|
+
@change = Differ::Change.new()
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should have a default insert' do
|
15
|
+
expect(@change.insert).to eq('')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should have a default delete' do
|
19
|
+
expect(@change.delete).to eq('')
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should stringify to ""' do
|
23
|
+
expect(@format).to receive(:call).once.and_return('')
|
24
|
+
expect(@change.to_s).to eq('')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '(insert only)' do
|
29
|
+
before(:each) do
|
30
|
+
@change = Differ::Change.new(:insert => 'foo')
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should populate the :insert parameter' do
|
34
|
+
expect(@change.insert).to eq('foo')
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should have a default delete' do
|
38
|
+
expect(@change.delete).to eq('')
|
39
|
+
end
|
40
|
+
|
41
|
+
it { expect(@change).to be_an_insert }
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '(delete only)' do
|
45
|
+
before(:each) do
|
46
|
+
@change = Differ::Change.new(:delete => 'bar')
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should have a default :insert' do
|
50
|
+
expect(@change.insert).to eq('')
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should populate the :delete parameter' do
|
54
|
+
expect(@change.delete).to eq('bar')
|
55
|
+
end
|
56
|
+
|
57
|
+
it { expect(@change).to be_a_delete }
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '(both insert and delete)' do
|
61
|
+
before(:each) do
|
62
|
+
@change = Differ::Change.new(:insert => 'foo', :delete => 'bar')
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should populate the :insert parameter' do
|
66
|
+
expect(@change.insert).to eq('foo')
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should populate the :delete parameter' do
|
70
|
+
expect(@change.delete).to eq('bar')
|
71
|
+
end
|
72
|
+
|
73
|
+
it { expect(@change).to be_an_insert }
|
74
|
+
it { expect(@change).to be_a_delete }
|
75
|
+
it { expect(@change).to be_a_change }
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should stringify via the current format's #format method" do
|
79
|
+
expect(@format).to receive(:call).once
|
80
|
+
Differ::Change.new.to_s
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,298 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Differ::Diff do
|
4
|
+
before(:each) do
|
5
|
+
Differ.separator = nil
|
6
|
+
@diff = Differ::Diff.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#to_s' do
|
10
|
+
before(:each) do
|
11
|
+
@format = Differ.format
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should concatenate the result list' do
|
15
|
+
expect(diff('a', 'b', 'c').to_s).to eq('abc')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should concatenate without regard for the Differ.separator' do
|
19
|
+
Differ.separator = '*'
|
20
|
+
expect(diff('a', 'b', 'c').to_s).to eq('abc')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should delegate insertion changes to Differ#format' do
|
24
|
+
i = +'b'
|
25
|
+
expect(@format).to receive(:call).once.with(i).and_return('!')
|
26
|
+
expect(diff('a', i, 'c').to_s).to eq('a!c')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#format_as' do
|
31
|
+
before(:each) do
|
32
|
+
@change = +'b'
|
33
|
+
Differ.format = Module.new { def self.call(c); raise :error; end }
|
34
|
+
@format = Module.new { def self.call(c); end }
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should delegate change formatting to the given format' do
|
38
|
+
expect(@format).to receive(:call).once.with(@change).and_return('!')
|
39
|
+
expect(diff('a', @change, 'c').format_as(@format)).to eq('a!c')
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should use Differ#format_for to grab the correct format' do
|
43
|
+
expect(Differ).to receive(:format_for).once.with(@format)
|
44
|
+
diff().format_as(@format)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#same' do
|
49
|
+
it 'should append to the result list' do
|
50
|
+
@diff.same('c')
|
51
|
+
expect(@diff).to eq(diff('c'))
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should concatenate its arguments' do
|
55
|
+
@diff.same('a', 'b', 'c', 'd')
|
56
|
+
expect(@diff).to eq(diff('abcd'))
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should join its arguments with Differ.separator' do
|
60
|
+
Differ.separator = '*'
|
61
|
+
@diff.same(*'a*b*c*d'.split)
|
62
|
+
expect(@diff).to eq(diff('a*b*c*d'))
|
63
|
+
end
|
64
|
+
|
65
|
+
describe 'when the last result was a String' do
|
66
|
+
before(:each) do
|
67
|
+
@diff = diff('a')
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should append to the last result' do
|
71
|
+
@diff.same('b')
|
72
|
+
expect(@diff).to eq(diff('ab'))
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should join to the last result with Differ.separator' do
|
76
|
+
Differ.separator = '*'
|
77
|
+
@diff.same('b')
|
78
|
+
expect(@diff).to eq(diff('a*b'))
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe 'when the last result was a change' do
|
83
|
+
before(:each) do
|
84
|
+
@diff = diff('z' >> 'd')
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should append to the result list' do
|
88
|
+
@diff.same('a')
|
89
|
+
expect(@diff).to eq(diff(('z' >> 'd'), 'a'))
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should prepend Differ.separator to the result' do
|
93
|
+
Differ.separator = '*'
|
94
|
+
@diff.same('a')
|
95
|
+
expect(@diff).to eq(diff(('z' >> 'd'), '*a'))
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should do nothing to a leading Differ.separator on the insert" do
|
99
|
+
@diff = diff('a', ('*-' >> '*+'))
|
100
|
+
Differ.separator = '*'
|
101
|
+
@diff.same('c')
|
102
|
+
expect(@diff).to eq(diff('a', ('*-' >> '*+'), '*c'))
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe 'when the last result was just a delete' do
|
107
|
+
before(:each) do
|
108
|
+
@diff = diff(-'z')
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'should append to the result list' do
|
112
|
+
@diff.same('a')
|
113
|
+
expect(@diff).to eq(diff(Differ::Change.new(:delete => 'z'), 'a'))
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'should append Differ.separator to the previous result' do
|
117
|
+
Differ.separator = '*'
|
118
|
+
@diff.same('a')
|
119
|
+
expect(@diff).to eq(diff(Differ::Change.new(:delete => 'z*'), 'a'))
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should relocate a leading Differ.separator on the delete to the previous item" do
|
123
|
+
@diff = diff('a', -'*b')
|
124
|
+
Differ.separator = '*'
|
125
|
+
@diff.same('c')
|
126
|
+
expect(@diff).to eq(diff('a*', -'b*', 'c'))
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe 'when the last result was just an insert' do
|
131
|
+
before(:each) do
|
132
|
+
@diff = diff(+'z')
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'should append to the result list' do
|
136
|
+
@diff.same('a')
|
137
|
+
expect(@diff).to eq(diff(+'z', 'a'))
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'should append Differ.separator to the previous result' do
|
141
|
+
Differ.separator = '*'
|
142
|
+
@diff.same('a')
|
143
|
+
expect(@diff).to eq(diff(+'z*', 'a'))
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should relocate a leading Differ.separator on the insert to the previous item" do
|
147
|
+
@diff = diff('a', +'*b')
|
148
|
+
Differ.separator = '*'
|
149
|
+
@diff.same('c')
|
150
|
+
expect(@diff).to eq(diff('a*', +'b*', 'c'))
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
describe '#delete' do
|
156
|
+
it 'should append to the result list' do
|
157
|
+
@diff.delete('c')
|
158
|
+
expect(@diff).to eq(diff(-'c'))
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'should concatenate its arguments' do
|
162
|
+
@diff.delete('a', 'b', 'c', 'd')
|
163
|
+
expect(@diff).to eq(diff(-'abcd'))
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'should join its arguments with Differ.separator' do
|
167
|
+
Differ.separator = '*'
|
168
|
+
@diff.delete(*'a*b*c*d'.split)
|
169
|
+
expect(@diff).to eq(diff(-'a*b*c*d'))
|
170
|
+
end
|
171
|
+
|
172
|
+
describe 'when the last result was a Change' do
|
173
|
+
describe '(delete)' do
|
174
|
+
before(:each) do
|
175
|
+
@diff = diff(-'a')
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'should append to the last result' do
|
179
|
+
@diff.delete('b')
|
180
|
+
expect(@diff).to eq(diff(-'ab'))
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'should join to the last result with Differ.separator' do
|
184
|
+
Differ.separator = '*'
|
185
|
+
@diff.delete('b')
|
186
|
+
expect(@diff).to eq(diff(-'a*b'))
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe '(insert)' do
|
191
|
+
before(:each) do
|
192
|
+
@diff = diff(+'a')
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should turn the insert into a change" do
|
196
|
+
@diff.delete('b')
|
197
|
+
expect(@diff).to eq(diff('b' >> 'a'))
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should relocate a leading Differ.separator on the insert to the previous item" do
|
201
|
+
@diff = diff('a', +'*b')
|
202
|
+
Differ.separator = '*'
|
203
|
+
@diff.delete('z')
|
204
|
+
expect(@diff).to eq(diff('a*', ('z' >> 'b')))
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
describe 'when the last result was not a Change' do
|
210
|
+
before(:each) do
|
211
|
+
@diff = diff('a')
|
212
|
+
end
|
213
|
+
|
214
|
+
it 'should append a Change to the result list' do
|
215
|
+
@diff.delete('b')
|
216
|
+
expect(@diff).to eq(diff('a', -'b'))
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'should prepend Differ.separator to the result' do
|
220
|
+
Differ.separator = '*'
|
221
|
+
@diff.delete('b')
|
222
|
+
expect(@diff).to eq(diff('a', -'*b'))
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
describe '#insert' do
|
228
|
+
it 'should append to the result list' do
|
229
|
+
@diff.insert('c')
|
230
|
+
expect(@diff).to eq(diff(+'c'))
|
231
|
+
end
|
232
|
+
|
233
|
+
it 'should concatenate its arguments' do
|
234
|
+
@diff.insert('a', 'b', 'c', 'd')
|
235
|
+
expect(@diff).to eq(diff(+'abcd'))
|
236
|
+
end
|
237
|
+
|
238
|
+
it 'should join its arguments with Differ.separator' do
|
239
|
+
Differ.separator = '*'
|
240
|
+
@diff.insert(*'a*b*c*d'.split)
|
241
|
+
expect(@diff).to eq(diff(+'a*b*c*d'))
|
242
|
+
end
|
243
|
+
|
244
|
+
describe 'when the last result was a Change' do
|
245
|
+
describe '(delete)' do
|
246
|
+
before(:each) do
|
247
|
+
@diff = diff(-'b')
|
248
|
+
end
|
249
|
+
|
250
|
+
it "should not change the 'insert' portion of the last result" do
|
251
|
+
@diff.insert('a')
|
252
|
+
expect(@diff).to eq(diff('b' >> 'a'))
|
253
|
+
end
|
254
|
+
|
255
|
+
it "should relocate a leading Differ.separator on the delete to the previous item" do
|
256
|
+
@diff = diff('a', -'*b')
|
257
|
+
Differ.separator = '*'
|
258
|
+
@diff.insert('z')
|
259
|
+
expect(@diff).to eq(diff('a*', ('b' >> 'z')))
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
describe '(insert)' do
|
264
|
+
before(:each) do
|
265
|
+
@diff = diff(+'a')
|
266
|
+
end
|
267
|
+
|
268
|
+
it 'should append to the last result' do
|
269
|
+
@diff.insert('b')
|
270
|
+
expect(@diff).to eq(diff(+'ab'))
|
271
|
+
end
|
272
|
+
|
273
|
+
it 'should join to the last result with Differ.separator' do
|
274
|
+
Differ.separator = '*'
|
275
|
+
@diff.insert('b')
|
276
|
+
expect(@diff).to eq(diff(+'a*b'))
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
describe 'when the last result was not a Change' do
|
282
|
+
before(:each) do
|
283
|
+
@diff = diff('a')
|
284
|
+
end
|
285
|
+
|
286
|
+
it 'should append a Change to the result list' do
|
287
|
+
@diff.insert('b')
|
288
|
+
expect(@diff).to eq(diff('a', +'b'))
|
289
|
+
end
|
290
|
+
|
291
|
+
it 'should prepend Differ.separator to the result' do
|
292
|
+
Differ.separator = '*'
|
293
|
+
@diff.insert('b')
|
294
|
+
expect(@diff).to eq(diff('a', +'*b'))
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Differ::Format::Ascii do
|
4
|
+
it 'should format inserts well' do
|
5
|
+
@expected = '{+"SAMPLE"}'
|
6
|
+
expect(Differ::Format::Ascii.call(+'SAMPLE')).to eq(@expected)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should format deletes well' do
|
10
|
+
@expected = '{-"SAMPLE"}'
|
11
|
+
expect(Differ::Format::Ascii.call(-'SAMPLE')).to eq(@expected)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should format changes well' do
|
15
|
+
@expected = '{"THEN" >> "NOW"}'
|
16
|
+
expect(Differ::Format::Ascii.call('THEN' >> 'NOW')).to eq(@expected)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Differ::Format::Color do
|
4
|
+
it 'should format inserts well' do
|
5
|
+
@expected = "\033[32mSAMPLE\033[0m"
|
6
|
+
expect(Differ::Format::Color.call(Differ::Change.new(:insert => 'SAMPLE'))).to eq(@expected)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should format deletes well' do
|
10
|
+
@expected = "\033[31mSAMPLE\033[0m"
|
11
|
+
expect(Differ::Format::Color.call(Differ::Change.new(:delete => 'SAMPLE'))).to eq(@expected)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should format changes well' do
|
15
|
+
@expected = "\033[31mTHEN\033[0m\033[32mNOW\033[0m"
|
16
|
+
expect(Differ::Format::Color.call(Differ::Change.new(:delete => 'THEN', :insert => 'NOW'))).to eq(@expected)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Differ::Format::HTML do
|
4
|
+
it 'should format inserts well' do
|
5
|
+
@expected = '<ins class="differ">SAMPLE</ins>'
|
6
|
+
expect(Differ::Format::HTML.call(Differ::Change.new(:insert => 'SAMPLE'))).to eq(@expected)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should format deletes well' do
|
10
|
+
@expected = '<del class="differ">SAMPLE</del>'
|
11
|
+
expect(Differ::Format::HTML.call(Differ::Change.new(:delete => 'SAMPLE'))).to eq(@expected)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should format changes well' do
|
15
|
+
@expected = '<del class="differ">THEN</del><ins class="differ">NOW</ins>'
|
16
|
+
expect(Differ::Format::HTML.call(Differ::Change.new(:delete => 'THEN', :insert => 'NOW'))).to eq(@expected)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Differ::Format::Patch do
|
4
|
+
it 'should format inserts well' do
|
5
|
+
@expected = "\033[32m+ SAMPLE\033[0m"
|
6
|
+
expect(Differ::Format::Patch.format(+'SAMPLE')).to eq(@expected)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should format deletes well' do
|
10
|
+
@expected = "\033[31m- SAMPLE\033[0m"
|
11
|
+
expect(Differ::Format::Patch.format(-'SAMPLE')).to eq(@expected)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should format changes well' do
|
15
|
+
@expected = "\033[31m- THEN\033[0m\n\033[32m+ NOW\033[0m"
|
16
|
+
expect(Differ::Format::Patch.format('THEN' >> 'NOW')).to eq(@expected)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'differ/string'
|
3
|
+
|
4
|
+
describe Differ::StringDiffer do
|
5
|
+
it 'should be automatically mixed into String' do
|
6
|
+
expect(String.included_modules).to include(Differ::StringDiffer)
|
7
|
+
end
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
Differ.separator = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#diff' do
|
14
|
+
it 'should call Differ#diff' do
|
15
|
+
expect(Differ).to receive(:diff).with('TO', 'FROM', "\n").once
|
16
|
+
'TO'.diff('FROM')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should call Differ#diff with Differ.separator' do
|
20
|
+
Differ.separator = 'x'
|
21
|
+
expect(Differ).to receive(:diff).with('TO', 'FROM', Differ.separator).once
|
22
|
+
'TO'.diff('FROM')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#-' do
|
27
|
+
it 'should call Differ#diff' do
|
28
|
+
expect(Differ).to receive(:diff).with('TO', 'FROM', "\n").once
|
29
|
+
'TO' - 'FROM'
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should call Differ#diff with Differ.separator' do
|
33
|
+
Differ.separator = 'x'
|
34
|
+
expect(Differ).to receive(:diff).with('TO', 'FROM', Differ.separator).once
|
35
|
+
'TO' - 'FROM'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#diff_by_char' do
|
40
|
+
it 'should call Differ#diff' do
|
41
|
+
expect(Differ).to receive(:diff).with('Othellos', 'hello', '').once
|
42
|
+
'Othellos'.diff_by_char('hello')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#diff_by_word' do
|
47
|
+
it 'should call Differ#diff' do
|
48
|
+
expect(Differ).to receive(:diff).with('Othellos', 'hello', /\b/).once
|
49
|
+
'Othellos'.diff_by_word('hello')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#diff_by_line' do
|
54
|
+
it 'should call Differ#diff' do
|
55
|
+
expect(Differ).to receive(:diff).with('Othellos', 'hello', "\n").once
|
56
|
+
'Othellos'.diff_by_line('hello')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|