Fix incorrect lookup on non-shared partial keys

Given the following nodes in a tree:

    # ( 8) /product
    # ( 4)         /new
    # ( 1)         s
    tree = Radix::Tree(Symbol).new
    tree.add "/products", :products
    tree.add "/product/new", :product_new

It failed to properly identify `/products` during lookup:

    result = tree.find "/products"
    result.found? # => false

Caused by incorrect comparsion of `s` remaining path against `/new`
node instead of continue comparison with the next one.

Fixes #21
This commit is contained in:
Luis Lavena 2017-03-12 12:36:05 -03:00
parent b81ac70758
commit 9895655a8a
3 changed files with 19 additions and 0 deletions

View file

@ -323,6 +323,17 @@ module Radix
result.payload.should eq(:abc)
end
it "finds matching path across separator" do
tree = Tree(Symbol).new
tree.add "/products", :products
tree.add "/product/new", :product_new
result = tree.find("/products")
result.found?.should be_true
result.key.should eq("/products")
result.payload.should eq(:products)
end
it "finds matching path across parents" do
tree = Tree(Symbol).new
tree.add "/", :root