Fix source spans for scalars. Closes dart-lang/yaml#13 R=pquitslund@google.com, rnystrom@google.com Review URL: https://codereview.chromium.org//1329183002 .
diff --git a/pkgs/yaml/CHANGELOG.md b/pkgs/yaml/CHANGELOG.md index 6359d97..2dfac86 100644 --- a/pkgs/yaml/CHANGELOG.md +++ b/pkgs/yaml/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.
diff --git a/pkgs/yaml/lib/src/yaml_node.dart b/pkgs/yaml/lib/src/yaml_node.dart index d4961bb..99f7515 100644 --- a/pkgs/yaml/lib/src/yaml_node.dart +++ b/pkgs/yaml/lib/src/yaml_node.dart
@@ -166,7 +166,7 @@ /// 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.
diff --git a/pkgs/yaml/pubspec.yaml b/pkgs/yaml/pubspec.yaml index f6a5b1e..f91d9cf 100644 --- a/pkgs/yaml/pubspec.yaml +++ b/pkgs/yaml/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.
diff --git a/pkgs/yaml/test/yaml_test.dart b/pkgs/yaml/test/yaml_test.dart index 8091dc5..c4601d5 100644 --- a/pkgs/yaml/test/yaml_test.dart +++ b/pkgs/yaml/test/yaml_test.dart
@@ -54,6 +54,43 @@ }); }); + 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