Skip to content

Instantly share code, notes, and snippets.

@daniel-v
Created May 4, 2016 14:40
Show Gist options
  • Save daniel-v/e6d016374474eb257cdb8f92f0606bbb to your computer and use it in GitHub Desktop.
Save daniel-v/e6d016374474eb257cdb8f92f0606bbb to your computer and use it in GitHub Desktop.
XML package test case
import 'package:test/test.dart';
import 'package:xml/xml.dart';
final String xmlWithoutGt = '''
<?xml version="1.0" encoding="utf-8"?>
<doc>
<test>
You shall do pass
</test>
</doc>
''';
final String xmlWithGt = '''
<?xml version="1.0" encoding="utf-8"?>
<doc>
<test>
&lt;You shall do pass&gt;
</test>
</doc>
''';
final RegExp WS_REGEX = new RegExp(r'[\r\n\t]+');
main() {
group('Without &gt', () {
String trimmedXml;
setUp(() {
trimmedXml = xmlWithoutGt.replaceAll(WS_REGEX, '');
});
test('Parsing and reencoding the document should be equal', () {
XmlDocument document = parse(trimmedXml);
String reencoded = document.toXmlString().replaceAll(WS_REGEX, '');
expect(trimmedXml, equalsIgnoringWhitespace(reencoded));
});
});
group('With &gt', () {
String trimmedXml;
setUp(() {
trimmedXml = xmlWithGt.replaceAll(WS_REGEX, '');
});
test('Parsing and reencoding the document should be equal', () {
XmlDocument document = parse(trimmedXml);
String reencoded = document.toXmlString()
.replaceAll(WS_REGEX, '');
expect(trimmedXml, equalsIgnoringWhitespace(reencoded));
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment