<commit_before>// Copyright 2015 by caixw, All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.

package upload

import (
	"os"
	"testing"

	"github.com/issue9/assert"
)

func TestNew(t *testing.T) {
	a := assert.New(t)

	u, err := New("./testdir", "2006/01/02/", 10*1024, "gif", ".png", ".GIF")
	a.NotError(err).NotNil(u)
	// 自动转换成小写，且加上最前面的.符号
	a.Equal(u.exts, []string{".gif", ".png", ".gif"})
	a.Equal(u.dir, "./testdir"+string(os.PathSeparator))

	// dir为一个文件
	u, err = New("./testdir/file", "2006/01/02/", 10*1024, "gif", ".png", ".GIF")
	a.Error(err).Nil(u)
}

func TestUpload_isAllowExt(t *testing.T) {
	a := assert.New(t)

	u, err := New("./testdir", "2006/01/02/", 10*1024, "gif", ".png", ".GIF")
	a.NotError(err).NotNil(u)
	a.True(u.isAllowExt(".gif"))
	a.True(u.isAllowExt(".png"))

	a.False(u.isAllowExt(".TXT"))
	a.False(u.isAllowExt(""))
	a.False(u.isAllowExt(".png"))
	a.False(u.isAllowExt(".exe"))
}

func TestUpload_getDestPath(t *testing.T) {
	a := assert.New(t)

	u, err := New("./testdir", "2006/01/02/", 10*1024, "gif", ".png", ".GIF")<commit_msg>修正测试错误<commit_after>// Copyright 2015 by caixw, All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.

package upload

import (
	"os"
	"testing"

	"github.com/issue9/assert"
)

func TestNew(t *testing.T) {
	a := assert.New(t)

	u, err := New("./testdir", "2006/01/02/", 10*1024, "gif", ".png", ".GIF")
	a.NotError(err).NotNil(u)
	// 自动转换成小写，且加上最前面的.符号
	a.Equal(u.exts, []string{".gif", ".png", ".gif"})
	a.Equal(u.dir, "./testdir"+string(os.PathSeparator))

	// dir为一个文件
	u, err = New("./testdir/file", "2006/01/02/", 10*1024, "gif", ".png", ".GIF")
	a.Error(err).Nil(u)
}

func TestUpload_isAllowExt(t *testing.T) {
	a := assert.New(t)

	u, err := New("./testdir", "2006/01/02/", 10*1024, "gif", ".png", ".GIF")
	a.NotError(err).NotNil(u)
	a.True(u.isAllowExt(".gif"))
	a.True(u.isAllowExt(".png"))

	a.False(u.isAllowExt(".TXT"))
	a.False(u.isAllowExt(""))
	a.False(u.isAllowExt("png"))
	a.False(u.isAllowExt(".exe"))
}

func TestUpload_getDestPath(t *testing.T) {
	a := assert.New(t)

	u, err := New("./testdir", "2006/01/02/", 10*1024, "gif", ".png", ".GIF")
{'fraction_non_alphanumeric': 0.24447391688771, 'fraction_numerical': 0.053934571175950484, 'mean_word_length': 3.877155172413793, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1624477', 'n_tokens_mistral': 1096, 'n_tokens_neox': 1006, 'n_words': 193}