test(paths): cover lexical normalize and subtree grants - #80
Merged
Merged
Conversation
normalize_lexically, insert_subtree, path_within_subtree, and component_matches_ignore_ascii_case had no test reaching them. A wrong .. pop, an escaping parent, or a prefix-sibling treated as inside a grant would ship without a failing test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
crates/moon-util/src/paths.rshad pure path helpers no existing test reached. This adds six unit tests for the branches a caller would notice: lexical../.normalization, a..that climbs out of the path, subtree-grant pruning, and ASCII case-folding of a path component.Production behaviour is unchanged. The only edit in
paths.rsis#[cfg(test)] mod paths_tests;. The existing inline tests in that file were not modified.Tests and the mutation that proved each one
Each test was run green, the production function was mutated, that test failed for the reason below, the production file was restored (
git diffshowed only the module declaration), and the test was run green again.normalize_lexically_collapses_dot_and_parent_inside_the_path—ParentDirdidcontinueinstead oflexical.pop(). Failedassert_eqwith leftfoo\barand rightbar.normalize_lexically_rejects_parent_that_escapes_the_root— the root-length check becameif false && ..., so a..that reaches the root was popped instead of rejected. Failed becausefoo/../../barreturnedOk("bar").insert_subtree_prunes_descendants_and_keeps_prefix_siblings—retainkept every grant. Failedassert_eq: left still containedproj/srcandproj/tests.insert_subtree_ignores_a_path_an_existing_grant_covers— the already-covered early return was skipped (if false &&). Failedassert_eq: left gainedproj/src.path_within_subtree_matches_the_grant_and_not_a_prefix_sibling—path.starts_with(granted)was inverted. Failed the assertion thatproj2must stay outside aprojgrant.component_matches_ignore_ascii_case_folds_ascii_case—eq_ignore_ascii_casebecameeq. Failed the assertion that.ZEDmatches.zed.A review with a clean context kept all six. Nothing was dropped. Nothing was left unverified.
Still untested in this file
PathExt::try_from_bytesPathExt::local_to_wslPathExt::try_shell_safepath_ends_withSanitizedPath::from_arc,new_arc,cast_arc,cast_arc_refRemotePathBuf::from_str,to_protoPathWithPosition::map_pathPathMatcher::is_match_std_pathcompare_rel_pathsHow to verify
cargo test -p moon-util --lib paths_tests