Skip to content

Commit

Permalink
Change default dummy value for String to contain some info
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 568789232
  • Loading branch information
Ilya Yanok authored and copybara-github committed Sep 27, 2023
1 parent 097e563 commit 7126a89
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 0 additions & 2 deletions lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1567,8 +1567,6 @@ class _MockClassInfo {
..url = 'dart:async'
..types.add(elementType);
}).property('empty').call([]);
} else if (type.isDartCoreString) {
return literalString('');
} else if (type.isDartTypedDataSealed) {
// These types (XXXList + ByteData) from dart:typed_data are
// sealed, e.g. "non-subtypeable", but they
Expand Down
10 changes: 7 additions & 3 deletions lib/src/dummies.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ import 'dart:async';
import 'dart:collection';
import 'dart:typed_data';

import 'mock.dart' show FakeFunctionUsedError;
import 'mock.dart' show FakeFunctionUsedError, PrettyString;
import 'platform_dummies_js.dart'
if (dart.library.io) 'platform_dummies_vm.dart';

// TODO(yanok): try to change these to _unreasonable_ values, for example,
// String could totally contain an explanation.
const int _dummyInt = 0;
const double _dummyDouble = 0.0;
const String _dummyString = '';

// Create a dummy String with info on why it was created.
String _dummyString(Object o, Invocation i) =>
'''Dummy String created while calling ${i.toPrettyString()} on $o.
''';

// This covers functions with up to 20 positional arguments, for more arguments,
// type arguments or named arguments, users would have to provide a dummy
Expand Down Expand Up @@ -104,7 +108,7 @@ Map<Type, DummyBuilder> _defaultDummyBuilders = {
int: (_, _i) => _dummyInt,
num: (_, _i) => _dummyInt,
double: (_, _i) => _dummyDouble,
String: (_, _i) => _dummyString,
String: _dummyString,
Int8List: (_, _i) => Int8List(0),
Int16List: (_, _i) => Int16List(0),
Int32List: (_, _i) => Int32List(0),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/mock.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@ void resetMockitoState() {
resetDummyBuilders();
}

extension on Invocation {
extension PrettyString on Invocation {
/// Returns a pretty String representing a method (or getter or setter) call
/// including its arguments, separating elements with newlines when it should
/// improve readability.
Expand Down

0 comments on commit 7126a89

Please sign in to comment.