Add tests for StringsToInt64s() & Int64sToStrings()

tokarchuk/v1.17
Matthias Loibl 8 years ago
parent b00d82d679
commit d417aedcfa
No known key found for this signature in database
GPG Key ID: B1C7DF661ABB2C1A
  1. 3
      modules/base/tool.go
  2. 51
      modules/base/tool_test.go

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

@ -9,11 +9,17 @@ import (
)
func TestEncodeMD5(t *testing.T) {
assert.Equal(t, "3858f62230ac3c915f300c664312c63f", EncodeMD5("foobar"))
assert.Equal(t,
"3858f62230ac3c915f300c664312c63f",
EncodeMD5("foobar"),
)
}
func TestEncodeSha1(t *testing.T) {
assert.Equal(t, "8843d7f92416211de9ebb963ff4ce28125932878", EncodeSha1("foobar"))
assert.Equal(t,
"8843d7f92416211de9ebb963ff4ce28125932878",
EncodeSha1("foobar"),
)
}
func TestShortSha(t *testing.T) {
@ -45,8 +51,14 @@ func TestGetRandomString(t *testing.T) {
// TODO: Test CreateTimeLimitCode()
func TestHashEmail(t *testing.T) {
assert.Equal(t, "d41d8cd98f00b204e9800998ecf8427e", HashEmail(""))
assert.Equal(t, "353cbad9b58e69c96154ad99f92bedc7", HashEmail("gitea@example.com"))
assert.Equal(t,
"d41d8cd98f00b204e9800998ecf8427e",
HashEmail(""),
)
assert.Equal(t,
"353cbad9b58e69c96154ad99f92bedc7",
HashEmail("gitea@example.com"),
)
}
func TestAvatarLink(t *testing.T) {
@ -57,10 +69,16 @@ func TestAvatarLink(t *testing.T) {
assert.Equal(t, "/img/avatar_default.png", AvatarLink(""))
setting.DisableGravatar = false
assert.Equal(t, "353cbad9b58e69c96154ad99f92bedc7", AvatarLink("gitea@example.com"))
assert.Equal(t,
"353cbad9b58e69c96154ad99f92bedc7",
AvatarLink("gitea@example.com"),
)
setting.EnableFederatedAvatar = true
assert.Equal(t, "353cbad9b58e69c96154ad99f92bedc7", AvatarLink("gitea@example.com"))
assert.Equal(t,
"353cbad9b58e69c96154ad99f92bedc7",
AvatarLink("gitea@example.com"),
)
setting.LibravatarService = libravatar.New()
assert.Equal(t,
"http://cdn.libravatar.org/avatar/353cbad9b58e69c96154ad99f92bedc7",
@ -116,8 +134,25 @@ func TestTruncateString(t *testing.T) {
assert.Equal(t, "foobar", TruncateString("foobar", 7))
}
// TODO: StringsToInt64s()
// TODO: Int64sToStrings()
func TestStringsToInt64s(t *testing.T) {
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: IsLetter()
// TODO: IsTextFile()

Loading…
Cancel
Save