Fix describeInvocation code style (#154)
Fix code style for `describeInvocation`.
Might as well fix output for `Invocation.setter` cases too.
diff --git a/packages/file/lib/src/backends/record_replay/common.dart b/packages/file/lib/src/backends/record_replay/common.dart
index c494e50..ce5b2ef 100644
--- a/packages/file/lib/src/backends/record_replay/common.dart
+++ b/packages/file/lib/src/backends/record_replay/common.dart
@@ -159,26 +159,33 @@
/// Returns a human-readable representation of an [Invocation].
String describeInvocation(Invocation invocation) {
- StringBuffer buf = StringBuffer();
- buf.write(getSymbolName(invocation.memberName));
+ final StringBuffer buffer = StringBuffer()
+ ..write(getSymbolName(invocation.memberName));
if (invocation.isMethod) {
- buf.write('(');
- int i = 0;
+ buffer.write('(');
+ int printedCount = 0;
for (dynamic arg in invocation.positionalArguments) {
- if (i++ > 0) {
- buf.write(', ');
+ if (printedCount > 0) {
+ buffer.write(', ');
}
- buf.write(Error.safeToString(encode(arg)));
+ buffer.write(Error.safeToString(encode(arg)));
+ printedCount += 1;
}
- invocation.namedArguments.forEach((Symbol name, dynamic value) {
- if (i++ > 0) {
- buf.write(', ');
+ for (final nameValue in invocation.namedArguments.entries) {
+ final Symbol name = nameValue.key;
+ final dynamic value = nameValue.value;
+ if (printedCount > 0) {
+ buffer.write(', ');
}
- buf.write('${getSymbolName(name)}: ${Error.safeToString(encode(value))}');
- });
- buf.write(')');
+ buffer.write(
+ '${getSymbolName(name)}: ${Error.safeToString(encode(value))}');
+ printedCount += 1;
+ }
+ buffer.write(')');
} else if (invocation.isSetter) {
- buf.write(Error.safeToString(encode(invocation.positionalArguments[0])));
+ buffer
+ ..write(' = ')
+ ..write(Error.safeToString(encode(invocation.positionalArguments[0])));
}
- return buf.toString();
+ return buffer.toString();
}
diff --git a/packages/file/test/replay_test.dart b/packages/file/test/replay_test.dart
index 9bcb4d5..36edbd6 100644
--- a/packages/file/test/replay_test.dart
+++ b/packages/file/test/replay_test.dart
@@ -210,21 +210,21 @@
});
group('describeInvocation', () {
- test('noArguments', () {
+ test('methodWithNoArguments', () {
expect(
describeInvocation(Invocation.method(#foo, [])),
'foo()',
);
});
- test('onlyPositionalArguments', () {
+ test('methodWithOnlyPositionalArguments', () {
expect(
describeInvocation(Invocation.method(#foo, [1, 'bar', null])),
'foo(1, "bar", null)',
);
});
- test('onlyNamedArguments', () {
+ test('methodWithOnlyNamedArguments', () {
expect(
describeInvocation(
Invocation.method(#foo, [], {#x: 2, #y: 'baz', #z: null})),
@@ -232,7 +232,7 @@
);
});
- test('positionalAndNamedArguments', () {
+ test('methodWithPositionalAndNamedArguments', () {
expect(
describeInvocation(Invocation.method(
#foo,
@@ -242,6 +242,13 @@
'foo(1, "bar", null, x: 2, y: "baz", z: null)',
);
});
+
+ test('setter', () {
+ expect(
+ describeInvocation(Invocation.setter(#property, 'value')),
+ 'property = "value"',
+ );
+ });
});
}