Skip to content

Testing cleanup #249

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 4 commits into from
Jun 27, 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
3 changes: 1 addition & 2 deletions example/test/ensure_build_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ final _whitespace = new RegExp(r'\s');
Set<String> _changedGeneratedFiles() {
var output = _runProc('git', ['status', '--porcelain']);

return LineSplitter
.split(output)
return LineSplitter.split(output)
.map((line) => line.split(_whitespace).last)
.where((path) => path.endsWith('.dart'))
.toSet();
Expand Down
4 changes: 2 additions & 2 deletions json_serializable/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: json_serializable
version: 0.5.8
version: 0.5.9-dev
author: Dart Team <misc@dartlang.org>
description: Generates utilities to aid in serializing to/from JSON.
homepage: https://github.com/dart-lang/json_serializable
Expand All @@ -19,7 +19,7 @@ dependencies:
source_gen: ^0.8.2

dev_dependencies:
build_runner: ^0.8.0
build_runner: ^0.9.0
build_web_compilers: ^0.4.0+1
build_test: ^0.10.0
collection: ^1.14.0
Expand Down
3 changes: 1 addition & 2 deletions json_serializable/test/ensure_build_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ final _whitespace = new RegExp(r'\s');
Set<String> _changedGeneratedFiles() {
var output = _runProc('git', ['status', '--porcelain']);

return LineSplitter
.split(output)
return LineSplitter.split(output)
.map((line) => line.split(_whitespace).last)
.where((path) => path.endsWith('.dart'))
.toSet();
Expand Down
20 changes: 14 additions & 6 deletions json_serializable/test/integration/integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
import 'package:test/test.dart';

import '../test_utils.dart';
import 'json_test_common.dart' show Category, House, Platform;
import 'json_test_common.dart' show Category, Platform;
import 'json_test_example.dart';

Matcher _throwsArgumentError(matcher) =>
throwsA(isArgumentError.having((e) => e.message, 'message', matcher));

void main() {
group('Person', () {
void roundTripPerson(Person p) {
Expand All @@ -25,12 +28,12 @@ void main() {
});

test('now', () {
roundTripPerson(new Person('a', 'b', House.gryffindor,
roundTripPerson(new Person('a', 'b', Category.charmed,
middleName: 'c', dateOfBirth: new DateTime.now()));
});

test('now toUtc', () {
roundTripPerson(new Person('a', 'b', House.hufflepuff,
roundTripPerson(new Person('a', 'b', Category.bottom,
middleName: 'c', dateOfBirth: new DateTime.now().toUtc()));
});

Expand All @@ -42,7 +45,7 @@ void main() {

test('enum map', () {
var person = new Person(null, null, null)
..houseMap = {'bob': House.gryffindor};
..houseMap = {'bob': Category.strange};
expect(person.dateOfBirth, isNull);
roundTripPerson(person);
});
Expand Down Expand Up @@ -81,12 +84,17 @@ void main() {
});

test('required, but missing enum value fails', () {
expect(() => new Order.fromJson({}), throwsArgumentError);
expect(
() => new Order.fromJson({}),
_throwsArgumentError('`null` is not one of the supported values: '
'top, bottom, strange, charmed, up, down'));
});

test('mismatched enum value fails', () {
expect(
() => new Order.fromJson({'category': 'weird'}), throwsArgumentError);
() => new Order.fromJson({'category': 'weird'}),
_throwsArgumentError('`weird` is not one of the supported values: '
'top, bottom, strange, charmed, up, down'));
});

test('platform', () {
Expand Down
1 change: 0 additions & 1 deletion json_serializable/test/integration/json_test_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import 'package:collection/collection.dart';

enum House { gryffindor, hufflepuff, ravenclaw, slytherin }
enum Category { top, bottom, strange, charmed, up, down }

Duration durationFromInt(int ms) => new Duration(milliseconds: ms);
Expand Down
4 changes: 2 additions & 2 deletions json_serializable/test/integration/json_test_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class Person extends Object with _$PersonSerializerMixin {
final String firstName, middleName, lastName;
final DateTime dateOfBirth;
@JsonKey(name: '\$house')
final House house;
final Category house;

Order order;

Map<String, House> houseMap;
Map<String, Category> houseMap;

Person(this.firstName, this.lastName, this.house,
{this.middleName, this.dateOfBirth});
Expand Down
13 changes: 8 additions & 5 deletions json_serializable/test/integration/json_test_example.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ part of 'json_test_example.dart';
// **************************************************************************

Person _$PersonFromJson(Map<String, dynamic> json) {
return new Person(json['firstName'] as String, json['lastName'] as String,
$enumDecodeNullable('House', House.values, json[r'$house'] as String),
return new Person(
json['firstName'] as String,
json['lastName'] as String,
$enumDecodeNullable(
'Category', Category.values, json[r'$house'] as String),
middleName: json['middleName'] as String,
dateOfBirth: json['dateOfBirth'] == null
? null
Expand All @@ -22,17 +25,17 @@ Person _$PersonFromJson(Map<String, dynamic> json) {
: new Order.fromJson(json['order'] as Map<String, dynamic>)
..houseMap = (json['houseMap'] as Map<String, dynamic>)?.map((k, e) =>
new MapEntry(
k, $enumDecodeNullable('House', House.values, e as String)));
k, $enumDecodeNullable('Category', Category.values, e as String)));
}

abstract class _$PersonSerializerMixin {
String get firstName;
String get middleName;
String get lastName;
DateTime get dateOfBirth;
House get house;
Category get house;
Order get order;
Map<String, House> get houseMap;
Map<String, Category> get houseMap;
Map<String, dynamic> toJson() => <String, dynamic>{
'firstName': firstName,
'middleName': middleName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class Person extends Object with _$PersonSerializerMixin {
final String firstName, middleName, lastName;
final DateTime dateOfBirth;
@JsonKey(name: '\$house')
final House house;
final Category house;

Order order;

Map<String, House> houseMap;
Map<String, Category> houseMap;

Person(this.firstName, this.lastName, this.house,
{this.middleName, this.dateOfBirth});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ part of 'json_test_example.non_nullable.dart';

Person _$PersonFromJson(Map<String, dynamic> json) {
return new Person(json['firstName'] as String, json['lastName'] as String,
$enumDecode('House', House.values, json[r'$house'] as String),
$enumDecode('Category', Category.values, json[r'$house'] as String),
middleName: json['middleName'] as String,
dateOfBirth: DateTime.parse(json['dateOfBirth'] as String))
..order = new Order.fromJson(json['order'] as Map<String, dynamic>)
..houseMap = (json['houseMap'] as Map<String, dynamic>).map((k, e) =>
new MapEntry(k, $enumDecode('House', House.values, e as String)));
new MapEntry(k, $enumDecode('Category', Category.values, e as String)));
}

abstract class _$PersonSerializerMixin {
String get firstName;
String get middleName;
String get lastName;
DateTime get dateOfBirth;
House get house;
Category get house;
Order get order;
Map<String, House> get houseMap;
Map<String, Category> get houseMap;
Map<String, dynamic> toJson() => <String, dynamic>{
'firstName': firstName,
'middleName': middleName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class Person extends Object with _$PersonSerializerMixin {
final String firstName, middleName, lastName;
final DateTime dateOfBirth;
@JsonKey(name: '\$house')
final House house;
final Category house;

Order order;

Map<String, House> houseMap;
Map<String, Category> houseMap;

Person(this.firstName, this.lastName, this.house,
{this.middleName, this.dateOfBirth});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ part of 'json_test_example.non_nullable.wrapped.dart';

Person _$PersonFromJson(Map<String, dynamic> json) {
return new Person(json['firstName'] as String, json['lastName'] as String,
$enumDecode('House', House.values, json[r'$house'] as String),
$enumDecode('Category', Category.values, json[r'$house'] as String),
middleName: json['middleName'] as String,
dateOfBirth: DateTime.parse(json['dateOfBirth'] as String))
..order = new Order.fromJson(json['order'] as Map<String, dynamic>)
..houseMap = (json['houseMap'] as Map<String, dynamic>).map((k, e) =>
new MapEntry(k, $enumDecode('House', House.values, e as String)));
new MapEntry(k, $enumDecode('Category', Category.values, e as String)));
}

abstract class _$PersonSerializerMixin {
String get firstName;
String get middleName;
String get lastName;
DateTime get dateOfBirth;
House get house;
Category get house;
Order get order;
Map<String, House> get houseMap;
Map<String, Category> get houseMap;
Map<String, dynamic> toJson() => new _$PersonJsonMapWrapper(this);
}

Expand Down Expand Up @@ -63,7 +63,7 @@ class _$PersonJsonMapWrapper extends $JsonMapWrapper {
case 'order':
return _v.order;
case 'houseMap':
return $wrapMap<String, House>(
return $wrapMap<String, Category>(
_v.houseMap, (e) => e.toString().split('.').last);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class Person extends Object with _$PersonSerializerMixin {
final String firstName, middleName, lastName;
final DateTime dateOfBirth;
@JsonKey(name: '\$house')
final House house;
final Category house;

Order order;

Map<String, House> houseMap;
Map<String, Category> houseMap;

Person(this.firstName, this.lastName, this.house,
{this.middleName, this.dateOfBirth});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ part of 'json_test_example.wrapped.dart';
// **************************************************************************

Person _$PersonFromJson(Map<String, dynamic> json) {
return new Person(json['firstName'] as String, json['lastName'] as String,
$enumDecodeNullable('House', House.values, json[r'$house'] as String),
return new Person(
json['firstName'] as String,
json['lastName'] as String,
$enumDecodeNullable(
'Category', Category.values, json[r'$house'] as String),
middleName: json['middleName'] as String,
dateOfBirth: json['dateOfBirth'] == null
? null
Expand All @@ -22,17 +25,17 @@ Person _$PersonFromJson(Map<String, dynamic> json) {
: new Order.fromJson(json['order'] as Map<String, dynamic>)
..houseMap = (json['houseMap'] as Map<String, dynamic>)?.map((k, e) =>
new MapEntry(
k, $enumDecodeNullable('House', House.values, e as String)));
k, $enumDecodeNullable('Category', Category.values, e as String)));
}

abstract class _$PersonSerializerMixin {
String get firstName;
String get middleName;
String get lastName;
DateTime get dateOfBirth;
House get house;
Category get house;
Order get order;
Map<String, House> get houseMap;
Map<String, Category> get houseMap;
Map<String, dynamic> toJson() => new _$PersonJsonMapWrapper(this);
}

Expand Down Expand Up @@ -68,7 +71,7 @@ class _$PersonJsonMapWrapper extends $JsonMapWrapper {
case 'order':
return _v.order;
case 'houseMap':
return $wrapMapHandleNull<String, House>(
return $wrapMapHandleNull<String, Category>(
_v.houseMap, (e) => e?.toString()?.split('.')?.last);
}
}
Expand Down