Skip to content

Commit 592fd9c

Browse files
Fix add missing #== overloads for Log::Metadata::Value and YAML::Any
1 parent 743cf3f commit 592fd9c

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

spec/std/log/metadata_spec.cr

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,11 @@ describe Log::Metadata::Value do
128128
it "json" do
129129
v({a: 1}).to_json.should eq(%({"a":1}))
130130
end
131+
132+
describe "#==" do
133+
it "compares with String" do
134+
v("foo").should eq "foo"
135+
"foo".should eq v("foo")
136+
end
137+
end
131138
end

spec/std/yaml/any_spec.cr

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,17 @@ describe YAML::Any do
453453
obj["foo"]["bar"]["baz"][1].as_s.should eq("fox")
454454
end
455455

456-
it "compares to other objects" do
457-
obj = YAML.parse("- foo\n- bar \n")
458-
obj.should eq(%w(foo bar))
459-
obj[0].should eq("foo")
456+
describe "#==" do
457+
it "compares to other objects" do
458+
obj = YAML.parse("- foo\n- bar \n")
459+
obj.should eq(%w(foo bar))
460+
obj[0].should eq("foo")
461+
end
462+
463+
it "compares with Set" do
464+
Set{1, 2, 3}.should eq YAML.parse( "!!set { 1, 2, 3 }")
465+
YAML.parse( "!!set { 1, 2, 3 }").should eq Set{1, 2, 3}
466+
end
460467
end
461468

462469
it "returns array of any when doing parse all" do

src/log/metadata.cr

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,15 @@ class Fiber
231231
@logging_context = value
232232
end
233233
end
234+
235+
class String
236+
def ==(other : Log::Metadata::Value)
237+
other == self
238+
end
239+
end
240+
241+
struct Value
242+
def ==(other : Log::Metadata::Value)
243+
other == self
244+
end
245+
end

src/yaml/any.cr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,12 @@ struct Value
377377
end
378378
end
379379

380+
struct Struct
381+
def ==(other : YAML::Any)
382+
self == other.raw
383+
end
384+
end
385+
380386
class Reference
381387
def ==(other : YAML::Any)
382388
self == other.raw

0 commit comments

Comments
 (0)