platform/test/route/with_params.dart

77 lines
2.9 KiB
Dart
Raw Normal View History

2016-10-13 20:50:27 +00:00
import 'package:angel_route/angel_route.dart';
import 'package:test/test.dart';
2016-10-12 17:58:32 +00:00
main() {
final foo = new Router().root;
final fooById = foo.child(':id((?!bar)[0-9]+)', handlers: ['bar']);
final bar = fooById.child('bar');
2016-10-13 20:50:27 +00:00
final baz = bar.child('//////baz//////', handlers: ['hello', 'world']);
final bazById = baz.child(':bazId([A-Za-z]+)');
2016-10-14 03:07:34 +00:00
new Router(foo).dumpTree();
2016-10-13 20:50:27 +00:00
test('matching', () {
expect(fooById.children.length, equals(1));
expect(fooById.handlers.length, equals(1));
expect(fooById.handlerSequence.length, equals(1));
expect(fooById.path, equals(':id'));
expect(fooById.match('/2'), isNotNull);
expect(fooById.match('/aaa'), isNull);
expect(fooById.match('/bar'), isNull);
expect(fooById.match('lish'), isNull);
expect(fooById.parent, equals(foo));
expect(fooById.absoluteParent, equals(foo));
2016-10-13 20:50:27 +00:00
expect(bar.path, equals(':id/bar'));
2016-10-13 20:50:27 +00:00
expect(bar.children.length, equals(1));
expect(bar.handlers, isEmpty);
expect(bar.handlerSequence.length, equals(1));
expect(bar.match('/2/bar'), isNotNull);
2016-10-13 20:50:27 +00:00
expect(bar.match('/bar'), isNull);
expect(bar.match('/a/bar'), isNull);
expect(bar.parent, equals(fooById));
expect(baz.absoluteParent, equals(foo));
2016-10-13 20:50:27 +00:00
expect(baz.children.length, equals(1));
2016-10-13 20:50:27 +00:00
expect(baz.handlers.length, equals(2));
expect(baz.handlerSequence.length, equals(3));
expect(baz.path, equals(':id/bar/baz'));
expect(baz.match('/2A/bar/baz'), isNull);
expect(baz.match('/2/bar/baz'), isNotNull);
expect(baz.match('/1337/bar/baz'), isNotNull);
expect(baz.match('/bat/baz'), isNull);
expect(baz.match('/bar/baz/1'), isNull);
2016-10-13 20:50:27 +00:00
expect(baz.parent, equals(bar));
expect(baz.absoluteParent, equals(foo));
2016-10-13 20:50:27 +00:00
});
test('hierarchy', () {
expect(fooById.resolve('/2'), equals(fooById));
2016-10-13 20:50:27 +00:00
expect(fooById.resolve('/2/bar'), equals(bar));
expect(fooById.resolve('/bar'), isNull);
expect(fooById.resolve('/a/bar'), isNull);
expect(fooById.resolve('1337/bar/baz'), equals(baz));
2016-10-13 20:50:27 +00:00
expect(bar.resolve('..'), equals(fooById));
new Router(bar.parent).dumpTree(header: "POOP");
expect(bar.parent.resolve('bar/baz'), equals(baz));
expect(bar.resolve('/2/bar/baz'), equals(baz));
2016-10-13 20:50:27 +00:00
expect(bar.resolve('../bar'), equals(bar));
2016-10-12 17:58:32 +00:00
2016-10-13 20:50:27 +00:00
expect(baz.resolve('..'), equals(bar));
expect(baz.resolve('../..'), equals(fooById));
2016-10-13 20:50:27 +00:00
expect(baz.resolve('../baz'), equals(baz));
expect(baz.resolve('../../bar'), equals(bar));
expect(baz.resolve('../../bar/baz'), equals(baz));
expect(baz.resolve('/2/bar'), equals(bar));
expect(baz.resolve('/1337/bar/baz'), equals(baz));
expect(bar.resolve('/2/bar/baz/e'), equals(bazById));
expect(bar.resolve('baz/e'), equals(bazById));
expect(fooById.resolve('/2/bar/baz/e'), equals(bazById));
expect(fooById.resolve('/2/bar/baz/2'), isNull);
expect(fooById.resolve('/2a/bar/baz/e'), isNull);
2016-10-13 20:50:27 +00:00
});
}