riffdiff 1.0.19 → 1.0.20

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/refiner.rb +13 -9
  3. data/spec/refiner_spec.rb +17 -0
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab9270780987e9731750adac81951e66b7e0cf74
4
- data.tar.gz: ae9e29dd801bf4502dcb651581ce99573946410b
3
+ metadata.gz: ee5b9e6b9b78557a80e5b991f48673b90eeda880
4
+ data.tar.gz: 6a27e2bc22a0d7e47d9b414c1c9c1dbd7e2f0c62
5
5
  SHA512:
6
- metadata.gz: eee0b5d29449d2fe3bb8201a6c8b68f8ee96b835518b8b18e6659b8657403387ae04dbe3ae767c1951dd42acaf68c2b31cb154e49e151a3700d77cb74690633b
7
- data.tar.gz: 827c93ab1f9ea4217083d43823815390fb01397280370571e14fbd6e0f7a97daae94c9b8fb2b6f52c376b714617906c739088d80662d8f6f0ed6455991caaaa4
6
+ metadata.gz: b340f654f8ad84c341fb462da5dcbada725f4b64dadbce12cf38ee916d8a410df8ebe02b91db1d52e30ef0aad0e7c1a652721408d9b028f164a22398310870c4
7
+ data.tar.gz: e57adfa78061e38b062909dd49d976debe48fa2b0b286652113ba5c92db2a797711d5df8dce0187eecd9cef6def40e1711718271c8aac1c324173bd4c8d972ae
data/lib/refiner.rb CHANGED
@@ -115,16 +115,20 @@ class Refiner
115
115
  #
116
116
  # Returns false if the preconditions for using this method aren't fulfilled
117
117
  def create_one_to_many_refinements(old, new, old_highlights, new_highlights)
118
- if old_highlights.count > 0
119
- return false
120
- end
121
- if old.lines.count != 1
122
- return false
123
- end
118
+ # If things have been removed from the first line, the specialized
119
+ # highlighting won't work
120
+ return false if old_highlights.count > 0
121
+
122
+ # If the first line was replaced rather than updated, the specialized
123
+ # highlighting won't work
124
+ return false if new_highlights.count == 0
125
+
126
+ # Specialized highlighting requires exactly one old line
127
+ return false if old.lines.count != 1
128
+
124
129
  lines = new.lines
125
- if lines.count < 2
126
- return false
127
- end
130
+ # Specialized highlighting requires two or more new lines
131
+ return false if lines.count < 2
128
132
 
129
133
  @refined_old = ''
130
134
 
data/spec/refiner_spec.rb CHANGED
@@ -148,6 +148,23 @@ RSpec.describe Refiner, '#new' do
148
148
  end
149
149
  end
150
150
 
151
+ # From https://github.com/walles/riff/issues/5
152
+ context %(with one line being replaced with many, real world case) do
153
+ refiner = Refiner.new("THROTTLE_SECONDS = 51\n",
154
+ "\n" \
155
+ "Monkey\n" \
156
+ "THROTTLE_SECONDS = None\n")
157
+
158
+ it %(just colors the lines) do
159
+ expect(refiner.refined_old).to eq(
160
+ %(#{RED}-THROTTLE_SECONDS = 51#{RESET}\n))
161
+ expect(refiner.refined_new).to eq(
162
+ %(#{GREEN}+\n) +
163
+ %(#{GREEN}+Monkey\n) +
164
+ %(#{GREEN}+THROTTLE_SECONDS = None#{RESET}\n))
165
+ end
166
+ end
167
+
151
168
  context %(with many lines turning into one) do
152
169
  refiner = Refiner.new("abcde,\n" \
153
170
  "fffff,\n" \
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riffdiff
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.19
4
+ version: 1.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johan Walles
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-09 00:00:00.000000000 Z
11
+ date: 2015-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec