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
38 changes: 38 additions & 0 deletions spec/std/yaml/nodes/parser_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require "yaml"
require "spec"

describe YAML::Nodes do
describe ".parse" do
it "attaches location to scalar nodes" do
doc = YAML::Nodes.parse %(1)
node = doc.nodes[0]
node.location.should eq({1, 1})
node.end_line.should eq(1)
node.end_column.should eq(2)
end

it "attaches location to sequence nodes" do
doc = YAML::Nodes.parse %([1])
node = doc.nodes[0]
node.location.should eq({1, 1})
node.end_line.should eq(1)
node.end_column.should eq(4)
end

it "attaches location to mapping nodes" do
doc = YAML::Nodes.parse %({"a":1})
node = doc.nodes[0]
node.location.should eq({1, 1})
node.end_line.should eq(1)
node.end_column.should eq(8)
end

it "attaches location to alias nodes" do
doc = YAML::Nodes.parse %([&a 1, *a])
node = doc.nodes[0].as(YAML::Nodes::Sequence).nodes[1]
node.location.should eq({1, 8})
node.end_line.should eq(1)
node.end_column.should eq(10)
end
end
end
2 changes: 2 additions & 0 deletions src/yaml/parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,14 @@ abstract class YAML::Parser

protected def parse_scalar
value = anchor(@pull_parser.anchor, new_scalar)
end_value(value)
@pull_parser.read_next
value
end

protected def parse_alias
value = get_anchor(@pull_parser.anchor.not_nil!)
end_value(value)
@pull_parser.read_next
value
end
Expand Down