@@ -560,30 +560,41 @@ class YamlEditor {
560560 /// tree is equal to our expectations by deep equality of values. Throws an
561561 /// [AssertionError] if the two trees do not match.
562562 void _performEdit (
563- SourceEdit edit, Iterable <Object ?> path, YamlNode expectedNode) {
563+ SourceEdit edit,
564+ Iterable <Object ?> path,
565+ YamlNode expectedNode,
566+ ) {
564567 final expectedTree = _deepModify (_contents, path, [], expectedNode);
565568 final initialYaml = _yaml;
566- _yaml = edit.apply (_yaml);
569+ final updatedYaml = edit.apply (_yaml);
567570
571+ // Check that the edit does actually parse
572+ final YamlNode actualTree;
568573 try {
569- _initialize ( );
574+ actualTree = withYamlWarningCallback (() => loadYamlNode (updatedYaml) );
570575 } on YamlException {
571576 throw createAssertionError (
572- 'Failed to produce valid YAML after modification.' ,
573- initialYaml,
574- _yaml);
577+ 'Failed to produce valid YAML after modification.' ,
578+ initialYaml,
579+ updatedYaml,
580+ );
575581 }
576582
577- final actualTree = withYamlWarningCallback (() => loadYamlNode (_yaml));
583+ // Check that the edit is semantically correct
578584 if (! deepEquals (actualTree, expectedTree)) {
579585 throw createAssertionError (
580- 'Modification did not result in expected result.' ,
581- initialYaml,
582- _yaml);
586+ 'Modification did not result in expected result.' ,
587+ initialYaml,
588+ updatedYaml,
589+ );
583590 }
584591
592+ // Update state of YamlEditor, when we've validated that the edit was
593+ // semantically correct!
594+ _yaml = updatedYaml;
585595 _contents = actualTree;
586596 _edits.add (edit);
597+ _initialize (); // update tracking of aliases
587598 }
588599
589600 /// Utility method to produce an updated YAML tree equivalent to converting
0 commit comments