Fix splice list insertion (#84)

* Fix spliceList error for nested lists

* Fix list indentation calculation

* Add golden tests for spliceList

* Remove skip flag on test added in 8cc8580

* Add missing line at end of file

* Add spliceList tests

* Skip random test that fails (20th iteration)

* Add deeply nested input in golden tests for spliceList

* Fix formatting to account for space in nested list

* Add golden tests for weird spaces in nested list

* Run dart format

* Update `_formatNewBlock` to return indent size instead of the indent

* Update test/testdata/input/splice_list_in_nested_block_with_weird_spaces.test

---------

Co-authored-by: Jonas Finnemann Jensen <jopsen@gmail.com>
10 files changed
tree: d3a7a73e5c489285fb7d23e6f919caf92c3a2c2a
  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.