-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Check whether the label is for an issue or a pull request. 2. Don't use space to layout 3. Make sure the test strings have trailing spaces explicitly, to avoid some IDE removing the trailing spaces automatically.
- Loading branch information
1 parent
92e27e1
commit 18dd9f9
Showing
3 changed files
with
38 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,17 +7,21 @@ import ( | |
"context" | ||
"html/template" | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
"code.gitea.io/gitea/models/issues" | ||
"code.gitea.io/gitea/models/unittest" | ||
"code.gitea.io/gitea/modules/git" | ||
"code.gitea.io/gitea/modules/log" | ||
"code.gitea.io/gitea/modules/markup" | ||
"code.gitea.io/gitea/modules/translation" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
const testInput = ` space @mention-user | ||
func testInput() string { | ||
s := ` space @mention-user<SPACE><SPACE> | ||
/just/a/path.bin | ||
https://example.com/file.bin | ||
[local link](file.bin) | ||
|
@@ -36,8 +40,10 @@ com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb mit | |
[email protected] | ||
@mention-user test | ||
#123 | ||
space | ||
space<SPACE><SPACE> | ||
` | ||
return strings.ReplaceAll(s, "<SPACE>", " ") | ||
} | ||
|
||
var testMetas = map[string]string{ | ||
"user": "user13", | ||
|
@@ -121,23 +127,23 @@ com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb mit | |
<a href="/user13/repo11/issues/123" class="ref-issue">#123</a> | ||
space` | ||
|
||
assert.EqualValues(t, expected, RenderCommitBody(context.Background(), testInput, testMetas)) | ||
assert.EqualValues(t, expected, RenderCommitBody(context.Background(), testInput(), testMetas)) | ||
} | ||
|
||
func TestRenderCommitMessage(t *testing.T) { | ||
expected := `space <a href="/mention-user" class="mention">@mention-user</a> ` | ||
|
||
assert.EqualValues(t, expected, RenderCommitMessage(context.Background(), testInput, testMetas)) | ||
assert.EqualValues(t, expected, RenderCommitMessage(context.Background(), testInput(), testMetas)) | ||
} | ||
|
||
func TestRenderCommitMessageLinkSubject(t *testing.T) { | ||
expected := `<a href="https://example.com/link" class="default-link muted">space </a><a href="/mention-user" class="mention">@mention-user</a>` | ||
|
||
assert.EqualValues(t, expected, RenderCommitMessageLinkSubject(context.Background(), testInput, "https://example.com/link", testMetas)) | ||
assert.EqualValues(t, expected, RenderCommitMessageLinkSubject(context.Background(), testInput(), "https://example.com/link", testMetas)) | ||
} | ||
|
||
func TestRenderIssueTitle(t *testing.T) { | ||
expected := ` space @mention-user | ||
expected := ` space @mention-user<SPACE><SPACE> | ||
/just/a/path.bin | ||
https://example.com/file.bin | ||
[local link](file.bin) | ||
|
@@ -156,9 +162,10 @@ com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb mit | |
[email protected] | ||
@mention-user test | ||
<a href="/user13/repo11/issues/123" class="ref-issue">#123</a> | ||
space | ||
space<SPACE><SPACE> | ||
` | ||
assert.EqualValues(t, expected, RenderIssueTitle(context.Background(), testInput, testMetas)) | ||
expected = strings.ReplaceAll(expected, "<SPACE>", " ") | ||
assert.EqualValues(t, expected, RenderIssueTitle(context.Background(), testInput(), testMetas)) | ||
} | ||
|
||
func TestRenderMarkdownToHtml(t *testing.T) { | ||
|
@@ -183,5 +190,20 @@ com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb mit | |
#123 | ||
space</p> | ||
` | ||
assert.EqualValues(t, expected, RenderMarkdownToHtml(context.Background(), testInput)) | ||
assert.EqualValues(t, expected, RenderMarkdownToHtml(context.Background(), testInput())) | ||
} | ||
|
||
func TestRenderLabels(t *testing.T) { | ||
ctx := context.Background() | ||
locale := &translation.MockLocale{} | ||
|
||
label := &issues.Label{ID: 123, Name: "label-name", Color: "label-color"} | ||
issue := &issues.Issue{} | ||
expected := `/owner/repo/issues?labels=123` | ||
assert.Contains(t, RenderLabels(ctx, locale, []*issues.Label{label}, "/owner/repo", issue), expected) | ||
|
||
label = &issues.Label{ID: 123, Name: "label-name", Color: "label-color"} | ||
issue = &issues.Issue{IsPull: true} | ||
expected = `/owner/repo/pulls?labels=123` | ||
assert.Contains(t, RenderLabels(ctx, locale, []*issues.Label{label}, "/owner/repo", issue), expected) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters