This commit is contained in:
guange 2016-11-26 17:49:36 +08:00
parent a2439f0a14
commit efb0c9917c
1 changed files with 5 additions and 5 deletions

View File

@ -3,8 +3,11 @@ require 'rails_helper'
require 'ostruct'
describe "Git diff" do
before(:each) do
# 参照此diff的输出 http://ucloudgit.trustie.net/Hjqreturn/pullrequesttest111/commit/f36f15bc1d3e256a4fa5115d82201af72301884e
@content = '''
[{"diff":"--- a/readme\n+++ b/readme\n@@ -1,7 +1,8 @@\n 邀请界面\n 1.1 界面设计 (已处理)\n- 1.2 改写成html功能 (已处理)\n+sdkfsjkdf\n 1.3 集成到游戏邀请功能 (已处理)\n+adfjsdajlfk\n \n 微信登录功能\n 2.1 集成sdk (已处理)\n","new_path":"readme","old_path":"readme","a_mode":"100644","b_mode":"100644","new_file":false,"renamed_file":false,"deleted_file":false}]
'''
@ -33,18 +36,15 @@ describe "Git diff" do
diff_file.diff_lines.each_with_index do |line, index|
type = line.type
last_line = line.new_pos
line_code = Trustie::Gitlab::Diff::LineCode.generate('diff.file_path', line.new_pos, line.old_pos)
line_old = line.old_pos.to_s
#puts "type: #{type} last_line: #{last_line} last_code: #{line_code} line_old: #{line_old} text: #{line.text}"
if type == 'match'
## 表示没有修改,两个都要显示行号
output += "|#{line_old.center(4)}|#{line.new_pos.to_s.center(4)}|#{line.text}\n"
output += "|#{line_old.center(4)}|#{last_line.to_s.center(4)}|#{line.text}\n"
else
old_line = type == 'new' ? ' '*4: line_old
new_line = type == 'old' ? ' '*4: line.new_pos
new_line = type == 'old' ? ' '*4: last_line
output += "|#{old_line.to_s.center(4)}|#{new_line.to_s.center(4)}|#{line.text}\n"
end
end