hello default world

This commit is contained in:
vinchent 2024-09-10 11:12:42 +02:00
parent f13632e425
commit cbd4cf628f
2 changed files with 18 additions and 5 deletions

View File

@ -3,6 +3,9 @@ package main
import "fmt" import "fmt"
func Hello(name string) string { func Hello(name string) string {
if name == "" {
return "Hello world"
}
return fmt.Sprintf("Hello %s", name) return fmt.Sprintf("Hello %s", name)
} }

View File

@ -3,9 +3,19 @@ package main
import "testing" import "testing"
func TestHello(t *testing.T) { func TestHello(t *testing.T) {
got := Hello("Jason") t.Run("Hello someone", func(t *testing.T) {
exp := "Hello Jason" got := Hello("Jason")
if got != exp { exp := "Hello Jason"
t.Errorf("got %q expected %q", got, exp) if got != exp {
} t.Errorf("got %q expected %q", got, exp)
}
})
t.Run("Hello default", func(t *testing.T) {
got := Hello("")
exp := "Hello world"
if got != exp {
t.Errorf("got %q expected %q", got, exp)
}
})
} }