@@ -49,16 +49,37 @@ func wrap(ctx *context.Context) *context.APIContext {
49
49
}
50
50
}
51
51
52
- func TestAPI_RenderGFM (t * testing.T ) {
52
+ func testRenderMarkup (t * testing.T , mode , filePath , text , responseBody string , responseCode int ) {
53
+ setting .AppURL = AppURL
54
+
55
+ options := api.MarkupOption {
56
+ Mode : mode ,
57
+ Text : "" ,
58
+ Context : Repo ,
59
+ Wiki : true ,
60
+ FilePath : filePath ,
61
+ }
62
+ requrl , _ := url .Parse (util .URLJoin (AppURL , "api" , "v1" , "markup" ))
63
+ req := & http.Request {
64
+ Method : "POST" ,
65
+ URL : requrl ,
66
+ }
67
+ m , resp := createContext (req )
68
+ ctx := wrap (m )
69
+
70
+ options .Text = text
71
+ web .SetForm (ctx , & options )
72
+ Markup (ctx )
73
+ assert .Equal (t , responseBody , resp .Body .String ())
74
+ assert .Equal (t , responseCode , resp .Code )
75
+ resp .Body .Reset ()
76
+ }
77
+
78
+ func testRenderMarkdown (t * testing.T , mode , text , responseBody string , responseCode int ) {
53
79
setting .AppURL = AppURL
54
- markup .Init (& markup.ProcessorHelper {
55
- IsUsernameMentionable : func (ctx go_context.Context , username string ) bool {
56
- return username == "r-lyeh"
57
- },
58
- })
59
80
60
81
options := api.MarkdownOption {
61
- Mode : "gfm" ,
82
+ Mode : mode ,
62
83
Text : "" ,
63
84
Context : Repo ,
64
85
Wiki : true ,
@@ -71,7 +92,22 @@ func TestAPI_RenderGFM(t *testing.T) {
71
92
m , resp := createContext (req )
72
93
ctx := wrap (m )
73
94
74
- testCases := []string {
95
+ options .Text = text
96
+ web .SetForm (ctx , & options )
97
+ Markdown (ctx )
98
+ assert .Equal (t , responseBody , resp .Body .String ())
99
+ assert .Equal (t , responseCode , resp .Code )
100
+ resp .Body .Reset ()
101
+ }
102
+
103
+ func TestAPI_RenderGFM (t * testing.T ) {
104
+ markup .Init (& markup.ProcessorHelper {
105
+ IsUsernameMentionable : func (ctx go_context.Context , username string ) bool {
106
+ return username == "r-lyeh"
107
+ },
108
+ })
109
+
110
+ testCasesCommon := []string {
75
111
// dear imgui wiki markdown extract: special wiki syntax
76
112
`Wiki! Enjoy :)
77
113
- [[Links, Language bindings, Engine bindings|Links]]
@@ -85,6 +121,23 @@ func TestAPI_RenderGFM(t *testing.T) {
85
121
<li>Bezier widget (by <a href="` + AppURL + `r-lyeh" rel="nofollow">@r-lyeh</a>) <a href="https://github.com/ocornut/imgui/issues/786" rel="nofollow">https://github.com/ocornut/imgui/issues/786</a></li>
86
122
</ul>
87
123
` ,
124
+ // Guard wiki sidebar: special syntax
125
+ `[[Guardfile-DSL / Configuring-Guard|Guardfile-DSL---Configuring-Guard]]` ,
126
+ // rendered
127
+ `<p><a href="` + AppSubURL + `wiki/Guardfile-DSL---Configuring-Guard" rel="nofollow">Guardfile-DSL / Configuring-Guard</a></p>
128
+ ` ,
129
+ // special syntax
130
+ `[[Name|Link]]` ,
131
+ // rendered
132
+ `<p><a href="` + AppSubURL + `wiki/Link" rel="nofollow">Name</a></p>
133
+ ` ,
134
+ // empty
135
+ `` ,
136
+ // rendered
137
+ `` ,
138
+ }
139
+
140
+ testCasesDocument := []string {
88
141
// wine-staging wiki home extract: special wiki syntax, images
89
142
`## What is Wine Staging?
90
143
**Wine Staging** on website [wine-staging.com](http://wine-staging.com).
@@ -103,29 +156,28 @@ Here are some links to the most important topics. You can find the full list of
103
156
<p><a href="` + AppSubURL + `wiki/Configuration" rel="nofollow">Configuration</a>
104
157
<a href="` + AppSubURL + `wiki/raw/images/icon-bug.png" rel="nofollow"><img src="` + AppSubURL + `wiki/raw/images/icon-bug.png" title="icon-bug.png" alt="images/icon-bug.png"/></a></p>
105
158
` ,
106
- // Guard wiki sidebar: special syntax
107
- `[[Guardfile-DSL / Configuring-Guard|Guardfile-DSL---Configuring-Guard]]` ,
108
- // rendered
109
- `<p><a href="` + AppSubURL + `wiki/Guardfile-DSL---Configuring-Guard" rel="nofollow">Guardfile-DSL / Configuring-Guard</a></p>
110
- ` ,
111
- // special syntax
112
- `[[Name|Link]]` ,
113
- // rendered
114
- `<p><a href="` + AppSubURL + `wiki/Link" rel="nofollow">Name</a></p>
115
- ` ,
116
- // empty
117
- `` ,
118
- // rendered
119
- `` ,
120
159
}
121
160
122
- for i := 0 ; i < len (testCases ); i += 2 {
123
- options .Text = testCases [i ]
124
- web .SetForm (ctx , & options )
125
- Markdown (ctx )
126
- assert .Equal (t , testCases [i + 1 ], resp .Body .String ())
127
- resp .Body .Reset ()
161
+ for i := 0 ; i < len (testCasesCommon ); i += 2 {
162
+ text := testCasesCommon [i ]
163
+ response := testCasesCommon [i + 1 ]
164
+ testRenderMarkdown (t , "gfm" , text , response , http .StatusOK )
165
+ testRenderMarkup (t , "gfm" , "" , text , response , http .StatusOK )
166
+ testRenderMarkdown (t , "comment" , text , response , http .StatusOK )
167
+ testRenderMarkup (t , "comment" , "" , text , response , http .StatusOK )
168
+ testRenderMarkup (t , "file" , "path/test.md" , text , response , http .StatusOK )
128
169
}
170
+
171
+ for i := 0 ; i < len (testCasesDocument ); i += 2 {
172
+ text := testCasesDocument [i ]
173
+ response := testCasesDocument [i + 1 ]
174
+ testRenderMarkdown (t , "gfm" , text , response , http .StatusOK )
175
+ testRenderMarkup (t , "gfm" , "" , text , response , http .StatusOK )
176
+ testRenderMarkup (t , "file" , "path/test.md" , text , response , http .StatusOK )
177
+ }
178
+
179
+ testRenderMarkup (t , "file" , "path/test.unknown" , "## Test" , "Unsupported render extension: .unknown\n " , http .StatusUnprocessableEntity )
180
+ testRenderMarkup (t , "unknown" , "" , "## Test" , "Unknown mode: unknown\n " , http .StatusUnprocessableEntity )
129
181
}
130
182
131
183
var simpleCases = []string {
0 commit comments