1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-11-04 08:17:24 -05:00

Add tests for StringsToInt64s() & Int64sToStrings()

This commit is contained in:
Matthias Loibl 2016-11-07 21:49:50 +01:00
parent b00d82d679
commit d417aedcfa
No known key found for this signature in database
GPG Key ID: B1C7DF661ABB2C1A
2 changed files with 45 additions and 9 deletions

View File

@ -16,6 +16,7 @@ import (
"html/template" "html/template"
"math" "math"
"net/http" "net/http"
"strconv"
"strings" "strings"
"time" "time"
"unicode" "unicode"
@ -491,7 +492,7 @@ func StringsToInt64s(strs []string) []int64 {
func Int64sToStrings(ints []int64) []string { func Int64sToStrings(ints []int64) []string {
strs := make([]string, len(ints)) strs := make([]string, len(ints))
for i := range ints { for i := range ints {
strs[i] = com.ToStr(ints[i]) strs[i] = strconv.FormatInt(ints[i], 10)
} }
return strs return strs
} }

View File

@ -9,11 +9,17 @@ import (
) )
func TestEncodeMD5(t *testing.T) { func TestEncodeMD5(t *testing.T) {
assert.Equal(t, "3858f62230ac3c915f300c664312c63f", EncodeMD5("foobar")) assert.Equal(t,
"3858f62230ac3c915f300c664312c63f",
EncodeMD5("foobar"),
)
} }
func TestEncodeSha1(t *testing.T) { func TestEncodeSha1(t *testing.T) {
assert.Equal(t, "8843d7f92416211de9ebb963ff4ce28125932878", EncodeSha1("foobar")) assert.Equal(t,
"8843d7f92416211de9ebb963ff4ce28125932878",
EncodeSha1("foobar"),
)
} }
func TestShortSha(t *testing.T) { func TestShortSha(t *testing.T) {
@ -45,8 +51,14 @@ func TestGetRandomString(t *testing.T) {
// TODO: Test CreateTimeLimitCode() // TODO: Test CreateTimeLimitCode()
func TestHashEmail(t *testing.T) { func TestHashEmail(t *testing.T) {
assert.Equal(t, "d41d8cd98f00b204e9800998ecf8427e", HashEmail("")) assert.Equal(t,
assert.Equal(t, "353cbad9b58e69c96154ad99f92bedc7", HashEmail("gitea@example.com")) "d41d8cd98f00b204e9800998ecf8427e",
HashEmail(""),
)
assert.Equal(t,
"353cbad9b58e69c96154ad99f92bedc7",
HashEmail("gitea@example.com"),
)
} }
func TestAvatarLink(t *testing.T) { func TestAvatarLink(t *testing.T) {
@ -57,10 +69,16 @@ func TestAvatarLink(t *testing.T) {
assert.Equal(t, "/img/avatar_default.png", AvatarLink("")) assert.Equal(t, "/img/avatar_default.png", AvatarLink(""))
setting.DisableGravatar = false setting.DisableGravatar = false
assert.Equal(t, "353cbad9b58e69c96154ad99f92bedc7", AvatarLink("gitea@example.com")) assert.Equal(t,
"353cbad9b58e69c96154ad99f92bedc7",
AvatarLink("gitea@example.com"),
)
setting.EnableFederatedAvatar = true setting.EnableFederatedAvatar = true
assert.Equal(t, "353cbad9b58e69c96154ad99f92bedc7", AvatarLink("gitea@example.com")) assert.Equal(t,
"353cbad9b58e69c96154ad99f92bedc7",
AvatarLink("gitea@example.com"),
)
setting.LibravatarService = libravatar.New() setting.LibravatarService = libravatar.New()
assert.Equal(t, assert.Equal(t,
"http://cdn.libravatar.org/avatar/353cbad9b58e69c96154ad99f92bedc7", "http://cdn.libravatar.org/avatar/353cbad9b58e69c96154ad99f92bedc7",
@ -116,8 +134,25 @@ func TestTruncateString(t *testing.T) {
assert.Equal(t, "foobar", TruncateString("foobar", 7)) assert.Equal(t, "foobar", TruncateString("foobar", 7))
} }
// TODO: StringsToInt64s() func TestStringsToInt64s(t *testing.T) {
// TODO: Int64sToStrings() assert.Equal(t, []int64{}, StringsToInt64s([]string{}))
assert.Equal(t,
[]int64{1, 4, 16, 64, 256},
StringsToInt64s([]string{"1", "4", "16", "64", "256"}),
)
// TODO: StringsToInt64s should return ([]int64, error)
assert.Equal(t, []int64{-1, 0, 0}, StringsToInt64s([]string{"-1", "a", "$"}))
}
func TestInt64sToStrings(t *testing.T) {
assert.Equal(t, []string{}, Int64sToStrings([]int64{}))
assert.Equal(t,
[]string{"1", "4", "16", "64", "256"},
Int64sToStrings([]int64{1, 4, 16, 64, 256}),
)
}
// TODO: Int64sToMap() // TODO: Int64sToMap()
// TODO: IsLetter() // TODO: IsLetter()
// TODO: IsTextFile() // TODO: IsTextFile()