Skip to content

Conversation

@JGBSouza
Copy link

This commit add tests to the Bookmarked functions, increasing it's test coverage.

@JGBSouza JGBSouza changed the title test: add tests to Bookmarked functions test: Bookmarked: add tests to Bookmarked functions Nov 10, 2025
@JGBSouza JGBSouza force-pushed the test/bookmarked_patches branch from d4aba9c to 3846fb0 Compare November 10, 2025 02:48
Copy link
Collaborator

@lorenzoberts lorenzoberts left a comment

Choose a reason for hiding this comment

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

Hey @JGBSouza, thanks for one more contribution.

  1. You can see now that some actions are failing, and that's because for some reason i still have to approve the workflows from you PR, so when you pushed it the actions were not running. Please fix the format and linting stuff. Also, the pre-commit should have failed when you commited these changes, so make sure it's running so we don't depend on github actions to run fmt, lint and tests
  2. We don't need to prefixes for the commit title, just the conventional commit prefix is sufficient. So instead of "test: Bookmarked: ...." you should replace with "test: add tests to...". This is a change i could make myself when pushing it to upstream, but i'm letting you know anyway.
  3. Let me know if my comments make sense. Nothing is super strict, but i see more as good practices when creating tests.

Comment on lines 48 to 58
/// # Tests
///
/// [tests::test_select_below_patchset_increments_index]
/// [tests::test_select_below_patchset_stops_at_end]
/// [tests::test_select_above_patchset_decrements_index]
/// [tests::test_select_above_patchset_stops_at_start]
/// [tests::test_get_selected_patchset_returns_correct_patch]
/// [tests::test_bookmark_selected_patch_adds_new_patch]
/// [tests::test_bookmark_selected_patch_does_not_duplicate]
/// [tests::test_unbookmark_selected_patch_removes_patch]
/// [tests::test_unbookmark_selected_patch_ignores_missing_patch]
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the objective of these docstrings? Maybe it's my limited Rust knowledge but i don't think this comments will do anything

/// [tests::test_bookmark_selected_patch_does_not_duplicate]
/// [tests::test_unbookmark_selected_patch_removes_patch]
/// [tests::test_unbookmark_selected_patch_ignores_missing_patch]
pub fn make_patch(title: &str) -> Patch {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why does it need to be pub?

Comment on lines 87 to 88
s.select_below_patchset();
assert_eq!(s.patchset_index, 1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

it would be more consistent to assert the current patchset_index before and after the select_below_patchset call. So the function behavior is explicit in the test

Comment on lines +110 to +101
s.select_above_patchset();
assert_eq!(s.patchset_index, 0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

same thing here. We shouldn't need to see mock_bookmarked_patchsets implementation to understand what's the initial patchset_index. You can assert or set the patchset_index

#[test]
fn test_unbookmark_selected_patch_removes_patch() {
let mut s = mock_bookmarked_patchsets();
let to_remove = make_patch("Patch 2");
Copy link
Collaborator

Choose a reason for hiding this comment

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

it would make more sense to set to_remove as s.bookmarked_patchsets[1] and then unbookmark it. make_patch("Patch 2") wouldn't necessarily be in the mocked struct. If to_remove was make_patch("Patch 9"), the function would still work because Patch 9 was never bookmarked in the first place

let mut s = mock_bookmarked_patchsets();
let missing = make_patch("Inexistent");
s.unbookmark_selected_patch(&missing);
assert_eq!(s.bookmarked_patchsets.len(), 3);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again, you should be asserting the len before the unbookmark_selected_patch operation so the test behavior is explicit

@JGBSouza JGBSouza force-pushed the test/bookmarked_patches branch from 3846fb0 to 838622a Compare November 23, 2025 21:30
This commit add tests to the Bookmarked functions.

Signed-off-by: JGBSouza <joaosouzaaa12@usp.br>
@JGBSouza JGBSouza force-pushed the test/bookmarked_patches branch from 838622a to acd6f8e Compare November 23, 2025 21:52
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.

2 participants