diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-11-28 17:05:57 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-28 17:05:57 +0800 |
commit | ef9a0370ca71694c38cd8c30a3837ee3125974ba (patch) | |
tree | f61133a81538253a4dfabeaf88e1069f74b5b902 /services/gitdiff/gitdiff_test.go | |
parent | 6e578dd0c9db5284b470503376d97757c743b4c1 (diff) | |
download | gitea-ef9a0370ca71694c38cd8c30a3837ee3125974ba.tar.gz gitea-ef9a0370ca71694c38cd8c30a3837ee3125974ba.zip |
Fix panic when diff (#9187)
* fix panic when diff
* improve code
Diffstat (limited to 'services/gitdiff/gitdiff_test.go')
-rw-r--r-- | services/gitdiff/gitdiff_test.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/services/gitdiff/gitdiff_test.go b/services/gitdiff/gitdiff_test.go index acf3c6d7bd..ea25b38dff 100644 --- a/services/gitdiff/gitdiff_test.go +++ b/services/gitdiff/gitdiff_test.go @@ -6,11 +6,13 @@ package gitdiff import ( + "fmt" "html/template" "strings" "testing" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/setting" dmp "github.com/sergi/go-diff/diffmatchpatch" @@ -195,3 +197,15 @@ func TestDiffLine_GetCommentSide(t *testing.T) { assert.Equal(t, "previous", (&DiffLine{Comments: []*models.Comment{{Line: -3}}}).GetCommentSide()) assert.Equal(t, "proposed", (&DiffLine{Comments: []*models.Comment{{Line: 3}}}).GetCommentSide()) } + +func TestGetDiffRangeWithWhitespaceBehavior(t *testing.T) { + git.Debug = true + for _, behavior := range []string{"-w", "--ignore-space-at-eol", "-b", ""} { + diffs, err := GetDiffRangeWithWhitespaceBehavior("./testdata/academic-module", "559c156f8e0178b71cb44355428f24001b08fc68", "bd7063cc7c04689c4d082183d32a604ed27a24f9", + setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffFiles, behavior) + assert.NoError(t, err, fmt.Sprintf("Error when diff with %s", behavior)) + for _, f := range diffs.Files { + assert.True(t, len(f.Sections) > 0, fmt.Sprintf("%s should have sections", f.Name)) + } + } +} |