riffdiff 1.0.20 → 1.0.32

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee5b9e6b9b78557a80e5b991f48673b90eeda880
4
- data.tar.gz: 6a27e2bc22a0d7e47d9b414c1c9c1dbd7e2f0c62
3
+ metadata.gz: a903c564f968253a85a9e511353e4bea5cdb53e2
4
+ data.tar.gz: f6348bd244e212c8c63239f7534c16eb8854e453
5
5
  SHA512:
6
- metadata.gz: b340f654f8ad84c341fb462da5dcbada725f4b64dadbce12cf38ee916d8a410df8ebe02b91db1d52e30ef0aad0e7c1a652721408d9b028f164a22398310870c4
7
- data.tar.gz: e57adfa78061e38b062909dd49d976debe48fa2b0b286652113ba5c92db2a797711d5df8dce0187eecd9cef6def40e1711718271c8aac1c324173bd4c8d972ae
6
+ metadata.gz: 073ae0437959a08a2c62fa0e44ec1f49f828b06ee9b900648bf6b030ce6fe2c33fc6a3c46dc666a85be829a9a7e530a550082be5809bae1fe0d4d895dd25aa14
7
+ data.tar.gz: 4e35509f4eefd273ae0dc218798cc8f22bfe1bd6dd8eba4369b9bce8135f09c531e8aba18b212c70dfbd45e7e7aedd7b5933479e25c1f5526a98997a30374192
data/.rubocop.yml CHANGED
@@ -40,3 +40,8 @@ Metrics/AbcSize:
40
40
  # Johan looked at some methods and concluded 7 is fine
41
41
  Metrics/CyclomaticComplexity:
42
42
  Max: 7
43
+
44
+ # Offense count: 1
45
+ # Configuration parameters: CountKeywordArgs.
46
+ Metrics/ParameterLists:
47
+ CountKeywordArgs: false
data/README.md CHANGED
@@ -24,6 +24,10 @@ Optionally followed by...
24
24
 
25
25
  # TODO
26
26
  * Think about highlighting whitespace errors like Git does
27
+ * OK: Make DiffString.add() take a color as well
28
+ * Add a whitespace analysis pass to the Refiner
29
+ * Let the Refiner highlight whitespace errors among the added lines in reverse
30
+ red.
27
31
  * Think about how to visualize an added line break together with some
28
32
  indentation on the following line.
29
33
  * Do "git show 57f27da" and think about what rule we should use to get
@@ -122,3 +126,5 @@ globally on the system.
122
126
  still show the comma in reverse video though. Do this when:
123
127
  * One line is replaced by many
124
128
  * The diff contains only additions
129
+ * When special highighting an expansion, highlight the added parts in green
130
+ reverse, rather than black reverse. Testcase: `git show 7ea6877`
data/Rakefile CHANGED
@@ -33,5 +33,8 @@ end
33
33
 
34
34
  desc 'Publish to rubygems.org'
35
35
  task publish: [:package] do
36
+ branch = git_branch
37
+ fail "Cannot publish from #{branch}, must be on master" if branch != 'master'
38
+
36
39
  system('gem push *.gem') || fail
37
40
  end
data/lib/colors.rb CHANGED
@@ -6,6 +6,7 @@ module Colors
6
6
  CYAN = "#{ESC}[36m"
7
7
  GREEN = "#{ESC}[32m"
8
8
  RED = "#{ESC}[31m"
9
+ DEFAULT_COLOR = "#{ESC}[39m"
9
10
 
10
11
  REVERSE = "#{ESC}[7m"
11
12
  NOT_REVERSE = "#{ESC}[27m"
data/lib/diff_string.rb CHANGED
@@ -9,22 +9,31 @@ class DiffString
9
9
 
10
10
  # Note that the color argument can be the empty string
11
11
  def initialize(prefix, color)
12
- @reverse = false
13
12
  @prefix = prefix
14
- @color = color
13
+ @base_color = color
14
+
15
15
  @string = ''
16
+
17
+ @reverse = false
18
+ @color = @base_color
19
+ @reset_color = color.empty? ? DEFAULT_COLOR : color
16
20
  end
17
21
 
18
- def add(string, reverse)
22
+ # rubocop:disable Metrics/CyclomaticComplexity
23
+ # rubocop:disable Metrics/PerceivedComplexity
24
+ def add(string, reverse, color = '')
25
+ color = @reset_color if color.empty?
26
+
19
27
  if reverse && string == "\n"
