summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/inline_diff_spec.rb
blob: 2e0a05088ccb052f9a49286fbd04f97035db0a1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require 'spec_helper'

describe Gitlab::InlineDiff do
  describe '#processing' do
    let(:diff) do
      <<eos
--- a/test.rb
+++ b/test.rb
@@ -1,6 +1,6 @@
 class Test
   def cleanup_string(input)
     return nil if input.nil?
-    input.sub(/[\\r\\n].+/,'').sub(/\\\\[rn].+/, '').strip
+    input.to_s.sub(/[\\r\\n].+/,'').sub(/\\\\[rn].+/, '').strip
   end
 end
eos
    end

    let(:expected) do
      ["--- a/test.rb\n",
       "+++ b/test.rb\n",
       "@@ -1,6 +1,6 @@\n",
       " class Test\n",
       "   def cleanup_string(input)\n",
       "     return nil if input.nil?\n",
       "-    input.#!idiff-start!##!idiff-finish!#sub(/[\\r\\n].+/,'').sub(/\\\\[rn].+/, '').strip\n",
       "+    input.#!idiff-start!#to_s.#!idiff-finish!#sub(/[\\r\\n].+/,'').sub(/\\\\[rn].+/, '').strip\n",
       "   end\n",
       " end\n"]
    end

    let(:subject) { Gitlab::InlineDiff.processing(diff.lines) }

    it 'should retain backslashes' do
      expect(subject).to eq(expected)
    end
  end
end