source_gen_test
source_gen_test copied to clipboard
feat: add support for custom output formatting
This change adds support for custom output formatting and is inspired by #29 and https://github.com/google/json_serializable.dart/pull/179. I am currently in the process of rewriting the tests in xml_serializable to use this package instead of the generator directly and it would be very useful (and more performant) to be able to skip the formatting of the generated source code.
Before
@ShouldGenerate(r'''
void _$StringHappyPathBuildXmlChildren(
StringHappyPath instance, XmlBuilder builder,
{Map<String, String> namespaces = const {}}) {
final value = instance.value;
final valueSerialized = value;
builder.attribute('value', valueSerialized);
}
StringHappyPath _$StringHappyPathFromXmlElement(XmlElement element) {
final value = element.getAttribute('value')!;
return StringHappyPath(value: value);
}
List<XmlAttribute> _$StringHappyPathToXmlAttributes(StringHappyPath instance,
{Map<String, String?> namespaces = const {}}) {
final attributes = <XmlAttribute>[];
final value = instance.value;
final valueSerialized = value;
final valueConstructed = XmlAttribute(XmlName('value'), valueSerialized);
attributes.add(valueConstructed);
return attributes;
}
List<XmlNode> _$StringHappyPathToXmlChildren(StringHappyPath instance,
{Map<String, String?> namespaces = const {}}) {
final children = <XmlNode>[];
return children;
}
''')
@XmlSerializable()
class StringHappyPath {
@XmlAttribute()
String value;
StringHappyPath({required this.value});
}
After
@ShouldGenerate(r'''
void _$StringHappyPathBuildXmlChildren(StringHappyPath instance, XmlBuilder builder, {Map<String, String> namespaces = const {}}) {
final value = instance.value;
final valueSerialized = value;
builder.attribute('value', valueSerialized);
}
StringHappyPath _$StringHappyPathFromXmlElement(XmlElement element) {
final value = element.getAttribute('value')!;
return StringHappyPath(value: value);
}
List<XmlAttribute> _$StringHappyPathToXmlAttributes(StringHappyPath instance, {Map<String, String?> namespaces = const {}}) {
final attributes = <XmlAttribute>[];
final value = instance.value;
final valueSerialized = value;
final valueConstructed = XmlAttribute(XmlName('value'), valueSerialized);
attributes.add(valueConstructed);
return attributes;
}
List<XmlNode> _$StringHappyPathToXmlChildren(StringHappyPath instance, {Map<String, String?> namespaces = const {}}) {
final children = <XmlNode>[];
return children;
}''')
@XmlSerializable()
class StringHappyPath {
@XmlAttribute()
String value;
StringHappyPath({required this.value});
}
@kevmoo thank you very much for your work on this package!
I was wondering if you might be able to review these changes when you have a bit of time spare?