Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Zipper] Fix search_pattern/2 and move_to_cursor/2 #172

Merged
merged 2 commits into from
Nov 1, 2024

Conversation

zachallaun
Copy link
Contributor

I found a shared issue with search_pattern/2 and move_to_cursor/2: When __cursor__() was found, both functions would stop matching, so you'd get a positive result even if other elements of the pattern do not match:

iex(1)> alias Sourceror.Zipper, as: Z
Sourceror.Zipper

iex(2)> zipper = "[[[:foo], :bar], :baz]" |> Sourceror.parse_string!() |> Z.zip()
#Sourceror.Zipper<
  #root
  {:__block__, [...], [...]}
>

iex(3)> Z.search_pattern(zipper, "[__cursor__(), :qux]")
#Sourceror.Zipper<
  {:__block__, [...],
   [
     [{:__block__, [...], [[{:__block__, [...], [:foo]}]]},
      {:__block__, [...], [:bar]}]
   ]}
  #...
>

iex(4)> Z.move_to_cursor(zipper, "[[__cursor__(), :bar], :qux]")
#Sourceror.Zipper<
  {:__block__, [...],
   [[{:__block__, [...], [:foo]}]]}
  #...
>

This PR fixes that issue and improves the documentation and tests.

The function is readable as-is
Copy link
Owner

@doorgan doorgan left a comment

Choose a reason for hiding this comment

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

Thanks for the fix and the docs improvements!

@doorgan doorgan merged commit cb99192 into doorgan:main Nov 1, 2024
6 checks passed
@zachallaun zachallaun deleted the za-search-pattern-fix branch November 1, 2024 17:00
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