blob: 09e461cabc1c6cf2d49cfab791586c996cc648bb [file] [log] [blame]
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:convert';
import 'package:source_span/source_span.dart';
import 'package:test/test.dart';
import 'package:yaml/yaml.dart';
void main() {
YamlMap yaml;
setUpAll(() {
yaml = loadYaml(const JsonEncoder.withIndent(' ').convert({
'num': 42,
'nested': {
'null': null,
'num': 42,
},
'null': null,
})) as YamlMap;
});
test('first root key', () {
_expectSpan(
yaml.nodes['num'].span,
r'''
2 │ "num": 42,
│ ^^
╵''',
);
});
test('first root key', () {
_expectSpan(
yaml.nodes['null'].span,
r'''
7 │ "null": null
│ ^^^^
╵''',
);
});
group('nested', () {
YamlMap nestedMap;
setUpAll(() {
nestedMap = yaml.nodes['nested'] as YamlMap;
});
test('first root key', () {
_expectSpan(
nestedMap.nodes['null'].span,
r'''
4 │ "null": null,
│ ^^^^
╵''',
);
});
test('first root key', () {
_expectSpan(
nestedMap.nodes['num'].span,
r'''
5 │ "num": 42
│ ^^
╵''',
);
});
});
}
void _expectSpan(SourceSpan source, String expected) {
expect(source.highlight(), expected);
}