mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Implement arguments case equality
Implements https://github.com/icy-arctic-fox/spectator/issues/47 Some specs are failing and need to be resolved before the new feature is considered done.
This commit is contained in:
parent
0177a678f9
commit
e2130d12d3
3 changed files with 205 additions and 65 deletions
|
@ -11,7 +11,7 @@ Spectator.describe "GitHub Issue #47" do
|
|||
|
||||
let(fake) { mock(Original) }
|
||||
|
||||
xspecify do
|
||||
specify do
|
||||
expect(fake).to receive(:foo).with("arg1", arg2: "arg2")
|
||||
fake.foo("arg1", "arg2")
|
||||
end
|
||||
|
|
|
@ -20,18 +20,61 @@ Spectator.describe Spectator::Arguments do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#[]" do
|
||||
context "with an index" do
|
||||
describe "#[](index)" do
|
||||
it "returns a positional argument" do
|
||||
aggregate_failures do
|
||||
expect(arguments[0]).to eq(42)
|
||||
expect(arguments[1]).to eq("foo")
|
||||
end
|
||||
end
|
||||
|
||||
it "returns splat arguments" do
|
||||
aggregate_failures do
|
||||
expect(arguments[2]).to eq(:x)
|
||||
expect(arguments[3]).to eq(:y)
|
||||
expect(arguments[4]).to eq(:z)
|
||||
end
|
||||
end
|
||||
|
||||
context "with named positional arguments" do
|
||||
subject(arguments) { Spectator::Arguments.new({arg1: 42, arg2: "foo"}, :splat, {:x, :y, :z}, {bar: "baz", qux: 123}) }
|
||||
|
||||
it "returns a positional argument" do
|
||||
aggregate_failures do
|
||||
expect(arguments[0]).to eq(42)
|
||||
expect(arguments[1]).to eq("foo")
|
||||
end
|
||||
end
|
||||
|
||||
it "returns splat arguments" do
|
||||
aggregate_failures do
|
||||
expect(arguments[2]).to eq(:x)
|
||||
expect(arguments[3]).to eq(:y)
|
||||
expect(arguments[4]).to eq(:z)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#[](symbol)" do
|
||||
it "returns a keyword argument" do
|
||||
aggregate_failures do
|
||||
expect(arguments[:bar]).to eq("baz")
|
||||
expect(arguments[:qux]).to eq(123)
|
||||
end
|
||||
end
|
||||
|
||||
context "with a symbol" do
|
||||
it "returns a named argument" do
|
||||
context "with named positional arguments" do
|
||||
subject(arguments) { Spectator::Arguments.new({arg1: 42, arg2: "foo"}, :splat, {:x, :y, :z}, {bar: "baz", qux: 123}) }
|
||||
|
||||
it "returns a positional argument" do
|
||||
aggregate_failures do
|
||||
expect(arguments[:arg1]).to eq(42)
|
||||
expect(arguments[:arg2]).to eq("foo")
|
||||
end
|
||||
end
|
||||
|
||||
it "returns a keyword argument" do
|
||||
aggregate_failures do
|
||||
expect(arguments[:bar]).to eq("baz")
|
||||
expect(arguments[:qux]).to eq(123)
|
||||
|
@ -62,33 +105,57 @@ Spectator.describe Spectator::Arguments do
|
|||
context "with equal arguments" do
|
||||
let(other) { arguments }
|
||||
|
||||
it "returns true" do
|
||||
is_expected.to be_true
|
||||
end
|
||||
it { is_expected.to be_true }
|
||||
end
|
||||
|
||||
context "with different arguments" do
|
||||
let(other) { Spectator::Arguments.new({123, :foo, "bar"}, nil, nil, {opt: "foobar"}) }
|
||||
let(other) { Spectator::Arguments.new({123, :foo, "bar"}, :splat, {1, 2, 3}, {opt: "foobar"}) }
|
||||
|
||||
it "returns false" do
|
||||
is_expected.to be_false
|
||||
end
|
||||
it { is_expected.to be_false }
|
||||
end
|
||||
|
||||
context "with the same kwargs in a different order" do
|
||||
let(other) { Spectator::Arguments.new(arguments.args, nil, nil, {qux: 123, bar: "baz"}) }
|
||||
let(other) { Spectator::Arguments.new(arguments.args, arguments.splat_name, arguments.splat, {qux: 123, bar: "baz"}) }
|
||||
|
||||
it "returns true" do
|
||||
is_expected.to be_true
|
||||
end
|
||||
it { is_expected.to be_true }
|
||||
end
|
||||
|
||||
context "with a missing kwarg" do
|
||||
let(other) { Spectator::Arguments.new(arguments.args, nil, nil, {bar: "baz"}) }
|
||||
let(other) { Spectator::Arguments.new(arguments.args, arguments.splat_name, arguments.splat, {bar: "baz"}) }
|
||||
|
||||
it "returns false" do
|
||||
is_expected.to be_false
|
||||
end
|
||||
it { is_expected.to be_false }
|
||||
end
|
||||
|
||||
context "with an extra kwarg" do
|
||||
let(other) { Spectator::Arguments.new(arguments.args, arguments.splat_name, arguments.splat, {bar: "baz", qux: 123, extra: 0}) }
|
||||
|
||||
it { is_expected.to be_false }
|
||||
end
|
||||
|
||||
context "with different splat arguments" do
|
||||
let(other) { Spectator::Arguments.new(arguments.args, arguments.splat_name, {1, 2, 3}, arguments.kwargs) }
|
||||
|
||||
it { is_expected.to be_false }
|
||||
end
|
||||
|
||||
context "with mixed positional tuple types" do
|
||||
let(other) { Spectator::Arguments.new({arg1: 42, arg2: "foo"}, arguments.splat_name, arguments.splat, arguments.kwargs) }
|
||||
|
||||
it { is_expected.to be_true }
|
||||
end
|
||||
|
||||
context "with mixed positional tuple types (flipped)" do
|
||||
let(arguments) { Spectator::Arguments.new({arg1: 42, arg2: "foo"}, :splat, {:x, :y, :z}, {bar: "baz", qux: 123}) }
|
||||
let(other) { Spectator::Arguments.new({42, "foo"}, :splat, {:x, :y, :z}, {bar: "baz", qux: 123}) }
|
||||
|
||||
it { is_expected.to be_true }
|
||||
end
|
||||
|
||||
context "with args spilling over into splat and mixed positional tuple types" do
|
||||
let(arguments) { Spectator::Arguments.new({arg1: 42, arg2: "foo"}, :splat, {:x, :y, :z}, {bar: "baz", qux: 123}) }
|
||||
let(other) { Spectator::Arguments.new({42, "foo", :x, :y, :z}, nil, nil, {bar: "baz", qux: 123}) }
|
||||
|
||||
it { is_expected.to be_true }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -98,49 +165,96 @@ Spectator.describe Spectator::Arguments do
|
|||
context "with equal arguments" do
|
||||
let(pattern) { arguments }
|
||||
|
||||
it "returns true" do
|
||||
is_expected.to be_true
|
||||
end
|
||||
it { is_expected.to be_true }
|
||||
end
|
||||
|
||||
context "with matching arguments" do
|
||||
let(pattern) { Spectator::Arguments.new({Int32, /foo/}, :splat, {Symbol, Symbol, :z}, {bar: /baz/, qux: Int32}) }
|
||||
|
||||
it { is_expected.to be_true }
|
||||
end
|
||||
|
||||
context "with non-matching arguments" do
|
||||
let(pattern) { Spectator::Arguments.new({Float64, /bar/}, :splat, {String, Int32, :x}, {bar: /foo/, qux: "123"}) }
|
||||
|
||||
it { is_expected.to be_false }
|
||||
end
|
||||
|
||||
context "with different arguments" do
|
||||
let(pattern) { Spectator::Arguments.new({123, :foo, "bar"}, nil, nil, {opt: "foobar"}) }
|
||||
let(pattern) { Spectator::Arguments.new({123, :foo, "bar"}, :splat, {1, 2, 3}, {opt: "foobar"}) }
|
||||
|
||||
it "returns false" do
|
||||
is_expected.to be_false
|
||||
end
|
||||
it { is_expected.to be_false }
|
||||
end
|
||||
|
||||
context "with the same kwargs in a different order" do
|
||||
let(pattern) { Spectator::Arguments.new(arguments.args, nil, nil, {qux: 123, bar: "baz"}) }
|
||||
let(pattern) { Spectator::Arguments.new(arguments.args, arguments.splat_name, arguments.splat, {qux: Int32, bar: /baz/}) }
|
||||
|
||||
it "returns true" do
|
||||
is_expected.to be_true
|
||||
end
|
||||
it { is_expected.to be_true }
|
||||
end
|
||||
|
||||
context "with an additional kwarg" do
|
||||
let(pattern) { Spectator::Arguments.new(arguments.args, arguments.splat_name, arguments.splat, {bar: /baz/}) }
|
||||
|
||||
it { is_expected.to be_true }
|
||||
end
|
||||
|
||||
context "with a missing kwarg" do
|
||||
let(pattern) { Spectator::Arguments.new(arguments.args, nil, nil, {bar: "baz"}) }
|
||||
let(pattern) { Spectator::Arguments.new(arguments.args, arguments.splat_name, arguments.splat, {bar: /baz/, qux: Int32, extra: 0}) }
|
||||
|
||||
it "returns false" do
|
||||
is_expected.to be_false
|
||||
end
|
||||
it { is_expected.to be_false }
|
||||
end
|
||||
|
||||
context "with matching types and regex" do
|
||||
let(pattern) { Spectator::Arguments.new({Int32, /foo/}, nil, nil, {bar: String, qux: 123}) }
|
||||
context "with different splat arguments" do
|
||||
let(pattern) { Spectator::Arguments.new(arguments.args, arguments.splat_name, {1, 2, 3}, arguments.kwargs) }
|
||||
|
||||
it "returns true" do
|
||||
is_expected.to be_true
|
||||
end
|
||||
it { is_expected.to be_false }
|
||||
end
|
||||
|
||||
context "with different types and regex" do
|
||||
let(pattern) { Spectator::Arguments.new({Symbol, /bar/}, nil, nil, {bar: String, qux: 42}) }
|
||||
context "with matching mixed positional tuple types" do
|
||||
let(pattern) { Spectator::Arguments.new({arg1: Int32, arg2: /foo/}, arguments.splat_name, arguments.splat, arguments.kwargs) }
|
||||
|
||||
it "returns false" do
|
||||
is_expected.to be_false
|
||||
end
|
||||
it { is_expected.to be_true }
|
||||
end
|
||||
|
||||
context "with non-matching mixed positional tuple types" do
|
||||
let(pattern) { Spectator::Arguments.new({arg1: Float64, arg2: /bar/}, arguments.splat_name, arguments.splat, arguments.kwargs) }
|
||||
|
||||
it { is_expected.to be_false }
|
||||
end
|
||||
|
||||
context "with matching args spilling over into splat and mixed positional tuple types" do
|
||||
let(arguments) { Spectator::Arguments.new({arg1: 42, arg2: "foo"}, :splat, {:x, :y, :z}, {bar: "baz", qux: 123}) }
|
||||
let(pattern) { Spectator::Arguments.capture(Int32, /foo/, Symbol, Symbol, :z, bar: /baz/, qux: Int32) }
|
||||
|
||||
it { is_expected.to be_true }
|
||||
end
|
||||
|
||||
context "with non-matching args spilling over into splat and mixed positional tuple types" do
|
||||
let(arguments) { Spectator::Arguments.new({arg1: 42, arg2: "foo"}, :splat, {:x, :y, :z}, {bar: "baz", qux: 123}) }
|
||||
let(pattern) { Spectator::Arguments.capture(Float64, /bar/, Symbol, String, :z, bar: /foo/, qux: Int32) }
|
||||
|
||||
it { is_expected.to be_false }
|
||||
end
|
||||
|
||||
context "with matching mixed named positional and keyword arguments" do
|
||||
let(arguments) { Spectator::Arguments.new({arg1: 42, arg2: "foo"}, :splat, {:x, :y, :z}, {bar: "baz", qux: 123}) }
|
||||
let(pattern) { Spectator::Arguments.capture(/foo/, Symbol, :y, Symbol, arg1: Int32, bar: /baz/, qux: 123) }
|
||||
|
||||
it { is_expected.to be_true }
|
||||
end
|
||||
|
||||
context "with non-matching mixed named positional and keyword arguments" do
|
||||
let(arguments) { Spectator::Arguments.new({arg1: 42, arg2: "foo"}, :splat, {:x, :y, :z}, {bar: "baz", qux: 123}) }
|
||||
let(pattern) { Spectator::Arguments.capture(5, Symbol, :z, Symbol, arg2: /foo/, bar: /baz/, qux: Int32) }
|
||||
|
||||
it { is_expected.to be_false }
|
||||
end
|
||||
|
||||
context "with non-matching mixed named positional and keyword arguments" do
|
||||
let(arguments) { Spectator::Arguments.new({arg1: 42, arg2: "foo"}, :splat, {:x, :y, :z}, {bar: "baz", qux: 123}) }
|
||||
let(pattern) { Spectator::Arguments.capture(/bar/, String, :y, Symbol, arg1: 0, bar: /foo/, qux: Float64) }
|
||||
|
||||
it { is_expected.to be_false }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue