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-19 22:04:06 +00:00
|
|
|
final foo = new Router().root;
|
|
|
|
final fooById = foo.child(':id((?!bar)[0-9]+)', handlers: ['bar']);
|
2016-10-15 00:45:22 +00:00
|
|
|
final bar = fooById.child('bar');
|
2016-10-13 20:50:27 +00:00
|
|
|
final baz = bar.child('//////baz//////', handlers: ['hello', 'world']);
|
2016-10-19 22:04:06 +00:00
|
|
|
final bazById = baz.child(':bazId([A-Za-z]+)');
|
2016-10-21 03:13:13 +00:00
|
|
|
new Router(root: 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));
|
2016-10-19 22:04:06 +00:00
|
|
|
expect(fooById.path, equals(':id'));
|
|
|
|
expect(fooById.match('/2'), isNotNull);
|
|
|
|
expect(fooById.match('/aaa'), isNull);
|
2016-10-15 00:45:22 +00:00
|
|
|
expect(fooById.match('/bar'), isNull);
|
2016-10-19 22:04:06 +00:00
|
|
|
expect(fooById.match('lish'), isNull);
|
2016-10-15 00:45:22 +00:00
|
|
|
expect(fooById.parent, equals(foo));
|
|
|
|
expect(fooById.absoluteParent, equals(foo));
|
2016-10-13 20:50:27 +00:00
|
|
|
|
2016-10-19 22:04:06 +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));
|
2016-10-19 22:04:06 +00:00
|
|
|
expect(bar.match('/2/bar'), isNotNull);
|
2016-10-13 20:50:27 +00:00
|
|
|
expect(bar.match('/bar'), isNull);
|
2016-10-19 22:04:06 +00:00
|
|
|
expect(bar.match('/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));
|
2016-10-19 22:04:06 +00:00
|
|
|
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));
|
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-19 22:04:06 +00:00
|
|
|
expect(fooById.resolve('/2'), equals(fooById));
|
2016-10-13 20:50:27 +00:00
|
|
|
|
2016-10-19 22:04:06 +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
|
|
|
|
2016-10-15 00:45:22 +00:00
|
|
|
expect(bar.resolve('..'), equals(fooById));
|
|
|
|
|
2016-10-21 03:13:13 +00:00
|
|
|
new Router(root: bar.parent).dumpTree(header: "POOP");
|
2016-10-15 00:45:22 +00:00
|
|
|
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));
|
|
|
|
|
2016-10-19 22:04:06 +00:00
|
|
|
expect(bar.resolve('/2/bar/baz/e'), equals(bazById));
|
2016-10-15 00:45:22 +00:00
|
|
|
expect(bar.resolve('baz/e'), equals(bazById));
|
2016-10-19 22:04:06 +00:00
|
|
|
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
|
|
|
});
|
|
|
|
}
|