diff --git a/flake.lock b/flake.lock index cbf5f41..92ae66b 100644 --- a/flake.lock +++ b/flake.lock @@ -20,16 +20,16 @@ }, "nixpkgs": { "locked": { - "lastModified": 1754292888, - "narHash": "sha256-1ziydHSiDuSnaiPzCQh1mRFBsM2d2yRX9I+5OPGEmIE=", + "lastModified": 1764522689, + "narHash": "sha256-SqUuBFjhl/kpDiVaKLQBoD8TLD+/cTUzzgVFoaHrkqY=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "ce01daebf8489ba97bd1609d185ea276efdeb121", + "rev": "8bb5646e0bed5dbd3ab08c7a7cc15b75ab4e1d0f", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixos-25.05", + "ref": "nixos-25.11", "repo": "nixpkgs", "type": "github" } diff --git a/flake.nix b/flake.nix index 80bb6e3..66c6501 100644 --- a/flake.nix +++ b/flake.nix @@ -2,12 +2,18 @@ description = "Development Environment"; inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11"; flake-utils.url = "github:numtide/flake-utils"; }; - outputs = { self, nixpkgs, flake-utils }: - flake-utils.lib.eachDefaultSystem (system: + outputs = + { self + , nixpkgs + , flake-utils + , + }: + flake-utils.lib.eachDefaultSystem ( + system: let pkgs = nixpkgs.legacyPackages.${system}; in @@ -15,6 +21,7 @@ devShells.default = pkgs.mkShell { packages = with pkgs; [ go + gopls golangci-lint nodejs tailwindcss diff --git a/pkg/formatters/duration_test.go b/pkg/formatters/duration_test.go new file mode 100644 index 0000000..07b9d4d --- /dev/null +++ b/pkg/formatters/duration_test.go @@ -0,0 +1,22 @@ +package formatters + +import ( + "testing" + "time" +) + +func TestFormatDuration(t *testing.T) { + tests := []struct { + dur time.Duration + want string + }{ + {0, "N/A"}, + {22*24*time.Hour + 7*time.Hour + 39*time.Minute + 31*time.Second, "22d 7h 39m 31s"}, + {5*time.Minute + 15*time.Second, "5m 15s"}, + } + for _, tc := range tests { + if got := FormatDuration(tc.dur); got != tc.want { + t.Errorf("FormatDuration(%v) = %s, want %s", tc.dur, got, tc.want) + } + } +} diff --git a/pkg/formatters/numbers_test.go b/pkg/formatters/numbers_test.go new file mode 100644 index 0000000..84498f2 --- /dev/null +++ b/pkg/formatters/numbers_test.go @@ -0,0 +1,22 @@ +package formatters + +import ( + "testing" +) + +func TestFormatNumber(t *testing.T) { + tests := []struct { + input int64 + want string + }{ + {0, "0"}, + {19823, "19.8k"}, + {1500000, "1.50M"}, + {-12345, "-12.3k"}, + } + for _, tc := range tests { + if got := FormatNumber(tc.input); got != tc.want { + t.Errorf("FormatNumber(%d) = %s, want %s", tc.input, got, tc.want) + } + } +} \ No newline at end of file diff --git a/pkg/ptr/ptr_test.go b/pkg/ptr/ptr_test.go new file mode 100644 index 0000000..317d960 --- /dev/null +++ b/pkg/ptr/ptr_test.go @@ -0,0 +1,73 @@ +package ptr + +import ( + "testing" +) + +func TestOf(t *testing.T) { + // Test with different types + intVal := 42 + intPtr := Of(intVal) + if *intPtr != intVal { + t.Errorf("Expected %d, got %d", intVal, *intPtr) + } + + stringVal := "hello" + stringPtr := Of(stringVal) + if *stringPtr != stringVal { + t.Errorf("Expected %s, got %s", stringVal, *stringPtr) + } + + floatVal := 3.14 + floatPtr := Of(floatVal) + if *floatPtr != floatVal { + t.Errorf("Expected %f, got %f", floatVal, *floatPtr) + } +} + +func TestDeref(t *testing.T) { + // Test with non-nil pointer + intVal := 42 + intPtr := Of(intVal) + result := Deref(intPtr) + if result != intVal { + t.Errorf("Expected %d, got %d", intVal, result) + } + + // Test with nil pointer + var nilPtr *int + result = Deref(nilPtr) + if result != 0 { + t.Errorf("Expected 0, got %d", result) + } + + // Test with string + stringVal := "hello" + stringPtr := Of(stringVal) + resultStr := Deref(stringPtr) + if resultStr != stringVal { + t.Errorf("Expected %s, got %s", stringVal, resultStr) + } + + // Test with nil string pointer + var nilStrPtr *string + resultStr = Deref(nilStrPtr) + if resultStr != "" { + t.Errorf("Expected empty string, got %s", resultStr) + } +} + +func TestDerefZeroValue(t *testing.T) { + // Test that Deref returns zero value for nil pointers + var nilInt *int + result := Deref(nilInt) + if result != 0 { + t.Errorf("Expected zero int, got %d", result) + } + + var nilString *string + resultStr := Deref(nilString) + if resultStr != "" { + t.Errorf("Expected zero string, got %s", resultStr) + } +} diff --git a/pkg/sliceutils/sliceutils_test.go b/pkg/sliceutils/sliceutils_test.go new file mode 100644 index 0000000..2e80992 --- /dev/null +++ b/pkg/sliceutils/sliceutils_test.go @@ -0,0 +1,50 @@ +package sliceutils + +import ( + "testing" +) + +func TestFirst(t *testing.T) { + // Test with empty slice + var empty []int + result, ok := First(empty) + if ok != false { + t.Errorf("Expected ok=false for empty slice, got %v", ok) + } + if result != 0 { + t.Errorf("Expected zero value for empty slice, got %v", result) + } + + // Test with non-empty slice + testSlice := []int{1, 2, 3} + result, ok = First(testSlice) + if ok != true { + t.Errorf("Expected ok=true for non-empty slice, got %v", ok) + } + if result != 1 { + t.Errorf("Expected first element, got %v", result) + } +} + +func TestMap(t *testing.T) { + // Test with empty slice + var empty []int + result := Map(empty, func(x int) int { return x * 2 }) + if len(result) != 0 { + t.Errorf("Expected empty result for empty input, got %v", result) + } + + // Test with non-empty slice + testSlice := []int{1, 2, 3} + result = Map(testSlice, func(x int) int { return x * 2 }) + expected := []int{2, 4, 6} + if len(result) != len(expected) { + t.Errorf("Expected length %d, got %d", len(expected), len(result)) + } + for i, v := range result { + if v != expected[i] { + t.Errorf("Expected %d at index %d, got %d", expected[i], i, v) + } + } +} + diff --git a/pkg/utils/utils_test.go b/pkg/utils/utils_test.go new file mode 100644 index 0000000..d4a2dba --- /dev/null +++ b/pkg/utils/utils_test.go @@ -0,0 +1,45 @@ +package utils + +import ( + "testing" +) + +func TestTernary(t *testing.T) { + // Test true condition + result := Ternary(true, 42, 13) + if result != 42 { + t.Errorf("Expected 42, got %d", result) + } + + // Test false condition + result = Ternary(false, 42, 13) + if result != 13 { + t.Errorf("Expected 13, got %d", result) + } +} + +func TestFirstNonZero(t *testing.T) { + // Test with int values + result := FirstNonZero(0, 0, 42, 13) + if result != 42 { + t.Errorf("Expected 42, got %d", result) + } + + // Test with string values + resultStr := FirstNonZero("", "", "hello") + if resultStr != "hello" { + t.Errorf("Expected hello, got %s", resultStr) + } + + // Test all zero values (strings) + zeroResultStr := FirstNonZero("") + if zeroResultStr != "" { + t.Errorf("Expected empty string, got %s", zeroResultStr) + } + + // Test with float values + floatResult := FirstNonZero(0.0, 0.0, 3.14) + if floatResult != 3.14 { + t.Errorf("Expected 3.14, got %f", floatResult) + } +} \ No newline at end of file