Skip to content

Adding tests, tweaking built_value code. #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions jsonexample/lib/built_value/built_complex_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ abstract class BuiltComplexObject
@nullable
double get aDouble;

@nullable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me sad, but I know you're doing it for a reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I did the other two first, so it's been changed to match. I'm annoyed that I didn't catch it earlier, but that's why one writes tests, I guess. 😄

BuiltSimpleObject get anObject;

@nullable
BuiltList<String> get aListOfStrings;

@nullable
BuiltList<int> get aListOfInts;

@nullable
BuiltList<double> get aListOfDoubles;

@nullable
BuiltList<BuiltSimpleObject> get aListOfObjects;

BuiltComplexObject._();
Expand Down
94 changes: 47 additions & 47 deletions jsonexample/lib/built_value/built_complex_object.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
part of 'built_complex_object.dart';

// **************************************************************************
// Generator: BuiltValueGenerator
// BuiltValueGenerator
// **************************************************************************

// ignore_for_file: always_put_control_body_on_new_line
Expand All @@ -31,27 +31,7 @@ class _$BuiltComplexObjectSerializer
@override
Iterable serialize(Serializers serializers, BuiltComplexObject object,
{FullType specifiedType: FullType.unspecified}) {
final result = <Object>[
'anObject',
serializers.serialize(object.anObject,
specifiedType: const FullType(BuiltSimpleObject)),
'aListOfStrings',
serializers.serialize(object.aListOfStrings,
specifiedType:
const FullType(BuiltList, const [const FullType(String)])),
'aListOfInts',
serializers.serialize(object.aListOfInts,
specifiedType:
const FullType(BuiltList, const [const FullType(int)])),
'aListOfDoubles',
serializers.serialize(object.aListOfDoubles,
specifiedType:
const FullType(BuiltList, const [const FullType(double)])),
'aListOfObjects',
serializers.serialize(object.aListOfObjects,
specifiedType: const FullType(
BuiltList, const [const FullType(BuiltSimpleObject)])),
];
final result = <Object>[];
if (object.aString != null) {
result
..add('aString')
Expand All @@ -70,6 +50,40 @@ class _$BuiltComplexObjectSerializer
..add(serializers.serialize(object.aDouble,
specifiedType: const FullType(double)));
}
if (object.anObject != null) {
result
..add('anObject')
..add(serializers.serialize(object.anObject,
specifiedType: const FullType(BuiltSimpleObject)));
}
if (object.aListOfStrings != null) {
result
..add('aListOfStrings')
..add(serializers.serialize(object.aListOfStrings,
specifiedType:
const FullType(BuiltList, const [const FullType(String)])));
}
if (object.aListOfInts != null) {
result
..add('aListOfInts')
..add(serializers.serialize(object.aListOfInts,
specifiedType:
const FullType(BuiltList, const [const FullType(int)])));
}
if (object.aListOfDoubles != null) {
result
..add('aListOfDoubles')
..add(serializers.serialize(object.aListOfDoubles,
specifiedType:
const FullType(BuiltList, const [const FullType(double)])));
}
if (object.aListOfObjects != null) {
result
..add('aListOfObjects')
..add(serializers.serialize(object.aListOfObjects,
specifiedType: const FullType(
BuiltList, const [const FullType(BuiltSimpleObject)])));
}

return result;
}
Expand Down Expand Up @@ -163,21 +177,7 @@ class _$BuiltComplexObject extends BuiltComplexObject {
this.aListOfInts,
this.aListOfDoubles,
this.aListOfObjects})
: super._() {
if (anObject == null)
throw new BuiltValueNullFieldError('BuiltComplexObject', 'anObject');
if (aListOfStrings == null)
throw new BuiltValueNullFieldError(
'BuiltComplexObject', 'aListOfStrings');
if (aListOfInts == null)
throw new BuiltValueNullFieldError('BuiltComplexObject', 'aListOfInts');
if (aListOfDoubles == null)
throw new BuiltValueNullFieldError(
'BuiltComplexObject', 'aListOfDoubles');
if (aListOfObjects == null)
throw new BuiltValueNullFieldError(
'BuiltComplexObject', 'aListOfObjects');
}
: super._();

