1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

WTF-781 Todoist project ID conversion (#789)

* WTF-781 Switch Todoist IDs from `int` to `string`

On platforms that convert an `int` to `int32`, like the Raspberry Pi,
an `int` is not large enough to store Todoist project IDs.

Using a `string` ensures this never becomes a problem.

Fixes #781

Signed-off-by: Chris Cummer <chriscummer@me.com>
This commit is contained in:
Chris Cummer
2019-12-16 20:25:52 -08:00
committed by GitHub
parent 3a388fba23
commit 140dd553e0
9 changed files with 74 additions and 15 deletions

View File

@@ -19,6 +19,17 @@ func MapToStrs(aMap map[string]interface{}) map[string]string {
/* -------------------- Slice Conversion -------------------- */
// IntsToUints takes a slice of ints and returns a slice of uints
func IntsToUints(slice []int) []uint {
results := make([]uint, len(slice))
for i, val := range slice {
results[i] = uint(val)
}
return results
}
// ToInts takes a slice of interfaces and returns a slice of ints
func ToInts(slice []interface{}) []int {
results := make([]int, len(slice))
@@ -45,3 +56,14 @@ func ToStrs(slice []interface{}) []string {
return results
}
// ToUints takes a slice of interfaces and returns a slice of ints
func ToUints(slice []interface{}) []uint {
results := make([]uint, len(slice))
for i, val := range slice {
results[i] = val.(uint)
}
return results
}

View File

@@ -21,6 +21,32 @@ func Test_MapToStrs(t *testing.T) {
assert.Equal(t, expected, MapToStrs(source))
}
func Test_IntsToUints(t *testing.T) {
tests := []struct {
name string
src []int
expected []uint
}{
{
name: "empty set",
src: []int{},
expected: []uint{},
},
{
name: "full set",
src: []int{1, 2, 3},
expected: []uint{1, 2, 3},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actual := IntsToUints(tt.src)
assert.Equal(t, tt.expected, actual)
})
}
}
func Test_ToInts(t *testing.T) {
expected := []int{1, 2, 3}
@@ -49,3 +75,14 @@ func Test_ToStrs(t *testing.T) {
assert.Equal(t, expectedStrs, ToStrs(fromInts))
assert.Equal(t, expectedStrs, ToStrs(fromStrs))
}
func Test_ToUints(t *testing.T) {
expected := []uint{1, 2, 3}
source := make([]interface{}, len(expected))
for idx, val := range expected {
source[idx] = val
}
assert.Equal(t, expected, ToUints(source))
}