Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add the ability to update leading and trailing comments #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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