Skip to content

Test cleanup #160

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
May 17, 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
16 changes: 6 additions & 10 deletions json_serializable/test/json_serializable_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ library json_serializable.test.json_generator_test;
// TODO(kevmoo): test all flavors of `nullable` - class, fields, etc

import 'dart:async';
import 'dart:io';

import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/src/string_source.dart';
import 'package:dart_style/dart_style.dart' as dart_style;
import 'package:json_serializable/json_serializable.dart';
import 'package:json_serializable/src/constants.dart';
Expand All @@ -34,7 +32,7 @@ Matcher _throwsInvalidGenerationSourceError(messageMatcher, todoMatcher) =>

void main() {
setUpAll(() async {
_compUnit = await _getCompilationUnitForString(getPackagePath());
_compUnit = await _getCompilationUnitForString();
});

group('without wrappers',
Expand Down Expand Up @@ -512,14 +510,12 @@ abstract class _$SubTypeSerializerMixin {

final _formatter = new dart_style.DartFormatter();

Future<CompilationUnit> _getCompilationUnitForString(String projectPath) async {
var fileName = 'json_serializable_test_input.dart';
var filePath = p.join(getPackagePath(), 'test', 'src', fileName);
var source =
new StringSource(new File(filePath).readAsStringSync(), fileName);

var context = await getAnalysisContextForProjectPath(projectPath);
Future<CompilationUnit> _getCompilationUnitForString() async {
Copy link
Member

Choose a reason for hiding this comment

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

ForString... what String?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Old name. Can fix it up in a follow-up CL

var context = await getAnalysisContextForProjectPath(getPackagePath());

var fileUri = p.toUri(p.join(
getPackagePath(), 'test', 'src', 'json_serializable_test_input.dart'));
var source = context.sourceFactory.forUri2(fileUri);
var libElement = context.computeLibraryElement(source);
return context.resolveCompilationUnit(source, libElement);
}
Expand Down
134 changes: 2 additions & 132 deletions json_serializable/test/src/json_serializable_test_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
//ignore_for_file: avoid_unused_constructor_parameters, prefer_initializing_formals
import 'package:json_annotation/json_annotation.dart';

part 'to_from_json_test_input.dart';

@JsonSerializable()
const theAnswer = 42;

Expand Down Expand Up @@ -212,135 +214,3 @@ class SuperType {
int priceFraction(int other) =>
superTypeViaCtor == null ? null : superTypeViaCtor ~/ other;
}

//
// to/from JSON function classes
//

int _toInt(bool input) => 42;
int _twoArgFunction(int a, int b) => 42;

dynamic _toDynamic(dynamic input) => null;
Object _toObject(Object input) => null;

@JsonSerializable()
class BadFromFuncReturnType {
@JsonKey(fromJson: _toInt)
String field;
}

@JsonSerializable()
class InvalidFromFunc2Args {
@JsonKey(fromJson: _twoArgFunction)
String field;
}

@JsonSerializable()
class InvalidFromFuncClassStatic {
static Duration _staticFunc(int param) => null;

@JsonKey(fromJson: _staticFunc)
String field;
}

@JsonSerializable()
class BadToFuncReturnType {
@JsonKey(toJson: _toInt)
String field;
}

@JsonSerializable()
class InvalidToFunc2Args {
@JsonKey(toJson: _twoArgFunction)
String field;
}

@JsonSerializable()
class InvalidToFuncClassStatic {
static Duration _staticFunc(int param) => null;

@JsonKey(toJson: _staticFunc)
String field;
}

@JsonSerializable()
class ObjectConvertMethods {
@JsonKey(fromJson: _toObject, toJson: _toObject)
String field;
}

@JsonSerializable()
class DynamicConvertMethods {
@JsonKey(fromJson: _toDynamic, toJson: _toDynamic)
String field;
}

String _toString(String input) => null;

@JsonSerializable()
class TypedConvertMethods {
@JsonKey(fromJson: _toString, toJson: _toString)
String field;
}

String _fromDynamicMap(Map input) => null;
String _fromDynamicList(List input) => null;
String _fromDynamicIterable(Iterable input) => null;

@JsonSerializable(createToJson: false)
class FromDynamicCollection {
@JsonKey(fromJson: _fromDynamicMap)
String mapField;
@JsonKey(fromJson: _fromDynamicList)
String listField;
@JsonKey(fromJson: _fromDynamicIterable)
String iterableField;
}

String _noArgs() => null;

@JsonSerializable(createToJson: false)
class BadNoArgs {
@JsonKey(fromJson: _noArgs)
String field;
}

String _twoArgs(a, b) => null;

@JsonSerializable(createToJson: false)
class BadTwoRequiredPositional {
@JsonKey(fromJson: _twoArgs)
String field;
}

String _oneNamed({a}) => null;

@JsonSerializable(createToJson: false)
class BadOneNamed {
@JsonKey(fromJson: _oneNamed)
String field;
}

String _oneNormalOnePositional(a, [b]) => null;

@JsonSerializable(createToJson: false)
class OkayOneNormalOptionalPositional {
@JsonKey(fromJson: _oneNormalOnePositional)
String field;
}

String _oneNormalOptionalNamed(a, {b}) => null;

@JsonSerializable(createToJson: false)
class OkayOneNormalOptionalNamed {
@JsonKey(fromJson: _oneNormalOptionalNamed)
String field;
}

String _onlyOptionalPositional([a, b]) => null;

@JsonSerializable(createToJson: false)
class OkayOnlyOptionalPositional {
@JsonKey(fromJson: _onlyOptionalPositional)
String field;
}
133 changes: 133 additions & 0 deletions json_serializable/test/src/to_from_json_test_input.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

part of 'json_serializable_test_input.dart';

int _toInt(bool input) => 42;
int _twoArgFunction(int a, int b) => 42;

dynamic _toDynamic(dynamic input) => null;
Object _toObject(Object input) => null;

@JsonSerializable()
class BadFromFuncReturnType {
@JsonKey(fromJson: _toInt)
String field;
}

@JsonSerializable()
class InvalidFromFunc2Args {
@JsonKey(fromJson: _twoArgFunction)
String field;
}

@JsonSerializable()
class InvalidFromFuncClassStatic {
static Duration _staticFunc(int param) => null;

@JsonKey(fromJson: _staticFunc)
String field;
}

@JsonSerializable()
class BadToFuncReturnType {
@JsonKey(toJson: _toInt)
String field;
}

@JsonSerializable()
class InvalidToFunc2Args {
@JsonKey(toJson: _twoArgFunction)
String field;
}

@JsonSerializable()
class InvalidToFuncClassStatic {
static Duration _staticFunc(int param) => null;

@JsonKey(toJson: _staticFunc)
String field;
}

@JsonSerializable()
class ObjectConvertMethods {
@JsonKey(fromJson: _toObject, toJson: _toObject)
String field;
}

@JsonSerializable()
class DynamicConvertMethods {
@JsonKey(fromJson: _toDynamic, toJson: _toDynamic)
String field;
}

String _toString(String input) => null;

@JsonSerializable()
class TypedConvertMethods {
@JsonKey(fromJson: _toString, toJson: _toString)
String field;
}

String _fromDynamicMap(Map input) => null;
String _fromDynamicList(List input) => null;
String _fromDynamicIterable(Iterable input) => null;

@JsonSerializable(createToJson: false)
class FromDynamicCollection {
@JsonKey(fromJson: _fromDynamicMap)
String mapField;
@JsonKey(fromJson: _fromDynamicList)
String listField;
@JsonKey(fromJson: _fromDynamicIterable)
String iterableField;
}

String _noArgs() => null;

@JsonSerializable(createToJson: false)
class BadNoArgs {
@JsonKey(fromJson: _noArgs)
String field;
}

String _twoArgs(a, b) => null;

@JsonSerializable(createToJson: false)
class BadTwoRequiredPositional {
@JsonKey(fromJson: _twoArgs)
String field;
}

String _oneNamed({a}) => null;

@JsonSerializable(createToJson: false)
class BadOneNamed {
@JsonKey(fromJson: _oneNamed)
String field;
}

String _oneNormalOnePositional(a, [b]) => null;

@JsonSerializable(createToJson: false)
class OkayOneNormalOptionalPositional {
@JsonKey(fromJson: _oneNormalOnePositional)
String field;
}

String _oneNormalOptionalNamed(a, {b}) => null;

@JsonSerializable(createToJson: false)
class OkayOneNormalOptionalNamed {
@JsonKey(fromJson: _oneNormalOptionalNamed)
String field;
}

String _onlyOptionalPositional([a, b]) => null;

@JsonSerializable(createToJson: false)
class OkayOnlyOptionalPositional {
@JsonKey(fromJson: _onlyOptionalPositional)
String field;
}