blob: 2ffd5f50d3ba901ccb5132e2133ebc6b2f5b5f6d (
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::GithubImport::Representation::DiffNotes::SuggestionFormatter do
it 'does nothing when there is any text before the suggestion tag' do
note = <<~BODY
looks like```suggestion but it isn't
```
BODY
expect(described_class.formatted_note_for(note: note)).to eq(note)
end
it 'handles nil value for note' do
note = nil
expect(described_class.formatted_note_for(note: note)).to eq(note)
end
it 'does not allow over 3 leading spaces for valid suggestion' do
note = <<~BODY
Single-line suggestion
```suggestion
sug1
```
BODY
expect(described_class.formatted_note_for(note: note)).to eq(note)
end
it 'allows up to 3 leading spaces' do
note = <<~BODY
Single-line suggestion
```suggestion
sug1
```
BODY
expected = <<~BODY
Single-line suggestion
```suggestion:-0+0
sug1
```
BODY
expect(described_class.formatted_note_for(note: note)).to eq(expected)
end
it 'does nothing when there is any text without space after the suggestion tag' do
note = <<~BODY
```suggestionbut it isn't
```
BODY
expect(described_class.formatted_note_for(note: note)).to eq(note)
end
it 'formats single-line suggestions' do
note = <<~BODY
Single-line suggestion
```suggestion
sug1
```
BODY
expected = <<~BODY
Single-line suggestion
```suggestion:-0+0
sug1
```
BODY
expect(described_class.formatted_note_for(note: note)).to eq(expected)
end
it 'ignores text after suggestion tag on the same line' do
note = <<~BODY
looks like
```suggestion text to be ignored
suggestion
```
BODY
expected = <<~BODY
looks like
```suggestion:-0+0
suggestion
```
BODY
expect(described_class.formatted_note_for(note: note)).to eq(expected)
end
it 'formats multiple single-line suggestions' do
note = <<~BODY
Single-line suggestion
```suggestion
sug1
```
OR
```suggestion
sug2
```
BODY
expected = <<~BODY
Single-line suggestion
```suggestion:-0+0
sug1
```
OR
```suggestion:-0+0
sug2
```
BODY
expect(described_class.formatted_note_for(note: note)).to eq(expected)
end
it 'formats multi-line suggestions' do
note = <<~BODY
Multi-line suggestion
```suggestion
sug1
```
BODY
expected = <<~BODY
Multi-line suggestion
```suggestion:-2+0
sug1
```
BODY
expect(described_class.formatted_note_for(note: note, start_line: 6, end_line: 8)).to eq(expected)
end
it 'formats multiple multi-line suggestions' do
note = <<~BODY
Multi-line suggestion
```suggestion
sug1
```
OR
```suggestion
sug2
```
BODY
expected = <<~BODY
Multi-line suggestion
```suggestion:-2+0
sug1
```
OR
```suggestion:-2+0
sug2
```
BODY
expect(described_class.formatted_note_for(note: note, start_line: 6, end_line: 8)).to eq(expected)
end
end
|