Fix YamlEditor.update method leaving trailing spaces at eol (#42)

* Fix for selecting the correct index in insertion

* Add new test cases

* Add more tests and format corrections

* Update `CHANGELOG.md`

* Fix leaving whitespace at eol on YamlEditor.update & update the testcases

* Fix formatting

* Apply proposed change

* Update lib/src/map_mutations.dart

Co-authored-by: Jonas Finnemann Jensen <jopsen@gmail.com>

---------

Co-authored-by: Jonas Finnemann Jensen <jopsen@gmail.com>
9 files changed
tree: d045e5c5925b8d7134ce18e909c338ba6fe18a86
  1. .github/
  2. example/
  3. lib/
  4. test/
  5. .gitignore
  6. analysis_options.yaml
  7. CHANGELOG.md
  8. LICENSE
  9. pubspec.yaml
  10. README.md
README.md

Dart CI pub package package publisher Coverage Status

A library for YAML manipulation while preserving comments.

Usage

A simple usage example:

import 'package:yaml_edit/yaml_edit.dart';

void main() {
  final yamlEditor = YamlEditor('{YAML: YAML}');
  yamlEditor.update(['YAML'], "YAML Ain't Markup Language");
  print(yamlEditor);
  // Expected output:
  // {YAML: YAML Ain't Markup Language}
}

Example: Converting JSON to YAML (block formatted)

void main() {
  final jsonString = r'''
{
  "key": "value",
  "list": [
    "first",
    "second",
    "last entry in the list"
  ],
  "map": {
    "multiline": "this is a fairly long string with\nline breaks..."
  }
}
''';
  final jsonValue = json.decode(jsonString);

  // Convert jsonValue to YAML
  final yamlEditor = YamlEditor('');
  yamlEditor.update([], jsonValue);
  print(yamlEditor.toString());
}

Testing

Testing is done in two strategies: Unit testing (/test/editor_test.dart) and Golden testing (/test/golden_test.dart). More information on Golden testing and the input/output format can be found at /test/testdata/README.md.

These tests are automatically run with pub run test.

Limitations

  1. Users are not allowed to define tags in the modifications.
  2. Map keys will always be added in the flow style.