From 3802668cfcda543314ee616cb12ba60945afa43c Mon Sep 17 00:00:00 2001 From: Tobe O Date: Wed, 10 Apr 2019 19:05:53 -0400 Subject: [PATCH] Add parse ID tests --- CHANGELOG.md | 1 + lib/src/core/service.dart | 2 +- test/parse_id_test.dart | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 test/parse_id_test.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 15e3a178..3d8763e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` would attempt to parse an `int`. # 2.0.0-alpha.24 * Add `AngelEnv` class to `core`. diff --git a/lib/src/core/service.dart b/lib/src/core/service.dart index 7eb6d840..52104df0 100644 --- a/lib/src/core/service.dart +++ b/lib/src/core/service.dart @@ -177,7 +177,7 @@ class Service 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 diff --git a/test/parse_id_test.dart b/test/parse_id_test.dart new file mode 100644 index 00000000..7e427ec3 --- /dev/null +++ b/test/parse_id_test.dart @@ -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('23'), 23); + }); + + test('double', () { + expect(Service.parseId('23.4'), 23.4); + }); + + test('num', () { + expect(Service.parseId('23.4'), 23.4); + }); + + test('bool', () { + expect(Service.parseId('true'), true); + expect(Service.parseId(true), true); + expect(Service.parseId('false'), false); + expect(Service.parseId(false), false); + expect(Service.parseId('hmm'), false); + }); +}