diff --git a/test/regression_test.dart b/test/regression_test.dart index ad873b6..33f06f3 100644 --- a/test/regression_test.dart +++ b/test/regression_test.dart @@ -1,5 +1,6 @@ import 'package:test/test.dart'; import 'package:xml/xml.dart'; +import 'package:xml/xml_events.dart'; import 'utils/assertions.dart'; @@ -249,4 +250,32 @@ void main() { ''); expect(expected.toXmlString(), actual.toXmlString()); }); + group('https://github.com/renggli/dart-xml/discussions/177', () { + const input = 'ab'; + test('iterable', () { + var started = false; + final found = []; + for (final event in parseEvents(input)) { + if (event is XmlStartElementEvent && event.name == 'item') { + started = true; + } else if (event is XmlEndElementEvent && event.name == 'item') { + started = false; + } else if (started) { + found.add(event); // an event that is part of `...` + } + } + expect(found, [XmlTextEvent('a'), XmlTextEvent('b')]); + }); + test('stream', () async { + final result = await Stream.value(input) + .toXmlEvents() + .normalizeEvents() + .selectSubtreeEvents((event) => event.name == 'item') + .toXmlNodes() + .expand((nodes) => nodes) + .toList(); + expect(result.map((each) => each.toString()), + ['a', 'b']); + }); + }); }