-
Notifications
You must be signed in to change notification settings - Fork 418
Add any_map
support
#158
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
Add any_map
support
#158
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// 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. | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:build/build.dart'; | ||
import 'package:json_serializable/builder.dart'; | ||
import 'package:logging/logging.dart'; | ||
import 'package:source_gen/source_gen.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
final _throwsCastError = throwsA(const isInstanceOf<CastError>()); | ||
|
||
void main() { | ||
StreamSubscription sub; | ||
final records = <LogRecord>[]; | ||
|
||
setUpAll(() { | ||
sub = log.onRecord.listen(records.add); | ||
}); | ||
|
||
tearDownAll(() async { | ||
await sub.cancel(); | ||
}); | ||
|
||
setUp(records.clear); | ||
|
||
test('empty', () async { | ||
var builder = jsonSerializable(BuilderOptions.empty) as PartBuilder; | ||
expect(builder, isNotNull); | ||
expect(records, isEmpty); | ||
}); | ||
|
||
test('valid config', () async { | ||
var builder = | ||
jsonSerializable(const BuilderOptions(_validConfig)) as PartBuilder; | ||
expect(builder, isNotNull); | ||
|
||
expect(records, isEmpty); | ||
}); | ||
|
||
test('unsupported configuration', () async { | ||
var builder = | ||
jsonSerializable(const BuilderOptions(const {'unsupported': 'config'})) | ||
as PartBuilder; | ||
expect(builder, isNotNull); | ||
|
||
expect(records.single.message, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't get how this is passing given my comment above... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as discussed... |
||
'These options were ignored: `{unsupported: config}`.'); | ||
}); | ||
|
||
group('invalid config', () { | ||
for (var entry in _invalidConfig.entries) { | ||
test(entry.key, () { | ||
var config = new Map<String, dynamic>.from(_validConfig); | ||
config[entry.key] = entry.value; | ||
|
||
expect(() => jsonSerializable(new BuilderOptions(config)), | ||
_throwsCastError); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Worth checking the actual message here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. They will all be 'String is not a bool' etc. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ya I was just wondering if you wanted to check the cast messages were correct, but its probably overkill |
||
}); | ||
} | ||
}); | ||
} | ||
|
||
const _validConfig = const { | ||
'header': 'header', | ||
'use_wrappers': true, | ||
'any_map': true | ||
}; | ||
|
||
const _invalidConfig = const { | ||
'header': true, | ||
'use_wrappers': 42, | ||
'any_map': 42 | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that since the logs come through asynchronously you would never see them at this point, you would need to add an
await null
or something along those lines. Not really sure the absolute best way to deal with it honestly.