diff --git a/spec/std/log/metadata_spec.cr b/spec/std/log/metadata_spec.cr index 884a4f9e2898..ba0b9c1a616d 100644 --- a/spec/std/log/metadata_spec.cr +++ b/spec/std/log/metadata_spec.cr @@ -28,6 +28,14 @@ describe Log::Metadata do m({a: 1}).extend({} of Symbol => String).should_not be_empty end + describe "#dup" do + it "creates a shallow copy" do + Log::Metadata.empty.dup.should eq(Log::Metadata.empty) + m({a: 1}).dup.should eq(m({a: 1})) + m({a: 1, b: 3}).dup.should eq(m({a: 1, b: 3})) + end + end + it "extend" do m({a: 1}).extend({b: 2}).should eq(m({a: 1, b: 2})) m({a: 1, b: 3}).extend({b: 2}).should eq(m({a: 1, b: 2})) diff --git a/src/log/metadata.cr b/src/log/metadata.cr index 258b1b817c52..b1ea8ae38fa9 100644 --- a/src/log/metadata.cr +++ b/src/log/metadata.cr @@ -37,6 +37,10 @@ class Log::Metadata data end + def dup : self + self + end + protected def setup(@parent : Metadata?, entries : NamedTuple | Hash) @size = @overridden_size = entries.size @max_total_size = @size + (@parent.try(&.max_total_size) || 0)