mirror of
https://gitea.invidious.io/iv-org/shard-radix.git
synced 2024-08-15 00:43:21 +00:00
No longer expose internal functionality used only in tests. Reduce the exposed elements of `Radix::Result` to focus on payload only. Also remove the associated array used to collect all the traversed nodes when performing the lookup. NOTE: this is a breaking change
45 lines
1.1 KiB
Crystal
45 lines
1.1 KiB
Crystal
require "../spec_helper"
|
|
|
|
module Radix
|
|
describe Result do
|
|
describe "#found?" do
|
|
context "a new instance" do
|
|
it "returns false when no payload is associated" do
|
|
result = Result(Nil).new
|
|
result.found?.should be_false
|
|
end
|
|
end
|
|
|
|
context "with a payload" do
|
|
it "returns true" do
|
|
node = Node(Symbol).new("/", :root)
|
|
result = Result(Symbol).new
|
|
result.use node
|
|
|
|
result.found?.should be_true
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "#use" do
|
|
it "uses the node payload" do
|
|
node = Node(Symbol).new("/", :root)
|
|
result = Result(Symbol).new
|
|
result.payload?.should be_falsey
|
|
|
|
result.use node
|
|
result.payload?.should be_truthy
|
|
result.payload.should eq(node.payload)
|
|
end
|
|
|
|
it "allow not to assign payload" do
|
|
node = Node(Symbol).new("/", :root)
|
|
result = Result(Symbol).new
|
|
result.payload?.should be_falsey
|
|
|
|
result.use node, payload: false
|
|
result.payload?.should be_falsey
|
|
end
|
|
end
|
|
end
|
|
end
|