Una prueba en Go en Go
Un archivo que termina en _test.go, una función que toma *testing.T y t.Errorf.
func Slugify(title string) string {
return strings.ReplaceAll(strings.ToLower(title), " ", "-")
}
func TestSlugify(t *testing.T) {
got := Slugify("Language Basics")
want := "language-basics"
if got != want {
t.Errorf("Slugify() = %q, want %q", got, want)
}
}
func TestSlugifyEmpty(t *testing.T) {
if got := Slugify(""); got != "" {
t.Fatalf("expected empty, got %q", got)
}
}
Cómo funciona
- El nombre debe empezar con Test y tomar
*testing.T. t.Errorfregistra una falla y sigue;t.Fatalfse detiene.- No hay biblioteca de aserciones: la comparación la escribes tú.
Palabras clave y builtins usados aquí
funcifreturnstring
El intento, en números
- Líneas
- 17
- Caracteres a escribir
- 377
- Tokens
- 93
- Ritmo de tres estrellas
- 100 tpm
Al ritmo de tres estrellas de 100 tokens por minuto, este intento toma unos 56 segundos.
Paso 1 de 4 en Escribir pruebas; paso 1 de 13 en Pruebas.