Skip to content

Commit

Permalink
move spec
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil committed Feb 6, 2024
1 parent f2b7294 commit f76db6e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 42 deletions.
41 changes: 0 additions & 41 deletions spec/primitives/object_spec.cr

This file was deleted.

36 changes: 35 additions & 1 deletion spec/std/object_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ private class StringWrapper
end
end

private EQ_OPERATORS = %w(<= >= == != []= ===)

private class TestObject
getter getter1
getter getter2 : Int32
Expand Down Expand Up @@ -113,6 +115,19 @@ private class TestObject
{key, value}
end

# NOTE: these methods are a syntax error in older versions
{% if compare_versions(Crystal::VERSION, "1.12.0-dev") >= 0 %}
{% for op in EQ_OPERATORS %}
def {{ op.id }}(*args, **opts)
[args, opts]
end

def {{ op.id }}(*args, **opts, &)
[args, opts, yield]
end
{% end %}
{% end %}

annotation TestAnnotation
end

Expand All @@ -130,7 +145,10 @@ end

private class DelegatedTestObject
delegate :property1=, to: @test_object
delegate :[]=, to: @test_object

{% for op in EQ_OPERATORS %}
delegate {{ op.id.symbolize }}, to: @test_object
{% end %}

def initialize(@test_object : TestObject)
end
Expand Down Expand Up @@ -206,6 +224,22 @@ describe Object do
delegated = DelegatedTestObject.new(test_object)
(delegated["foo"] = "bar").should eq({"foo", "bar"})
end

{% if compare_versions(Crystal::VERSION, "1.12.0-dev") >= 0 %}
{% for op in EQ_OPERATORS %}
it "forwards \#{{ op.id }} with multiple parameters" do
test_object = TestObject.new
delegated = DelegatedTestObject.new(test_object)
delegated.{{ op.id }}(1, 2, a: 3, b: 4).should eq [{1, 2}, {a: 3, b: 4}]
end

it "forwards \#{{ op.id }} with multiple parameters and block parameter" do
test_object = TestObject.new
delegated = DelegatedTestObject.new(test_object)
delegated.{{ op.id }}(1, 2, a: 3, b: 4) { 5 }.should eq [{1, 2}, {a: 3, b: 4}, 5]
end
{% end %}
{% end %}
end

describe "getter" do
Expand Down

0 comments on commit f76db6e

Please sign in to comment.