@@ -11,7 +11,9 @@ import (
1111 "testing"
1212
1313 "code.gitea.io/gitea/models/issues"
14+ "code.gitea.io/gitea/models/repo"
1415 "code.gitea.io/gitea/models/unittest"
16+ user_model "code.gitea.io/gitea/models/user"
1517 "code.gitea.io/gitea/modules/git"
1618 "code.gitea.io/gitea/modules/log"
1719 "code.gitea.io/gitea/modules/markup"
4850}
4951
5052var testMetas = map [string ]string {
51- "user" : "user13" ,
52- "repo" : "repo11" ,
5353 "repoPath" : "../../tests/gitea-repositories-meta/user13/repo11.git/" ,
5454 "markdownNewLineHardBreak" : "true" ,
5555 "markupAllowShortIssuePattern" : "true" ,
@@ -74,46 +74,52 @@ func newTestRenderUtils(t *testing.T) *RenderUtils {
7474 return NewRenderUtils (ctx )
7575}
7676
77- func TestRenderCommitBody (t * testing.T ) {
78- defer test .MockVariableValue (& markup .RenderBehaviorForTesting .DisableAdditionalAttributes , true )()
79- type args struct {
80- msg string
77+ func TestRenderRepoComment (t * testing.T ) {
78+ mockRepo := & repo.Repository {
79+ ID : 1 , OwnerName : "user13" , Name : "repo11" ,
80+ Owner : & user_model.User {ID : 13 , Name : "user13" },
81+ Units : []* repo.RepoUnit {},
8182 }
82- tests := []struct {
83- name string
84- args args
85- want template.HTML
86- }{
87- {
88- name : "multiple lines" ,
89- args : args {
90- msg : "first line\n second line" ,
83+ t .Run ("RenderCommitBody" , func (t * testing.T ) {
84+ defer test .MockVariableValue (& markup .RenderBehaviorForTesting .DisableAdditionalAttributes , true )()
85+ type args struct {
86+ msg string
87+ }
88+ tests := []struct {
89+ name string
90+ args args
91+ want template.HTML
92+ }{
93+ {
94+ name : "multiple lines" ,
95+ args : args {
96+ msg : "first line\n second line" ,
97+ },
98+ want : "second line" ,
9199 },
92- want : "second line" ,
93- } ,
94- {
95- name : "multiple lines with leading newlines " ,
96- args : args {
97- msg : "\n \n \n \n first line \n second line" ,
100+ {
101+ name : "multiple lines with leading newlines" ,
102+ args : args {
103+ msg : "\n \n \n \n first line \n second line " ,
104+ },
105+ want : "second line" ,
98106 },
99- want : "second line" ,
100- } ,
101- {
102- name : "multiple lines with trailing newlines " ,
103- args : args {
104- msg : "first line\n second line \n \n \n " ,
107+ {
108+ name : "multiple lines with trailing newlines" ,
109+ args : args {
110+ msg : "first line \n second line \n \n \n " ,
111+ },
112+ want : "second line" ,
105113 },
106- want : "second line" ,
107- },
108- }
109- ut := newTestRenderUtils (t )
110- for _ , tt := range tests {
111- t .Run (tt .name , func (t * testing.T ) {
112- assert .Equalf (t , tt .want , ut .RenderCommitBody (tt .args .msg , nil ), "RenderCommitBody(%v, %v)" , tt .args .msg , nil )
113- })
114- }
115-
116- expected := `/just/a/path.bin
114+ }
115+ ut := newTestRenderUtils (t )
116+ for _ , tt := range tests {
117+ t .Run (tt .name , func (t * testing.T ) {
118+ assert .Equalf (t , tt .want , ut .RenderCommitBody (tt .args .msg , mockRepo ), "RenderCommitBody(%v, %v)" , tt .args .msg , nil )
119+ })
120+ }
121+
122+ expected := `/just/a/path.bin
117123<a href="https://example.com/file.bin">https://example.com/file.bin</a>
118124[local link](file.bin)
119125[remote link](<a href="https://example.com">https://example.com</a>)
@@ -132,22 +138,22 @@ com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb mit
132138<a href="/mention-user">@mention-user</a> test
133139<a href="/user13/repo11/issues/123" class="ref-issue">#123</a>
134140 space`
135- assert .Equal (t , expected , string (newTestRenderUtils (t ).RenderCommitBody (testInput (), testMetas )))
136- }
141+ assert .Equal (t , expected , string (newTestRenderUtils (t ).RenderCommitBody (testInput (), mockRepo )))
142+ })
137143
138- func TestRenderCommitMessage (t * testing.T ) {
139- expected := `space <a href="/mention-user" data-markdown-generated-content="">@mention-user</a> `
140- assert .EqualValues (t , expected , newTestRenderUtils (t ).RenderCommitMessage (testInput (), testMetas ))
141- }
144+ t . Run ( "RenderCommitMessage" , func (t * testing.T ) {
145+ expected := `space <a href="/mention-user" data-markdown-generated-content="">@mention-user</a> `
146+ assert .EqualValues (t , expected , newTestRenderUtils (t ).RenderCommitMessage (testInput (), mockRepo ))
147+ })
142148
143- func TestRenderCommitMessageLinkSubject (t * testing.T ) {
144- expected := `<a href="https://example.com/link" class="muted">space </a><a href="/mention-user" data-markdown-generated-content="">@mention-user</a>`
145- assert .EqualValues (t , expected , newTestRenderUtils (t ).RenderCommitMessageLinkSubject (testInput (), "https://example.com/link" , testMetas ))
146- }
149+ t . Run ( "RenderCommitMessageLinkSubject" , func (t * testing.T ) {
150+ expected := `<a href="https://example.com/link" class="muted">space </a><a href="/mention-user" data-markdown-generated-content="">@mention-user</a>`
151+ assert .EqualValues (t , expected , newTestRenderUtils (t ).RenderCommitMessageLinkSubject (testInput (), "https://example.com/link" , mockRepo ))
152+ })
147153
148- func TestRenderIssueTitle (t * testing.T ) {
149- defer test .MockVariableValue (& markup .RenderBehaviorForTesting .DisableAdditionalAttributes , true )()
150- expected := ` space @mention-user<SPACE><SPACE>
154+ t . Run ( "RenderIssueTitle" , func (t * testing.T ) {
155+ defer test .MockVariableValue (& markup .RenderBehaviorForTesting .DisableAdditionalAttributes , true )()
156+ expected := ` space @mention-user<SPACE><SPACE>
151157/just/a/path.bin
152158https://example.com/file.bin
153159[local link](file.bin)
168174<a href="/user13/repo11/issues/123" class="ref-issue">#123</a>
169175 space<SPACE><SPACE>
170176`
171- expected = strings .ReplaceAll (expected , "<SPACE>" , " " )
172- assert .Equal (t , expected , string (newTestRenderUtils (t ).RenderIssueTitle (testInput (), testMetas )))
177+ expected = strings .ReplaceAll (expected , "<SPACE>" , " " )
178+ assert .Equal (t , expected , string (newTestRenderUtils (t ).RenderIssueTitle (testInput (), mockRepo )))
179+ })
173180}
174181
175182func TestRenderMarkdownToHtml (t * testing.T ) {
0 commit comments