Skip to content

Commit

Permalink
Use adjacent_sibling instead of sibling (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
ypconstante authored Feb 20, 2024
1 parent b66034f commit 10a9824
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/floki/finder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ defmodule Floki.Finder do
Enum.reverse(html_node.children_nodes_ids)
end

defp get_selector_nodes(%Selector.Combinator{match_type: :sibling}, html_node, tree) do
defp get_selector_nodes(%Selector.Combinator{match_type: :adjacent_sibling}, html_node, tree) do
case get_siblings(html_node, tree) do
[sibling_id | _] -> [sibling_id]
_ -> []
Expand Down
2 changes: 1 addition & 1 deletion lib/floki/selector/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ defmodule Floki.Selector.Parser do
end

defp do_parse([{:plus, _} | t], selector) do
{remaining_tokens, combinator} = consume_combinator(t, :sibling)
{remaining_tokens, combinator} = consume_combinator(t, :adjacent_sibling)

{%{selector | combinator: combinator}, remaining_tokens}
end
Expand Down
4 changes: 2 additions & 2 deletions test/floki_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,9 +1009,9 @@ defmodule FlokiTest do
assert_find(html, "div > p > span > img + img", expected)
end

# Floki.find/2 - Sibling combinator
# Floki.find/2 - Adjacent sibling combinator

test "find sibling element" do
test "find adjacent sibling element" do
html = document!(html_body(~s(
<a href="t"><img src="/l.png" class="js-l"></a>
<!-- comment -->
Expand Down

0 comments on commit 10a9824

Please sign in to comment.