platform/test/router/use.dart

36 lines
992 B
Dart
Raw Normal View History

2016-10-20 09:21:59 +00:00
import 'package:angel_route/angel_route.dart';
import 'package:test/test.dart';
2016-10-21 03:13:13 +00:00
final String ARTIFICIAL_INDEX = 'artificial index';
tattle(x) => 'This ${x.runtimeType}.debug = ${x.debug}';
tattleAll(x) => x.map(tattle).join('\n');
2016-10-20 09:21:59 +00:00
main() {
2016-10-21 03:13:13 +00:00
final parent = new Router(debug: true);
final child = new Router(debug: true);
Route a, b, c;
a = child.get('a', ['c']);
child.group('b', (router) {
b = router.get('/', ARTIFICIAL_INDEX);
c = router.post('c', 'Hello nested');
});
2016-10-22 15:21:04 +00:00
parent.mount('child', child);
2016-10-21 03:13:13 +00:00
parent.dumpTree(header: tattleAll([parent, child, a]));
2016-10-20 09:21:59 +00:00
group('no params', () {
test('resolve', () {
2016-10-21 03:13:13 +00:00
expect(child.resolve('a'), equals(a));
expect(child.resolve('b'), equals(b));
expect(child.resolve('b/c'), equals(c));
2016-10-20 09:21:59 +00:00
expect(parent.resolve('child/a'), equals(a));
expect(parent.resolve('a'), isNull);
2016-10-21 03:13:13 +00:00
expect(parent.resolve('child/b'), equals(b));
expect(parent.resolve('child/b/c'), equals(c));
2016-10-20 09:21:59 +00:00
});
});
}