Skip to content

Commit

Permalink
Add test for #177 examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
renggli committed Aug 16, 2023
1 parent e510de8 commit a1bc413
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/regression_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:test/test.dart';
import 'package:xml/xml.dart';
import 'package:xml/xml_events.dart';

import 'utils/assertions.dart';

Expand Down Expand Up @@ -249,4 +250,32 @@ void main() {
'<XML><BOX><BLUR><IMG><URL value="./" /></IMG></BLUR></BOX></XML>');
expect(expected.toXmlString(), actual.toXmlString());
});
group('https://github.com/renggli/dart-xml/discussions/177', () {
const input = '<rss><items><item>a</item><item>b</item></items></rss>';
test('iterable', () {
var started = false;
final found = <XmlEvent>[];
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 `<item>...</item>`
}
}
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()),
['<item>a</item>', '<item>b</item>']);
});
});
}

0 comments on commit a1bc413

Please sign in to comment.