Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
08f78973
Commit
08f78973
authored
Mar 12, 2019
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement suggestion diff lines parser
parent
30e52b23
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
0 deletions
+92
-0
lib/gitlab/diff/suggestion_diff.rb
lib/gitlab/diff/suggestion_diff.rb
+37
-0
spec/lib/gitlab/diff/suggestion_diff_spec.rb
spec/lib/gitlab/diff/suggestion_diff_spec.rb
+55
-0
No files found.
lib/gitlab/diff/suggestion_diff.rb
0 → 100644
View file @
08f78973
# frozen_string_literal: true
module
Gitlab
module
Diff
class
SuggestionDiff
include
Gitlab
::
Utils
::
StrongMemoize
delegate
:from_content
,
:to_content
,
:from_line
,
to: :@suggestible
def
initialize
(
suggestible
)
@suggestible
=
suggestible
end
def
diff_lines
Gitlab
::
Diff
::
Parser
.
new
.
parse
(
raw_diff
.
each_line
).
to_a
end
private
def
raw_diff
"
#{
diff_header
}
\n
#{
from_content_as_diff
}#{
to_content_as_diff
}
"
end
def
diff_header
"@@ -
#{
from_line
}
+
#{
from_line
}
"
end
def
from_content_as_diff
from_content
.
lines
.
map
{
|
line
|
line
.
prepend
(
'-'
)
}.
join
end
def
to_content_as_diff
to_content
.
lines
.
map
{
|
line
|
line
.
prepend
(
'+'
)
}.
join
end
end
end
end
spec/lib/gitlab/diff/suggestion_diff_spec.rb
0 → 100644
View file @
08f78973
# frozen_string_literal: true
require
'spec_helper'
describe
Gitlab
::
Diff
::
SuggestionDiff
do
describe
'#diff_lines'
do
let
(
:from_content
)
do
<<-
BLOB
.
strip_heredoc
"tags": ["devel", "development", "nightly"],
"desktop-file-name-prefix": "(Development) ",
"finish-args": "foo",
BLOB
end
let
(
:to_content
)
do
<<-
BLOB
.
strip_heredoc
"buildsystem": "meson",
"builddir": true,
"name": "nautilus",
"bar": "bar",
BLOB
end
let
(
:suggestion
)
do
instance_double
(
Suggestion
,
from_line:
12
,
from_content:
from_content
,
to_content:
to_content
)
end
subject
{
described_class
.
new
(
suggestion
).
diff_lines
}
let
(
:expected_diff_lines
)
do
[
{
old_pos:
12
,
new_pos:
12
,
type:
"match"
,
text:
"@@ -12 +12"
},
{
old_pos:
12
,
new_pos:
12
,
type:
"old"
,
text:
"-
\"
tags
\"
: [
\"
devel
\"
,
\"
development
\"
,
\"
nightly
\"
],"
},
{
old_pos:
13
,
new_pos:
12
,
type:
"old"
,
text:
"-
\"
desktop-file-name-prefix
\"
:
\"
(Development)
\"
,"
},
{
old_pos:
14
,
new_pos:
12
,
type:
"old"
,
text:
"-
\"
finish-args
\"
:
\"
foo
\"
,"
},
{
old_pos:
15
,
new_pos:
12
,
type:
"new"
,
text:
"+
\"
buildsystem
\"
:
\"
meson
\"
,"
},
{
old_pos:
15
,
new_pos:
13
,
type:
"new"
,
text:
"+
\"
builddir
\"
: true,"
},
{
old_pos:
15
,
new_pos:
14
,
type:
"new"
,
text:
"+
\"
name
\"
:
\"
nautilus
\"
,"
},
{
old_pos:
15
,
new_pos:
15
,
type:
"new"
,
text:
"+
\"
bar
\"
:
\"
bar
\"
,"
}
]
end
it
'returns diff lines with correct line numbers'
do
diff_lines
=
subject
expect
(
diff_lines
).
to
all
(
be_a
(
Gitlab
::
Diff
::
Line
))
expected_diff_lines
.
each_with_index
do
|
expected_line
,
index
|
expect
(
diff_lines
[
index
].
to_hash
).
to
include
(
expected_line
)
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment