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() {
|
2016-10-15 00:45:22 +00:00
|
|
|
final fooById = new Route.build('/foo/:id([0-9]+)', handlers: ['bar']);
|
|
|
|
final foo = fooById.parent;
|
|
|
|
final bar = fooById.child('bar');
|
2016-10-13 20:50:27 +00:00
|
|
|
final baz = bar.child('//////baz//////', handlers: ['hello', 'world']);
|
2016-10-15 00:45:22 +00:00
|
|
|
final bazById = baz.child(':bazId');
|
2016-10-14 03:07:34 +00:00
|
|
|
new Router(foo).dumpTree();
|
2016-10-13 20:50:27 +00:00
|
|
|
|
|
|
|
test('matching', () {
|
2016-10-15 00:45:22 +00:00
|
|
|
expect(fooById.children.length, equals(1));
|
|
|
|
expect(fooById.handlers.length, equals(1));
|
|
|
|
expect(fooById.handlerSequence.length, equals(1));
|
|
|
|
expect(fooById.path, equals('foo/:id'));
|
|
|
|
expect(fooById.match('/foo/2'), isNotNull);
|
|
|
|
expect(fooById.match('/foo/aaa'), isNull);
|
|
|
|
expect(fooById.match('/bar'), isNull);
|
|
|
|
expect(fooById.match('/foolish'), isNull);
|
|
|
|
expect(fooById.parent, equals(foo));
|
|
|
|
expect(fooById.absoluteParent, equals(foo));
|
2016-10-13 20:50:27 +00:00
|
|
|
|
|
|
|
expect(bar.path, equals('foo/:id/bar'));
|
|
|
|
expect(bar.children.length, equals(1));
|
|
|
|
expect(bar.handlers, isEmpty);
|
|
|
|
expect(bar.handlerSequence.length, equals(1));
|
|
|
|
expect(bar.match('/foo/2/bar'), isNotNull);
|
|
|
|
expect(bar.match('/bar'), isNull);
|
|
|
|
expect(bar.match('/foo/a/bar'), isNull);
|
2016-10-15 00:45:22 +00:00
|
|
|
expect(bar.parent, equals(fooById));
|
|
|
|
expect(baz.absoluteParent, equals(foo));
|
2016-10-13 20:50:27 +00:00
|
|
|
|
2016-10-15 00:45:22 +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('foo/:id/bar/baz'));
|
|
|
|
expect(baz.match('/foo/2A/bar/baz'), isNull);
|
|
|
|
expect(baz.match('/foo/2/bar/baz'), isNotNull);
|
|
|
|
expect(baz.match('/foo/1337/bar/baz'), isNotNull);
|
|
|
|
expect(baz.match('/foo/bat/baz'), isNull);
|
|
|
|
expect(baz.match('/foo/bar/baz/1'), isNull);
|
|
|
|
expect(baz.parent, equals(bar));
|
2016-10-15 00:45:22 +00:00
|
|
|
expect(baz.absoluteParent, equals(foo));
|
2016-10-13 20:50:27 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('hierarchy', () {
|
2016-10-15 00:45:22 +00:00
|
|
|
expect(fooById.resolve('/foo/2'), equals(fooById));
|
2016-10-13 20:50:27 +00:00
|
|
|
|
2016-10-15 00:45:22 +00:00
|
|
|
expect(fooById.resolve('/foo/2/bar'), equals(bar));
|
|
|
|
expect(fooById.resolve('/foo/bar'), isNull);
|
|
|
|
expect(fooById.resolve('/foo/a/bar'), isNull);
|
|
|
|
expect(fooById.resolve('foo/1337/bar/baz'), equals(baz));
|
2016-10-13 20:50:27 +00:00
|
|
|
|
2016-10-15 00:45:22 +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));
|
2016-10-15 00:45:22 +00:00
|
|
|
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));
|
2016-10-15 00:45:22 +00:00
|
|
|
expect(baz.resolve('/2/bar'), equals(bar));
|
|
|
|
expect(baz.resolve('/1337/bar/baz'), equals(baz));
|
|
|
|
|
|
|
|
expect(bar.resolve('/2/baz/e'), equals(bazById));
|
|
|
|
expect(bar.resolve('baz/e'), equals(bazById));
|
|
|
|
expect(bar.resolve('baz/e'), isNull);
|
|
|
|
expect(fooById.resolve('/foo/2/baz/e'), equals(bazById));
|
|
|
|
expect(fooById.resolve('/foo/2/baz/2'), isNull);
|
|
|
|
expect(fooById.resolve('/foo/2a/baz/e'), isNull);
|
2016-10-13 20:50:27 +00:00
|
|
|
});
|
|
|
|
}
|