// Copyright 2021 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package typesniffer
import (
"bytes"
"encoding/base64"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestDetectContentTypeLongerThanSniffLen(t *testing.T) {
// Pre-condition: Shorter than sniffLen detects SVG.
assert.Equal(t, "image/svg+xml", DetectContentType([]byte(``)).contentType)
// Longer than sniffLen detects something else.
assert.NotEqual(t, "image/svg+xml", DetectContentType([]byte(``)).contentType)
}
func TestIsTextFile(t *testing.T) {
assert.True(t, DetectContentType([]byte{}).IsText())
assert.True(t, DetectContentType([]byte("lorem ipsum")).IsText())
}
func TestIsSvgImage(t *testing.T) {
assert.True(t, DetectContentType([]byte("")).IsSvgImage())
assert.True(t, DetectContentType([]byte(" ")).IsSvgImage())
assert.True(t, DetectContentType([]byte(``)).IsSvgImage())
assert.True(t, DetectContentType([]byte("")).IsSvgImage())
assert.True(t, DetectContentType([]byte(``)).IsSvgImage())
assert.True(t, DetectContentType([]byte(`
`)).IsSvgImage())
assert.True(t, DetectContentType([]byte(`
`)).IsSvgImage())
assert.True(t, DetectContentType([]byte(`
`)).IsSvgImage())
assert.True(t, DetectContentType([]byte(`
`)).IsSvgImage())
assert.True(t, DetectContentType([]byte(`
`)).IsSvgImage())
assert.True(t, DetectContentType([]byte(`
`)).IsSvgImage())
assert.True(t, DetectContentType([]byte(`
`)).IsSvgImage())
assert.True(t, DetectContentType([]byte(`
`)).IsSvgImage())
assert.False(t, DetectContentType([]byte{}).IsSvgImage())
assert.False(t, DetectContentType([]byte("svg")).IsSvgImage())
assert.False(t, DetectContentType([]byte("