Skip to content

Add test for some movements - #56

Merged
merces merged 2 commits into
mentebinaria:mainfrom
glazari:add-test-to-event-handler-v0
Aug 13, 2026
Merged

Add test for some movements#56
merces merged 2 commits into
mentebinaria:mainfrom
glazari:add-test-to-event-handler-v0

Conversation

@glazari

@glazari glazari commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Adicionei um teste para os movimentos basicos como eu tinha dito

Comment thread src/events.rs

pub fn handle_events(app: &mut App) -> Result<bool> {
let event = event::read()?;
pub fn handle_events(app: &mut App, event: Event) -> Result<bool> {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Essa eh a principal mudanca que permite rodar esse teste sem um terminal

Comment thread test_data/test.bin
@@ -0,0 +1,3 @@
Not really a binary

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Um arquivo qualquer de teste. talvez de para nao ter ele e gerar um arquivo on the fly

Comment thread src/main.rs

/// Page size is dynamically calculated as:
/// frame height - (command line + status line + header) * bytes per line
pub fn update_page_size(app: &mut App, height: u16) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extrai como funcao, pq sem rodar isso o page_end e current_size ficam setados em zero e da problema no teste.

Acho que o ideal seria o App::new() ja gerar um app pronto para usar. mas eu mudaria isso depois so

Comment thread src/events.rs
Comment on lines +88 to +91
// (name, initial offset, key code, (expected cursor x, expected cursor y), new_offset)
let cases = [
// right
("right", 0, Right, (1, 0), 1),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eu costumo gostar de estruturar os testes assim: uma lista de casos e um for loop testando todos.

Eu acho que ajuda a deixar mais facil de adicionar mais casos parecidos depois.

Mas tem gente que prefere um teste separado por caso, nao sei o que voce prefere 🤷

@merces merces Aug 13, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bem legal essa abordagem. Nunca tinha visto, mas gostei. Bem mais rápido para escrever novos testes! :)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

muito bom mesmo, eu faço isso em python com pytest.mark.parametrize, fica bem legal para ampliar a cobertura no longo prazo.

Apesar disso não ser suportado nativamente por Rust, também dá pra ter um cenário parecido usando isso
https://crates.io/crates/rstest#:~:text=42)%3B%0A%7D-,Parametrize,-You%20can%20also

Comment thread src/main.rs Outdated

@merces merces left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Legal demais, muito obrigado! Só fiz uma pergunta sobre o println! ali, mas creio que não tenha sido intencional.

@glazari

glazari commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

Legal demais, muito obrigado! Só fiz uma pergunta sobre o println! ali, mas creio que não tenha sido intencional.

Boa, que bom que voce viu isso. esqueci mesmo. ja tirei

@merces
merces merged commit 9e960b8 into mentebinaria:main Aug 13, 2026
6 checks passed
@merces

merces commented Aug 13, 2026

Copy link
Copy Markdown
Member

Perfeito, obrigado!

@glazari
glazari deleted the add-test-to-event-handler-v0 branch August 13, 2026 13:13
@merces merces mentioned this pull request Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants