Add parse ID tests
This commit is contained in:
parent
47261f0a08
commit
3802668cfc
3 changed files with 35 additions and 1 deletions
|
@ -5,6 +5,7 @@
|
|||
* Deprecated `app.isProduction` in favor of `app.environment.isProduction`.
|
||||
* Allow setting of `bodyAsObject`, `bodyAsMap`, or `bodyAsList` **exactly once**.
|
||||
* Resolve named singletons in `resolveInjection`.
|
||||
* Fix a bug where `Service.parseId<double>` would attempt to parse an `int`.
|
||||
|
||||
# 2.0.0-alpha.24
|
||||
* Add `AngelEnv` class to `core`.
|
||||
|
|
|
@ -177,7 +177,7 @@ class Service<Id, Data> extends Routable {
|
|||
else if (T == bool)
|
||||
return (id == true || id?.toString() == 'true') as T;
|
||||
else if (T == double)
|
||||
return int.parse(id.toString()) as T;
|
||||
return double.parse(id.toString()) as T;
|
||||
else if (T == num)
|
||||
return num.parse(id.toString()) as T;
|
||||
else
|
||||
|
|
33
test/parse_id_test.dart
Normal file
33
test/parse_id_test.dart
Normal file
|
@ -0,0 +1,33 @@
|
|||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
test('null', () {
|
||||
expect(Service.parseId('null'), null);
|
||||
expect(Service.parseId(null), null);
|
||||
});
|
||||
|
||||
test('String', () {
|
||||
expect(Service.parseId('23'), '23');
|
||||
});
|
||||
|
||||
test('int', () {
|
||||
expect(Service.parseId<int>('23'), 23);
|
||||
});
|
||||
|
||||
test('double', () {
|
||||
expect(Service.parseId<double>('23.4'), 23.4);
|
||||
});
|
||||
|
||||
test('num', () {
|
||||
expect(Service.parseId<num>('23.4'), 23.4);
|
||||
});
|
||||
|
||||
test('bool', () {
|
||||
expect(Service.parseId<bool>('true'), true);
|
||||
expect(Service.parseId<bool>(true), true);
|
||||
expect(Service.parseId<bool>('false'), false);
|
||||
expect(Service.parseId<bool>(false), false);
|
||||
expect(Service.parseId<bool>('hmm'), false);
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue