Testes Unitários
Marque os testes unitários com #[test]
:
fn primeira_palavra(texto: &str) -> &str {
match texto.find(' ') {
Some(idx) => &texto[..idx],
None => &texto,
}
}
#[test]
fn teste_vazio() {
assert_eq!(primeira_palavra(""), "");
}
#[test]
fn teste_palavra_unica() {
assert_eq!(primeira_palavra("Hello"), "Hello");
}
#[test]
fn teste_palavras_multiplas() {
assert_eq!(primeira_palavra("Hello World"), "Hello");
}
Use cargo test
para encontrar e executar os testes unitários.