go-learning/using_modules/using_modules_test.go

27 lines
641 B
Go
Raw Permalink Normal View History

2025-08-30 12:55:18 +00:00
package using_modules
import (
"testing"
"regexp"
)
// TestHelloName calls greetings.Hello with a name, checking
// for a valid return value.
func TestHelloName(t *testing.T) {
name := "Gladys"
want := regexp.MustCompile(`\b`+name+`\b`)
msg, err := Hello("Gladys")
if !want.MatchString(msg) || err != nil {
t.Errorf(`Hello("Gladys") = %q, %v, want match for %#q, nill`, msg, err, want)
}
}
// TestHelloEmpty calls greeting.Hello with an empty string,
// checking for an error
func TestHelloEmpty(t *testing.T) {
msg, err := Hello("")
if msg != "" || err == nil {
t.Errorf(`Hello("") = %q, %v, want "", error`, msg, err)
}
}