Skip to content

Commit

Permalink
Fix source spans for scalars.
Browse files Browse the repository at this point in the history
Closes #13

R=pquitslund@google.com, rnystrom@google.com

Review URL: https://codereview.chromium.org//1329183002 .
  • Loading branch information
nex3 committed Sep 9, 2015
1 parent 445e54e commit 7bf5103
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,8 @@
## 2.1.5

* Fix a bug with 2.1.4 where source span information was being discarded for
scalar values.

## 2.1.4

* Substantially improve performance.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/yaml_node.dart
Expand Up @@ -166,7 +166,7 @@ class YamlScalar extends YamlNode {
/// Users of the library should not use this constructor.
YamlScalar.internal(this.value, ScalarEvent scalar)
: style = scalar.style {
_span = span;
_span = scalar.span;
}

/// Users of the library should not use this constructor.
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
@@ -1,5 +1,5 @@
name: yaml
version: 2.1.4
version: 2.1.5
author: "Dart Team <misc@dartlang.org>"
homepage: https://github.com/dart-lang/yaml
description: A parser for YAML.
Expand Down
37 changes: 37 additions & 0 deletions test/yaml_test.dart
Expand Up @@ -54,6 +54,43 @@ main() {
});
});

test("includes source span information", () {
var yaml = loadYamlNode(r"""
- foo:
bar
- 123
""");

expect(yaml.span.start.line, equals(0));
expect(yaml.span.start.column, equals(0));
expect(yaml.span.end.line, equals(3));
expect(yaml.span.end.column, equals(0));

var map = yaml.nodes.first;
expect(map.span.start.line, equals(0));
expect(map.span.start.column, equals(2));
expect(map.span.end.line, equals(2));
expect(map.span.end.column, equals(0));

var key = map.nodes.keys.first;
expect(key.span.start.line, equals(0));
expect(key.span.start.column, equals(2));
expect(key.span.end.line, equals(0));
expect(key.span.end.column, equals(5));

var value = map.nodes.values.first;
expect(value.span.start.line, equals(1));
expect(value.span.start.column, equals(4));
expect(value.span.end.line, equals(1));
expect(value.span.end.column, equals(7));

var scalar = yaml.nodes.last;
expect(scalar.span.start.line, equals(2));
expect(scalar.span.start.column, equals(2));
expect(scalar.span.end.line, equals(2));
expect(scalar.span.end.column, equals(5));
});

// The following tests are all taken directly from the YAML spec
// (http://www.yaml.org/spec/1.2/spec.html). Most of them are code examples
// that are directly included in the spec, but additional tests are derived
Expand Down

0 comments on commit 7bf5103

Please sign in to comment.