20
- add('↵', true)
28
+ add('↵', true, color)
21
29
  add("\n", false)
22
30
  return
23
31
  end
24
32
 
25
33
  if @string.empty?() || @string.end_with?("\n")
26
- @string += @color
34
+ @string += @base_color
27
35
  @string += @prefix
36
+ @color = @reset_color
28
37
  end
29
38
 
30
39
  if reverse != @reverse
@@ -32,6 +41,11 @@ class DiffString
32
41
  end
33
42
  @reverse = reverse
34
43
 
44
+ if color != @color
45
+ @string += color
46
+ end
47
+ @color = color
48
+
35
49
  @string += string
36
50
  end
37
51
 
@@ -41,7 +55,7 @@ class DiffString
41
55
  string = @string
42
56
  string.chomp! if string.end_with? "\n"
43
57
 
44
- suffix = @color.empty? ? '' : RESET
58
+ suffix = @base_color.empty? ? '' : RESET
45
59
  return string + suffix + "\n"
46
60
  end
47
61
 
data/lib/refiner.rb CHANGED
@@ -95,10 +95,12 @@ class Refiner
95
95
  return try_highlight(old, new)
96
96
  end
97
97
 
98
- def render_refinement(prefix, color, string, highlights, base_index = 0)
98
+ def render_refinement(prefix, color, string, highlights,
99
+ base_index: 0, highlight_color: '')
99
100
  return_me = DiffString.new(prefix, color)
100
101
  string.each_char.with_index do |char, index|
101
- return_me.add(char, highlights.include?(index + base_index))
102
+ highlight = highlights.include?(index + base_index)
103
+ return_me.add(char, highlight, highlight ? highlight_color : '')
102
104
  end
103
105
  return return_me.to_s
104
106
  end
@@ -132,13 +134,15 @@ class Refiner
132
134
 
133
135
  @refined_old = ''
134
136
 
135
- refined_line_1 = render_refinement(' ', '', lines[0], new_highlights)
137
+ refined_line_1 =
138
+ render_refinement(' ', '', lines[0], new_highlights,
139
+ highlight_color: GREEN)
136
140
 
137
141
  line_2_index_0 = lines[0].length
138
142
  refined_remaining_lines = render_refinement('+', GREEN,
139
143
  lines[1..-1].join,
140
144
  new_highlights,
141
- line_2_index_0)
145
+ base_index: line_2_index_0)
142
146
 
143
147
  @refined_new = refined_line_1 + refined_remaining_lines
144
148
 
data/lib/version.rb CHANGED
@@ -45,4 +45,13 @@ module Version
45
45
  def dirty?
46
46
  return git_version(true).include?('-dirty')
47
47
  end
48
+
49
+ def git_branch
50
+ git_result = `cd #{__dir__} ; git rev-parse --abbrev-ref HEAD 2> /dev/null`
51
+ if $CHILD_STATUS.success?
52
+ return git_result.chomp
53
+ else
54
+ return nil
55
+ end
56
+ end
48
57
  end
@@ -29,6 +29,113 @@ RSpec.describe DiffString, '#add' do
29
29
  end
30
30
  end
31
31
 
