platform/test/router/all_tests.dart

51 lines
1.6 KiB
Dart
Raw Normal View History

2016-10-12 17:58:32 +00:00
import 'package:angel_route/angel_route.dart';
import 'package:test/test.dart';
2016-10-13 20:50:27 +00:00
import 'fallback.dart' as fallback;
2016-10-20 09:21:59 +00:00
import 'use.dart' as use;
2016-10-12 17:58:32 +00:00
final ABC = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
main() {
final router = new Router();
final indexRoute = router.get('/', () => ':)');
final fizz = router.post('/user/fizz', null);
2016-10-21 03:13:13 +00:00
final deleteUserById =
router.delete('/user/:id/detail', (id) => num.parse(id));
2016-10-12 17:58:32 +00:00
Route lower;
final letters = router.group('/letter///', (router) {
lower = router
.get('/:id([A-Za-z])', (id) => ABC.indexOf(id[0]))
.child('////lower', handlers: [(String id) => id.toLowerCase()[0]]);
lower.parent
.child('/upper', handlers: [(String id) => id.toUpperCase()[0]]);
});
router.dumpTree(header: "ROUTER TESTS");
2016-10-12 17:58:32 +00:00
test('extensible', () {
2016-10-13 20:50:27 +00:00
router['two'] = 2;
expect(router.two, equals(2));
2016-10-12 17:58:32 +00:00
});
2016-10-13 20:50:27 +00:00
group('fallback', fallback.main);
2016-10-21 03:13:13 +00:00
test('group & use', use.main);
2016-10-13 20:50:27 +00:00
2016-10-12 17:58:32 +00:00
test('hierarchy', () {
expect(lower.absoluteParent, equals(router.root));
expect(lower.parent.path, equals('letter/:id'));
expect(lower.resolve('../upper').path, equals('letter/:id/upper'));
expect(lower.resolve('/user/34/detail'), equals(deleteUserById));
expect(deleteUserById.resolve('../../fizz'), equals(fizz));
2016-10-12 17:58:32 +00:00
});
test('resolve', () {
expect(router.resolve('/'), equals(indexRoute));
expect(router.resolve('user/1337/detail'), equals(deleteUserById));
expect(router.resolve('/user/1337/detail'), equals(deleteUserById));
2016-10-12 17:58:32 +00:00
expect(router.resolve('letter/a/lower'), equals(lower));
expect(router.resolve('letter/2/lower'), isNull);
});
}