2 Commits

Author SHA1 Message Date
Unbound Release e60459ddd4 chore(release): prepare for v0.0.3 2025-06-16 07:13:07 +00:00
argoyle 8e8bdac22c fix: update GetPage to check for empty items slice
Refactor the GetPage function to check for an empty slice of items 
instead of a nil pointer. Update tests to cover cases for nil and 
empty slices, ensuring consistent behavior and improved clarity.
2025-06-16 09:09:04 +02:00
3 changed files with 14 additions and 2 deletions
+6
View File
@@ -2,6 +2,12 @@
All notable changes to this project will be documented in this file.
## [0.0.3] - 2025-06-16
### 🐛 Bug Fixes
- Update GetPage to check for empty items slice
## [0.0.2] - 2025-06-15
### 🐛 Bug Fixes
+1 -1
View File
@@ -52,7 +52,7 @@ func EncodeCursor(cursor string) string {
}
func GetPage[T any](items []T, first *int, after *string, last *int, before *string, max int, fn func(T) string) ([]T, PageInfo) {
if items == nil {
if len(items) == 0 {
return nil, PageInfo{}
}
tmp := min(max, len(items))
+7 -1
View File
@@ -24,11 +24,17 @@ func TestGetPage(t *testing.T) {
}
tests := []testCase[string]{
{
name: "empty",
name: "nil items",
args: args[string]{max: 10},
wantItems: nil,
wantPageInfo: PageInfo{},
},
{
name: "empty items",
args: args[string]{items: []string{}, max: 10},
wantItems: nil,
wantPageInfo: PageInfo{},
},
{
name: "first 2",
args: args[string]{items: []string{"1", "2", "3"}, first: ptr(2), max: 10, fn: func(s string) string { return s }},