// Copyright 2021 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package typesniffer
import (
"bytes"
"encoding/base64"
"encoding/hex"
"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())
// the DetectContentType should work for incomplete data, because only beginning bytes are used for detection
assert.True(t, DetectContentType([]byte(`