platform/test/router/all_tests.dart

43 lines
1.3 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';
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', () {
router.two = 2;
expect(router.properties['two'], equals(2));
});
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);
});
}