Skip to content

Commit bbd4799

Browse files
committed
fine tune tests
1 parent 6408c43 commit bbd4799

File tree

3 files changed

+9
-31
lines changed

3 files changed

+9
-31
lines changed

routers/web/repo/compare.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ func PrepareCompareDiff(
641641
ctx.Data["DiffShortStat"] = diffShortStat
642642
ctx.Data["Diff"] = diff
643643
ctx.Data["DiffBlobExcerptData"] = &gitdiff.DiffBlobExcerptData{
644-
BaseLink: ctx.Repo.RepoLink + "/blob_excerpt",
644+
BaseLink: ci.HeadRepo.Link() + "/blob_excerpt",
645645
DiffStyle: ctx.FormString("style"),
646646
AfterCommitID: headCommitID,
647647
}

services/gitdiff/gitdiff.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ func FillHiddenCommentIDsForDiffLine(line *DiffLine, lineComments map[int64][]*i
224224
var hiddenCommentIDs []int64
225225
for commentLineNum, comments := range lineComments {
226226
absLineNum := int(commentLineNum)
227-
if commentLineNum < 0 {
228-
absLineNum = int(-commentLineNum)
227+
if absLineNum < 0 {
228+
absLineNum = -absLineNum
229229
}
230230
// Check if comments are in the hidden range
231231
if absLineNum > line.SectionInfo.LastRightIdx && absLineNum <= line.SectionInfo.RightIdx {

services/gitdiff/gitdiff_test.go

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -721,17 +721,17 @@ func TestGeneratePatchForUnchangedLineFromReader(t *testing.T) {
721721
},
722722
{
723723
name: "multi-line context",
724-
content: "package main\n\nfunc main() {\n\tfmt.Println(\"Hello\")\n}\n",
724+
content: "package main\n\nfunc main() {\n fmt.Println(\"Hello\")\n}\n",
725725
treePath: "main.go",
726726
line: 4,
727727
contextLines: 2,
728728
want: `diff --git a/main.go b/main.go
729729
--- a/main.go
730730
+++ b/main.go
731731
@@ -2,3 +2,3 @@
732-
732+
<SP>
733733
func main() {
734-
fmt.Println("Hello")
734+
fmt.Println("Hello")
735735
`,
736736
},
737737
{
@@ -752,7 +752,7 @@ func TestGeneratePatchForUnchangedLineFromReader(t *testing.T) {
752752
assert.Error(t, err)
753753
} else {
754754
require.NoError(t, err)
755-
assert.Equal(t, tt.want, got)
755+
assert.Equal(t, strings.ReplaceAll(tt.want, "<SP>", " "), got)
756756
}
757757
})
758758
}
@@ -820,38 +820,16 @@ func TestCalculateHiddenCommentIDsForLine(t *testing.T) {
820820
},
821821
lineComments: map[int64][]*issues_model.Comment{
822822
10: {{ID: 100}}, // at LastRightIdx, should not be included
823-
20: {{ID: 101}}, // at RightIdx, should not be included
823+
20: {{ID: 101}}, // at RightIdx, should be included
824824
11: {{ID: 102}}, // just inside range, should be included
825825
19: {{ID: 103}}, // just inside range, should be included
826826
},
827-
expected: []int64{102, 103},
828-
},
829-
{
830-
name: "not a section line",
831-
line: &DiffLine{
832-
Type: DiffLinePlain,
833-
},
834-
lineComments: map[int64][]*issues_model.Comment{
835-
15: {{ID: 100}},
836-
},
837-
expected: nil,
838-
},
839-
{
840-
name: "section line without section info",
841-
line: &DiffLine{
842-
Type: DiffLineSection,
843-
SectionInfo: nil,
844-
},
845-
lineComments: map[int64][]*issues_model.Comment{
846-
15: {{ID: 100}},
847-
},
848-
expected: nil,
827+
expected: []int64{101, 102, 103},
849828
},
850829
}
851830

852831
for _, tt := range tests {
853832
t.Run(tt.name, func(t *testing.T) {
854-
tt.line.SectionInfo = &DiffLineSectionInfo{}
855833
FillHiddenCommentIDsForDiffLine(tt.line, tt.lineComments)
856834
assert.ElementsMatch(t, tt.expected, tt.line.SectionInfo.HiddenCommentIDs)
857835
})

0 commit comments

Comments
 (0)