32
+ context 'single char special color, on green' do
33
+ diff_string = DiffString.new('+', GREEN)
34
+ diff_string.add('1', false)
35
+ diff_string.add('2', true, RED)
36
+ diff_string.add('3', false)
37
+ diff_string.add("\n", false)
38
+
39
+ it 'renders correctly' do
40
+ expect(diff_string.to_s).to eq(
41
+ "#{GREEN}+1#{reversed("#{RED}2")}#{GREEN}3#{RESET}\n")
42
+ end
43
+ end
44
+
45
+ context 'double char special color, on green' do
46
+ diff_string = DiffString.new('+', GREEN)
47
+ diff_string.add('1', false)
48
+ diff_string.add('2', true, RED)
49
+ diff_string.add('x', true, RED)
50
+ diff_string.add('3', false)
51
+ diff_string.add("\n", false)
52
+
53
+ it 'renders correctly' do
54
+ expect(diff_string.to_s).to eq(
55
+ "#{GREEN}+1#{reversed("#{RED}2x")}#{GREEN}3#{RESET}\n")
56
+ end
57
+ end
58
+
59
+ context 'special color at start, on green' do
60
+ diff_string = DiffString.new('+', GREEN)
61
+ diff_string.add('1', true, RED)
62
+ diff_string.add('2', false)
63
+ diff_string.add('3', false)
64
+ diff_string.add("\n", false)
65
+
66
+ it 'renders correctly' do
67
+ expect(diff_string.to_s).to eq(
68
+ "#{GREEN}+#{reversed("#{RED}1")}#{GREEN}23#{RESET}\n")
69
+ end
70
+ end
71
+
72
+ context 'special color at end, on green' do
73
+ diff_string = DiffString.new('+', GREEN)
74
+ diff_string.add('1', false)
75
+ diff_string.add('2', false)
76
+ diff_string.add('3', true, RED)
77
+ diff_string.add("\n", false)
78
+
79
+ it 'renders correctly' do
80
+ expect(diff_string.to_s).to eq(
81
+ "#{GREEN}+12#{reversed("#{RED}3")}#{GREEN}#{RESET}\n")
82
+ end
83
+ end
84
+
85
+ context 'special color before reverse, on green' do
86
+ diff_string = DiffString.new('+', GREEN)
87
+ diff_string.add('1', false)
88
+ diff_string.add('2', true, RED)
89
+ diff_string.add('3', true)
90
+ diff_string.add("\n", false)
91
+
92
+ it 'renders correctly' do
93
+ expect(diff_string.to_s).to eq(
94
+ "#{GREEN}+1#{reversed("#{RED}2#{GREEN}3")}#{RESET}\n")
95
+ end
96
+ end
97
+
98
+ context 'special color after reverse, on green' do
99
+ diff_string = DiffString.new('+', GREEN)
100
+ diff_string.add('1', false)
101
+ diff_string.add('2', true)
102
+ diff_string.add('3', true, RED)
103
+ diff_string.add("\n", false)
104
+
105
+ it 'renders correctly' do
106
+ expect(diff_string.to_s).to eq(
107
+ "#{GREEN}+1#{reversed("2#{RED}3")}#{GREEN}#{RESET}\n")
108
+ end
109
+ end
110
+
111
+ context 'special color at end of first line, on green' do
112
+ diff_string = DiffString.new('+', GREEN)
113
+ diff_string.add('1', false)
114
+ diff_string.add('2', true, RED)
115
+ diff_string.add("\n", false)
116
+ diff_string.add('3', false)
117
+ diff_string.add("\n", false)
118
+
119
+ it 'renders correctly' do
120
+ expect(diff_string.to_s).to eq(
121
+ "#{GREEN}+1#{reversed("#{RED}2")}#{GREEN}\n#{GREEN}+3#{RESET}\n")
122
+ end
123
+ end
124
+
125
+ context 'special color before reversed newline, on green' do
126
+ diff_string = DiffString.new('+', GREEN)
127
+ diff_string.add('1', false)
128
+ diff_string.add('2', true, RED)
129
+ diff_string.add("\n", true)
130
+ diff_string.add('3', false)
131
+ diff_string.add("\n", false)
132
+
133
+ it 'renders correctly' do
134
+ expect(diff_string.to_s).to eq(
135
+ "#{GREEN}+1#{reversed("#{RED}2#{GREEN}↵")}\n#{GREEN}+3#{RESET}\n")
136
+ end
137
+ end
138
+
32
139
  context 'multiline' do
33
140
  it 'colors both lines' do
34
141
  diff_string = DiffString.new('+', GREEN)
data/spec/refiner_spec.rb CHANGED
@@ -108,7 +108,7 @@ RSpec.describe Refiner, '#new' do
108
108
  it %(pretends first line is unchanged, but highlights comma) do
109
109
  expect(refiner.refined_old).to eq('')
110
110
  expect(refiner.refined_new).to eq(
111
- %( abcde#{reversed(',')}\n) +
111
+ %( abcde#{reversed("#{GREEN},")}#{DEFAULT_COLOR}\n) +
112
112
  %(#{GREEN}+fffff,\n) +
113
113
  %(#{GREEN}+ggggg#{RESET}\n))
114
114
  end
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.20
4
+ version: 1.0.32
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-13 00:00:00.000000000 Z
11
+ date: 2015-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec