Commit 8aacc288 authored by xster's avatar xster Committed by GitHub

Simplify change notifier toString and handle nulls (#9368)

parent 819bb539
......@@ -161,15 +161,7 @@ class _MergingListenable extends ChangeNotifier {
@override
String toString() {
final StringBuffer buffer = new StringBuffer();
buffer.write('Listenable.merge([');
for (int i = 0; i < _children.length; ++i) {
buffer.write(_children[i].toString());
if (i < _children.length - 1)
buffer.write(', ');
}
buffer.write('])');
return buffer.toString();
return 'Listenable.merge([${_children.join(", ")}])';
}
}
......
......@@ -206,4 +206,33 @@ void main() {
notifier.value = 3.0;
expect(log, isEmpty);
});
test('Listenable.merge toString', () {
final TestNotifier source1 = new TestNotifier();
final TestNotifier source2 = new TestNotifier();
ChangeNotifier listenableUnderTest = new Listenable.merge(<Listenable>[]);
expect(listenableUnderTest.toString(), 'Listenable.merge([])');
listenableUnderTest = new Listenable.merge(<Listenable>[null]);
expect(listenableUnderTest.toString(), 'Listenable.merge([null])');
listenableUnderTest = new Listenable.merge(<Listenable>[source1]);
expect(
listenableUnderTest.toString(),
"Listenable.merge([Instance of 'TestNotifier'])",
);
listenableUnderTest = new Listenable.merge(<Listenable>[source1, source2]);
expect(
listenableUnderTest.toString(),
"Listenable.merge([Instance of 'TestNotifier', Instance of 'TestNotifier'])",
);
listenableUnderTest = new Listenable.merge(<Listenable>[null, source2]);
expect(
listenableUnderTest.toString(),
"Listenable.merge([null, Instance of 'TestNotifier'])",
);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment