The following results in an Unhandled Exception "Assertion failed: (package:yaml_edit) Modification did not result in expected result."
import 'dart:io';
import 'package:yaml_edit/yaml_edit.dart';
Future<void> main() async {
YamlEditor yamlEditorFile =
YamlEditor(File('test/gh_test.yml').readAsStringSync());
try {
// yamlEditorFile.insertIntoList(
// ['school'],
// 3,
// {
// 'student': {'first_name': 'Henry', 'last_name': 'Smith'}
// });
yamlEditorFile.appendToList([
'school'
], {
'student': {'first_name': 'Henry', 'last_name': 'Smith'}
});
} on Exception catch (e) {
print(e);
}
print(yamlEditorFile);
}
gh_test.yml is:
# comment
school:
- student:
first_name: Harry
last_name: "Reynolds"
- student:
first_name: "Sally"
last_name: Rheims
- student:
first_name: "George"
last_name: "Silver"
teachers:
- english:
name: "Johnson"
- science:
name: "Smith"
The insertIntoList call results in the same if the index is the next one (i.e., 3 - commented code in example above).
Expected behavior in all cases is that it inserts it correctly in the school list after student George Silver.
Instead the result in both examples is that the inserted list item (Henry Smith) is inserted incorrectly as the first item of the next list (i.e., teachers) as shown by the "Modification did not result in expected result" message.":
> teachers:
> - student:
> first_name: Henry
> last_name: Smith
> - english:
> name: "Johnson"
> - science:
> name: "Smith"
the full error message:
Unhandled exception:
Assertion failed: (package:yaml_edit) Modification did not result in expected result.
# YAML before edit:
> # comment
> school:
> - student:
> first_name: Harry
> last_name: "Reynolds"
> - student:
> first_name: "Sally"
> last_name: Rheims
> - student:
> first_name: "George"
> last_name: "Silver"
> teachers:
> - english:
> name: "Johnson"
> - science:
> name: "Smith"
# YAML after edit:
> # comment
> school:
> - student:
> first_name: Harry
> last_name: "Reynolds"
> - student:
> first_name: "Sally"
> last_name: Rheims
> - student:
> first_name: "George"
> last_name: "Silver"
> teachers:
> - student:
> first_name: Henry
> last_name: Smith
> - english:
> name: "Johnson"
> - science:
> name: "Smith"
Please file an issue at:
https://github.com/google/dart-neats/issues/new?labels=pkg%3Ayaml_edit%2C+pending-triage&template=yaml_edit.md
#0 YamlEditor._performEdit
#1 YamlEditor.insertIntoList
#2 YamlEditor.appendToList
#3 main
#4 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
#5 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)
Exited (255)
So it appears it can't detect the end of the list. The example yaml is correctly validated. If I insert a non-list in between the two lists in the example yaml file, for example the boolean "public: false", I get "Mapping Values are not allowed here" as it attempts to insert it under the boolean yaml:
Here's that error message:
Error on line 13, column 12: Mapping values are not allowed here. Did you miss a colon earlier?
╷
13 │ - student:
│ ^
╵
# comment
school:
- student:
first_name: Harry
last_name: "Reynolds"
- student:
first_name: "Sally"
last_name: Rheims
- student:
first_name: "George"
last_name: "Silver"
public: false
- student:
first_name: Henry
last_name: Smith
teachers:
- english:
name: "Johnson"
- science:
name: "Smith"
Exited
bug