Initial commit: Go project with greet function and CLI

This commit is contained in:
Gabriel Radureau
2026-04-03 12:20:55 +02:00
commit 3efc1992d5
7 changed files with 201 additions and 0 deletions

10
pkg/greet/greet.go Normal file
View File

@@ -0,0 +1,10 @@
package greet
// Greet returns a greeting message for the given name.
// If name is empty, it defaults to "world".
func Greet(name string) string {
if name == "" {
return "Hello world!"
}
return "Hello " + name + "!"
}

24
pkg/greet/greet_test.go Normal file
View File

@@ -0,0 +1,24 @@
package greet
import "testing"
func TestGreet(t *testing.T) {
tests := []struct {
name string
expected string
}{
{"", "Hello world!"},
{"John", "Hello John!"},
{"Alice", "Hello Alice!"},
{" ", "Hello !"}, // spaces are not considered empty
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := Greet(tt.name)
if result != tt.expected {
t.Errorf("Greet(%q) = %q, want %q", tt.name, result, tt.expected)
}
})
}
}