@override
BuiltComplexObject rebuild(void updates(BuiltComplexObjectBuilder b)) =>
Expand Down Expand Up @@ -315,24 +315,24 @@ class BuiltComplexObjectBuilder
aString: aString,
anInt: anInt,
aDouble: aDouble,
anObject: anObject.build(),
aListOfStrings: aListOfStrings.build(),
aListOfInts: aListOfInts.build(),
aListOfDoubles: aListOfDoubles.build(),
aListOfObjects: aListOfObjects.build());
anObject: _anObject?.build(),
aListOfStrings: _aListOfStrings?.build(),
aListOfInts: _aListOfInts?.build(),
aListOfDoubles: _aListOfDoubles?.build(),
aListOfObjects: _aListOfObjects?.build());
} catch (_) {
String _$failedField;
try {
_$failedField = 'anObject';
anObject.build();
_anObject?.build();
_$failedField = 'aListOfStrings';
aListOfStrings.build();
_aListOfStrings?.build();
_$failedField = 'aListOfInts';
aListOfInts.build();
_aListOfInts?.build();
_$failedField = 'aListOfDoubles';
aListOfDoubles.build();
_aListOfDoubles?.build();
_$failedField = 'aListOfObjects';
aListOfObjects.build();
_aListOfObjects?.build();
} catch (e) {
throw new BuiltValueNestedFieldError(
'BuiltComplexObject', _$failedField, e.toString());
Expand Down
3 changes: 3 additions & 0 deletions jsonexample/lib/built_value/built_simple_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ abstract class BuiltSimpleObject
@nullable
double get aDouble;

@nullable
BuiltList<String> get aListOfStrings;

@nullable
BuiltList<int> get aListOfInts;

@nullable
BuiltList<double> get aListOfDoubles;

BuiltSimpleObject._();
Expand Down
59 changes: 30 additions & 29 deletions jsonexample/lib/built_value/built_simple_object.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
part of 'built_simple_object.dart';

// **************************************************************************
// Generator: BuiltValueGenerator
// BuiltValueGenerator
// **************************************************************************

// ignore_for_file: always_put_control_body_on_new_line
Expand All @@ -31,20 +31,7 @@ class _$BuiltSimpleObjectSerializer
@override
Iterable serialize(Serializers serializers, BuiltSimpleObject object,
{FullType specifiedType: FullType.unspecified}) {
final result = <Object>[
'aListOfStrings',
serializers.serialize(object.aListOfStrings,
specifiedType:
const FullType(BuiltList, const [const FullType(String)])),
'aListOfInts',
serializers.serialize(object.aListOfInts,
specifiedType:
const FullType(BuiltList, const [const FullType(int)])),
'aListOfDoubles',
serializers.serialize(object.aListOfDoubles,
specifiedType:
const FullType(BuiltList, const [const FullType(double)])),
];
final result = <Object>[];
if (object.aString != null) {
result
..add('aString')
Expand All @@ -63,6 +50,27 @@ class _$BuiltSimpleObjectSerializer
..add(serializers.serialize(object.aDouble,
specifiedType: const FullType(double)));
}
if (object.aListOfStrings != null) {
result
..add('aListOfStrings')
..add(serializers.serialize(object.aListOfStrings,
specifiedType:
const FullType(BuiltList, const [const FullType(String)])));
}
if (object.aListOfInts != null) {
result
..add('aListOfInts')
..add(serializers.serialize(object.aListOfInts,
specifiedType:
const FullType(BuiltList, const [const FullType(int)])));
}
if (object.aListOfDoubles != null) {
result
..add('aListOfDoubles')
..add(serializers.serialize(object.aListOfDoubles,
specifiedType:
const FullType(BuiltList, const [const FullType(double)])));
}

return result;
}
Expand Down Expand Up @@ -139,14 +147,7 @@ class _$BuiltSimpleObject extends BuiltSimpleObject {
this.aListOfStrings,
this.aListOfInts,
this.aListOfDoubles})
: super._() {
if (aListOfStrings == null)
throw new BuiltValueNullFieldError('BuiltSimpleObject', 'aListOfStrings');
if (aListOfInts == null)
throw new BuiltValueNullFieldError('BuiltSimpleObject', 'aListOfInts');
if (aListOfDoubles == null)
throw new BuiltValueNullFieldError('BuiltSimpleObject', 'aListOfDoubles');
}
: super._();

@override
BuiltSimpleObject rebuild(void updates(BuiltSimpleObjectBuilder b)) =>
Expand Down Expand Up @@ -262,18 +263,18 @@ class BuiltSimpleObjectBuilder
aString: aString,
anInt: anInt,
aDouble: aDouble,
aListOfStrings: aListOfStrings.build(),
aListOfInts: aListOfInts.build(),
aListOfDoubles: aListOfDoubles.build());
aListOfStrings: _aListOfStrings?.build(),
aListOfInts: _aListOfInts?.build(),
aListOfDoubles: _aListOfDoubles?.build());
} catch (_) {
String _$failedField;
try {
_$failedField = 'aListOfStrings';
aListOfStrings.build();
_aListOfStrings?.build();
_$failedField = 'aListOfInts';
aListOfInts.build();
_aListOfInts?.build();
_$failedField = 'aListOfDoubles';
aListOfDoubles.build();
_aListOfDoubles?.build();
} catch (e) {
throw new BuiltValueNestedFieldError(
'BuiltSimpleObject', _$failedField, e.toString());
Expand Down
2 changes: 1 addition & 1 deletion jsonexample/lib/built_value/built_value_serializers.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
part of serializers;

// **************************************************************************
// Generator: BuiltValueGenerator
// BuiltValueGenerator
// **************************************************************************

// ignore_for_file: always_put_control_body_on_new_line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
part of 'serializable_complex_object.dart';

// **************************************************************************
// Generator: JsonSerializableGenerator
// JsonSerializableGenerator
// **************************************************************************

SerializableComplexObject _$SerializableComplexObjectFromJson(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
part of 'serializable_simple_object.dart';

// **************************************************************************
// Generator: JsonSerializableGenerator
// JsonSerializableGenerator
// **************************************************************************

SerializableSimpleObject _$SerializableSimpleObjectFromJson(
Expand Down
2 changes: 1 addition & 1 deletion jsonexample/lib/tab_pages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class BasicsPage extends StatelessWidget {
children: [
Padding(
padding: const EdgeInsets.only(right: 8.0, bottom: 4.0),
child: Text('List of dynamic:', style: boldStyle),
child: Text('List of dynamics:', style: boldStyle),
),
Text(
prettyPrintList(strongListOfDynamics),
Expand Down
Loading