|
5 | 5 | package base
|
6 | 6 |
|
7 | 7 | import (
|
8 |
| - "encoding/base64" |
9 | 8 | "os"
|
10 | 9 | "testing"
|
11 | 10 | "time"
|
@@ -246,97 +245,6 @@ func TestIsLetter(t *testing.T) {
|
246 | 245 | assert.False(t, IsLetter(0x93))
|
247 | 246 | }
|
248 | 247 |
|
249 |
| -func TestDetectContentTypeLongerThanSniffLen(t *testing.T) { |
250 |
| - // Pre-condition: Shorter than sniffLen detects SVG. |
251 |
| - assert.Equal(t, "image/svg+xml", DetectContentType([]byte(`<!-- Comment --><svg></svg>`))) |
252 |
| - // Longer than sniffLen detects something else. |
253 |
| - assert.Equal(t, "text/plain; charset=utf-8", DetectContentType([]byte(`<!-- |
254 |
| -Comment Comment Comment Comment Comment Comment Comment Comment Comment Comment |
255 |
| -Comment Comment Comment Comment Comment Comment Comment Comment Comment Comment |
256 |
| -Comment Comment Comment Comment Comment Comment Comment Comment Comment Comment |
257 |
| -Comment Comment Comment Comment Comment Comment Comment Comment Comment Comment |
258 |
| -Comment Comment Comment Comment Comment Comment Comment Comment Comment Comment |
259 |
| -Comment Comment Comment Comment Comment Comment Comment Comment Comment Comment |
260 |
| -Comment Comment Comment --><svg></svg>`))) |
261 |
| -} |
262 |
| - |
263 |
| -// IsRepresentableAsText |
264 |
| - |
265 |
| -func TestIsTextFile(t *testing.T) { |
266 |
| - assert.True(t, IsTextFile([]byte{})) |
267 |
| - assert.True(t, IsTextFile([]byte("lorem ipsum"))) |
268 |
| -} |
269 |
| - |
270 |
| -func TestIsImageFile(t *testing.T) { |
271 |
| - png, _ := base64.StdEncoding.DecodeString("iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAG0lEQVQYlWN4+vTpf3SMDTAMBYXYBLFpHgoKAeiOf0SGE9kbAAAAAElFTkSuQmCC") |
272 |
| - assert.True(t, IsImageFile(png)) |
273 |
| - assert.False(t, IsImageFile([]byte("plain text"))) |
274 |
| -} |
275 |
| - |
276 |
| -func TestIsSVGImageFile(t *testing.T) { |
277 |
| - assert.True(t, IsSVGImageFile([]byte("<svg></svg>"))) |
278 |
| - assert.True(t, IsSVGImageFile([]byte(" <svg></svg>"))) |
279 |
| - assert.True(t, IsSVGImageFile([]byte(`<svg width="100"></svg>`))) |
280 |
| - assert.True(t, IsSVGImageFile([]byte("<svg/>"))) |
281 |
| - assert.True(t, IsSVGImageFile([]byte(`<?xml version="1.0" encoding="UTF-8"?><svg></svg>`))) |
282 |
| - assert.True(t, IsSVGImageFile([]byte(`<!-- Comment --> |
283 |
| - <svg></svg>`))) |
284 |
| - assert.True(t, IsSVGImageFile([]byte(`<!-- Multiple --> |
285 |
| - <!-- Comments --> |
286 |
| - <svg></svg>`))) |
287 |
| - assert.True(t, IsSVGImageFile([]byte(`<!-- Multiline |
288 |
| - Comment --> |
289 |
| - <svg></svg>`))) |
290 |
| - assert.True(t, IsSVGImageFile([]byte(`<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Basic//EN" |
291 |
| - "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-basic.dtd"> |
292 |
| - <svg></svg>`))) |
293 |
| - assert.True(t, IsSVGImageFile([]byte(`<?xml version="1.0" encoding="UTF-8"?> |
294 |
| - <!-- Comment --> |
295 |
| - <svg></svg>`))) |
296 |
| - assert.True(t, IsSVGImageFile([]byte(`<?xml version="1.0" encoding="UTF-8"?> |
297 |
| - <!-- Multiple --> |
298 |
| - <!-- Comments --> |
299 |
| - <svg></svg>`))) |
300 |
| - assert.True(t, IsSVGImageFile([]byte(`<?xml version="1.0" encoding="UTF-8"?> |
301 |
| - <!-- Multline |
302 |
| - Comment --> |
303 |
| - <svg></svg>`))) |
304 |
| - assert.True(t, IsSVGImageFile([]byte(`<?xml version="1.0" encoding="UTF-8"?> |
305 |
| - <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> |
306 |
| - <!-- Multline |
307 |
| - Comment --> |
308 |
| - <svg></svg>`))) |
309 |
| - assert.False(t, IsSVGImageFile([]byte{})) |
310 |
| - assert.False(t, IsSVGImageFile([]byte("svg"))) |
311 |
| - assert.False(t, IsSVGImageFile([]byte("<svgfoo></svgfoo>"))) |
312 |
| - assert.False(t, IsSVGImageFile([]byte("text<svg></svg>"))) |
313 |
| - assert.False(t, IsSVGImageFile([]byte("<html><body><svg></svg></body></html>"))) |
314 |
| - assert.False(t, IsSVGImageFile([]byte(`<script>"<svg></svg>"</script>`))) |
315 |
| - assert.False(t, IsSVGImageFile([]byte(`<!-- <svg></svg> inside comment --> |
316 |
| - <foo></foo>`))) |
317 |
| - assert.False(t, IsSVGImageFile([]byte(`<?xml version="1.0" encoding="UTF-8"?> |
318 |
| - <!-- <svg></svg> inside comment --> |
319 |
| - <foo></foo>`))) |
320 |
| -} |
321 |
| - |
322 |
| -func TestIsPDFFile(t *testing.T) { |
323 |
| - pdf, _ := base64.StdEncoding.DecodeString("JVBERi0xLjYKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0ZpbHRlci9GbGF0ZURlY29kZT4+CnN0cmVhbQp4nF3NPwsCMQwF8D2f4s2CNYk1baF0EHRwOwg4iJt/NsFb/PpevUE4Mjwe") |
324 |
| - assert.True(t, IsPDFFile(pdf)) |
325 |
| - assert.False(t, IsPDFFile([]byte("plain text"))) |
326 |
| -} |
327 |
| - |
328 |
| -func TestIsVideoFile(t *testing.T) { |
329 |
| - mp4, _ := base64.StdEncoding.DecodeString("AAAAGGZ0eXBtcDQyAAAAAGlzb21tcDQyAAEI721vb3YAAABsbXZoZAAAAADaBlwX2gZcFwAAA+gA") |
330 |
| - assert.True(t, IsVideoFile(mp4)) |
331 |
| - assert.False(t, IsVideoFile([]byte("plain text"))) |
332 |
| -} |
333 |
| - |
334 |
| -func TestIsAudioFile(t *testing.T) { |
335 |
| - mp3, _ := base64.StdEncoding.DecodeString("SUQzBAAAAAABAFRYWFgAAAASAAADbWFqb3JfYnJhbmQAbXA0MgBUWFhYAAAAEQAAA21pbm9yX3Zl") |
336 |
| - assert.True(t, IsAudioFile(mp3)) |
337 |
| - assert.False(t, IsAudioFile([]byte("plain text"))) |
338 |
| -} |
339 |
| - |
340 | 248 | // TODO: Test EntryIcon
|
341 | 249 |
|
342 | 250 | func TestSetupGiteaRoot(t *testing.T) {
|
|
0 commit comments