| // Copyright 2020 Garett Tok Ern Liang |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // https://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| import 'package:yaml_edit/yaml_edit.dart'; |
| import 'package:test/test.dart'; |
| |
| void main() { |
| group('YamlEditor records edits', () { |
| test('returns empty list at start', () { |
| final yamlEditor = YamlEditor('YAML: YAML'); |
| |
| expect(yamlEditor.edits, []); |
| }); |
| |
| test('after one change', () { |
| final yamlEditor = YamlEditor('YAML: YAML'); |
| yamlEditor.update(['YAML'], "YAML Ain't Markup Language"); |
| |
| expect( |
| yamlEditor.edits, [SourceEdit(5, 5, " YAML Ain't Markup Language")]); |
| }); |
| |
| test('after multiple changes', () { |
| final yamlEditor = YamlEditor('YAML: YAML'); |
| yamlEditor.update(['YAML'], "YAML Ain't Markup Language"); |
| yamlEditor.update(['XML'], 'Extensible Markup Language'); |
| yamlEditor.remove(['YAML']); |
| |
| expect(yamlEditor.edits, [ |
| SourceEdit(5, 5, " YAML Ain't Markup Language"), |
| SourceEdit(0, 0, 'XML: Extensible Markup Language\n'), |
| SourceEdit(32, 32, '') |
| ]); |
| }); |
| |
| test('that do not automatically update with internal list', () { |
| final yamlEditor = YamlEditor('YAML: YAML'); |
| yamlEditor.update(['YAML'], "YAML Ain't Markup Language"); |
| |
| final firstEdits = yamlEditor.edits; |
| |
| expect(firstEdits, [SourceEdit(5, 5, " YAML Ain't Markup Language")]); |
| |
| yamlEditor.update(['XML'], 'Extensible Markup Language'); |
| yamlEditor.remove(['YAML']); |
| |
| expect(firstEdits, [SourceEdit(5, 5, " YAML Ain't Markup Language")]); |
| expect(yamlEditor.edits, [ |
| SourceEdit(5, 5, " YAML Ain't Markup Language"), |
| SourceEdit(0, 0, 'XML: Extensible Markup Language\n'), |
| SourceEdit(32, 32, '') |
| ]); |
| }); |
| }); |
| } |