platform/test/router/all_tests.dart

46 lines
1.4 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-12 17:58:32 +00:00
final ABC = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
main() {
final router = new Router();
final indexRoute = router.get('/', () => ':)');
final userById = router.delete('/user/:id/detail', (id) => num.parse(id));
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();
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-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(userById));
});
test('resolve', () {
expect(router.resolve('/'), equals(indexRoute));
expect(router.resolve('user/1337/detail'), equals(userById));
expect(router.resolve('/user/1337/detail'), equals(userById));
expect(router.resolve('letter/a/lower'), equals(lower));
expect(router.resolve('letter/2/lower'), isNull);
});
}