mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add tests for change.from
This commit is contained in:
parent
59cf939536
commit
817128b286
2 changed files with 228 additions and 0 deletions
191
spec/matchers/change_from_matcher_spec.cr
Normal file
191
spec/matchers/change_from_matcher_spec.cr
Normal file
|
@ -0,0 +1,191 @@
|
|||
require "../spec_helper"
|
||||
|
||||
describe Spectator::Matchers::ChangeFromMatcher do
|
||||
describe "#match" do
|
||||
context "returned MatchData" do
|
||||
context "with a static expression" do
|
||||
describe "#matched?" do
|
||||
it "is false" do
|
||||
i = 0
|
||||
partial = new_block_partial { i += 0 }
|
||||
matcher = Spectator::Matchers::ChangeFromMatcher.new(i) { i }
|
||||
match_data = matcher.match(partial)
|
||||
match_data.matched?.should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with changing expression" do
|
||||
describe "#matched?" do
|
||||
it "is true" do
|
||||
i = 0
|
||||
partial = new_block_partial { i += 5 }
|
||||
matcher = Spectator::Matchers::ChangeFromMatcher.new(i) { i }
|
||||
match_data = matcher.match(partial)
|
||||
match_data.matched?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe "#values" do
|
||||
context "expected before" do
|
||||
it "is the expected value" do
|
||||
i = 0
|
||||
partial = new_block_partial { i += 5 }
|
||||
matcher = Spectator::Matchers::ChangeFromMatcher.new(0) { i }
|
||||
match_data = matcher.match(partial)
|
||||
match_data_value_with_key(match_data.values, :"expected before").value.should eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
context "actual before" do
|
||||
it "is the initial value" do
|
||||
i = 0
|
||||
partial = new_block_partial { i += 5 }
|
||||
matcher = Spectator::Matchers::ChangeFromMatcher.new(0) { i }
|
||||
match_data = matcher.match(partial)
|
||||
match_data_value_with_key(match_data.values, :"actual before").value.should eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
context "expected after" do
|
||||
it "is the negated initial value" do
|
||||
i = 0
|
||||
partial = new_block_partial { i += 5 }
|
||||
matcher = Spectator::Matchers::ChangeFromMatcher.new(0) { i }
|
||||
match_data = matcher.match(partial)
|
||||
match_data_value_sans_prefix(match_data.values, :"expected after")[:value].should eq(0)
|
||||
match_data_value_sans_prefix(match_data.values, :"expected after")[:to_s].should start_with("Not ")
|
||||
end
|
||||
end
|
||||
|
||||
context "actual after" do
|
||||
it "is the resulting value" do
|
||||
i = 0
|
||||
partial = new_block_partial { i += 5 }
|
||||
matcher = Spectator::Matchers::ChangeFromMatcher.new(0) { i }
|
||||
match_data = matcher.match(partial)
|
||||
match_data_value_with_key(match_data.values, :"actual after").value.should eq(5)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#message" do
|
||||
it "contains the action label" do
|
||||
i = 0
|
||||
label = "ACTION"
|
||||
partial = new_block_partial(label) { i += 5 }
|
||||
matcher = Spectator::Matchers::ChangeFromMatcher.new(i) { i }
|
||||
match_data = matcher.match(partial)
|
||||
match_data.message.should contain(label)
|
||||
end
|
||||
|
||||
it "contains the expression label" do
|
||||
i = 0
|
||||
label = "EXPRESSION"
|
||||
partial = new_block_partial { i += 5 }
|
||||
matcher = Spectator::Matchers::ChangeFromMatcher.new(label, i) { i }
|
||||
match_data = matcher.match(partial)
|
||||
match_data.message.should contain(label)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#negated_message" do
|
||||
it "contains the action label" do
|
||||
i = 0
|
||||
label = "ACTION"
|
||||
partial = new_block_partial(label) { i += 5 }
|
||||
matcher = Spectator::Matchers::ChangeFromMatcher.new(i) { i }
|
||||
match_data = matcher.match(partial)
|
||||
match_data.negated_message.should contain(label)
|
||||
end
|
||||
|
||||
it "contains the expression label" do
|
||||
i = 0
|
||||
label = "EXPRESSION"
|
||||
partial = new_block_partial { i += 5 }
|
||||
matcher = Spectator::Matchers::ChangeFromMatcher.new(label, i) { i }
|
||||
match_data = matcher.match(partial)
|
||||
match_data.negated_message.should contain(label)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with the wrong initial value" do
|
||||
describe "#matched?" do
|
||||
it "is false" do
|
||||
i = 0
|
||||
partial = new_block_partial { i += 5 }
|
||||
matcher = Spectator::Matchers::ChangeFromMatcher.new(2) { i }
|
||||
match_data = matcher.match(partial)
|
||||
match_data.matched?.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe "#values" do
|
||||
context "expected before" do
|
||||
it "is the expected value" do
|
||||
i = 0
|
||||
partial = new_block_partial { i += 5 }
|
||||
matcher = Spectator::Matchers::ChangeFromMatcher.new(2) { i }
|
||||
match_data = matcher.match(partial)
|
||||
match_data_value_with_key(match_data.values, :"expected before").value.should eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
context "actual before" do
|
||||
it "is the initial value" do
|
||||
i = 0
|
||||
partial = new_block_partial { i += 5 }
|
||||
matcher = Spectator::Matchers::ChangeFromMatcher.new(2) { i }
|
||||
match_data = matcher.match(partial)
|
||||
match_data_value_with_key(match_data.values, :"actual before").value.should eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
context "expected after" do
|
||||
it "is the negated initial value" do
|
||||
i = 0
|
||||
partial = new_block_partial { i += 5 }
|
||||
matcher = Spectator::Matchers::ChangeFromMatcher.new(2) { i }
|
||||
match_data = matcher.match(partial)
|
||||
match_data_value_sans_prefix(match_data.values, :"expected after")[:value].should eq(2)
|
||||
match_data_value_sans_prefix(match_data.values, :"expected after")[:to_s].should start_with("Not ")
|
||||
end
|
||||
end
|
||||
|
||||
context "actual after" do
|
||||
it "is the resulting value" do
|
||||
i = 0
|
||||
partial = new_block_partial { i += 5 }
|
||||
matcher = Spectator::Matchers::ChangeFromMatcher.new(2) { i }
|
||||
match_data = matcher.match(partial)
|
||||
match_data_value_with_key(match_data.values, :"actual after").value.should eq(5)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#message" do
|
||||
it "contains the expression label" do
|
||||
i = 0
|
||||
label = "EXPRESSION"
|
||||
partial = new_block_partial { i += 5 }
|
||||
matcher = Spectator::Matchers::ChangeFromMatcher.new(label, 2) { i }
|
||||
match_data = matcher.match(partial)
|
||||
match_data.message.should contain(label)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#negated_message" do
|
||||
it "contains the expression label" do
|
||||
i = 0
|
||||
label = "EXPRESSION"
|
||||
partial = new_block_partial { i += 5 }
|
||||
matcher = Spectator::Matchers::ChangeFromMatcher.new(label, 2) { i }
|
||||
match_data = matcher.match(partial)
|
||||
match_data.negated_message.should contain(label)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,6 +3,18 @@ require "../spec_helper"
|
|||
describe Spectator::Matchers::ChangeMatcher do
|
||||
describe "#match" do
|
||||
context "returned MatchData" do
|
||||
context "with a static expression" do
|
||||
describe "#matched?" do
|
||||
it "is false" do
|
||||
i = 0
|
||||
partial = new_block_partial { i += 0 }
|
||||
matcher = Spectator::Matchers::ChangeMatcher.new { i }
|
||||
match_data = matcher.match(partial)
|
||||
match_data.matched?.should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with changing expression" do
|
||||
describe "#matched?" do
|
||||
it "is true" do
|
||||
|
@ -78,4 +90,29 @@ describe Spectator::Matchers::ChangeMatcher do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#from" do
|
||||
it "returns a ChangeFromMatcher" do
|
||||
i = 0
|
||||
matcher = Spectator::Matchers::ChangeMatcher.new { i }
|
||||
matcher.from(0).should be_a(Spectator::Matchers::ChangeFromMatcher(Int32, Int32))
|
||||
end
|
||||
|
||||
it "passes along the expression" do
|
||||
i = 0
|
||||
partial = new_block_partial { i += 5 }
|
||||
matcher = Spectator::Matchers::ChangeMatcher.new { i }
|
||||
match_data = matcher.from(0).match(partial)
|
||||
i.should eq(5) # Local scope `i` will be updated if the expression (closure) was passed on.
|
||||
end
|
||||
|
||||
it "passes along the label" do
|
||||
i = 0
|
||||
label = "EXPRESSION"
|
||||
partial = new_block_partial { i += 5 }
|
||||
matcher = Spectator::Matchers::ChangeMatcher.new(label) { i }
|
||||
match_data = matcher.from(0).match(partial)
|
||||
match_data.message.should contain(label)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue