Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/psych/comments/node_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ def leading_comments
def trailing_comments
@trailing_comments ||= []
end

def leading_comments=(comments)
@leading_comments = Array(comments)
end

def trailing_comments=(comments)
@trailing_comments = Array(comments)
end
end
24 changes: 24 additions & 0 deletions spec/node_ext_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,36 @@
node = Psych::Nodes::Scalar.new("foo")
expect(node.leading_comments).to eq([])
end

it "can be set with an array of comments" do
node = Psych::Nodes::Scalar.new("foo")
node.leading_comments = ["# Comment 1", "# Comment 2"]
expect(node.leading_comments).to eq(["# Comment 1", "# Comment 2"])
end

it "wraps non-array values in an array" do
node = Psych::Nodes::Scalar.new("foo")
node.leading_comments = "# Single comment"
expect(node.leading_comments).to eq(["# Single comment"])
end
end

describe "#trailing_comments" do
it "has an array" do
node = Psych::Nodes::Scalar.new("foo")
expect(node.trailing_comments).to eq([])
end

it "can be set with an array of comments" do
node = Psych::Nodes::Scalar.new("foo")
node.trailing_comments = ["# Comment 1", "# Comment 2"]
expect(node.trailing_comments).to eq(["# Comment 1", "# Comment 2"])
end

it "wraps non-array values in an array" do
node = Psych::Nodes::Scalar.new("foo")
node.trailing_comments = "# Single comment"
expect(node.trailing_comments).to eq(["# Single comment"])
end
end
end