diff options
author | Matthias Loibl <mail@matthiasloibl.com> | 2016-11-07 21:49:50 +0100 |
---|---|---|
committer | Matthias Loibl <mail@matthiasloibl.com> | 2016-11-07 23:31:40 +0100 |
commit | d417aedcfac506674a5690c360e746ad17b366a6 (patch) | |
tree | 077120408fba5de5d55cef99a5f4ce47e3f779c4 /modules/base | |
parent | b00d82d67902b03298aedf6828b0c738398153a7 (diff) | |
download | gitea-d417aedcfac506674a5690c360e746ad17b366a6.tar.gz gitea-d417aedcfac506674a5690c360e746ad17b366a6.zip |
Add tests for StringsToInt64s() & Int64sToStrings()
Diffstat (limited to 'modules/base')
-rw-r--r-- | modules/base/tool.go | 3 | ||||
-rw-r--r-- | modules/base/tool_test.go | 51 |
2 files changed, 45 insertions, 9 deletions
diff --git a/modules/base/tool.go b/modules/base/tool.go index ab45dbae2f..209ff0a9cb 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.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 } diff --git a/modules/base/tool_test.go b/modules/base/tool_test.go index 5b69a45983..bca9954194 100644 --- a/modules/base/tool_test.go +++ b/modules/base/tool_test.go @@ -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() |