Stack Overflow now, haha
This commit is contained in:
parent
a9e4f6d4dc
commit
6dbccd2be6
5 changed files with 44 additions and 5 deletions
6
.idea/runConfigurations/Use.xml
Normal file
6
.idea/runConfigurations/Use.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Use" type="DartTestRunConfigurationType" factoryName="Dart Test" folderName="Router Tests" singleton="true">
|
||||
<option name="filePath" value="$PROJECT_DIR$/test/router/use.dart" />
|
||||
<method />
|
||||
</configuration>
|
||||
</component>
|
|
@ -217,6 +217,7 @@ class Route {
|
|||
|
||||
final route = new Route('$path1/$path2',
|
||||
children: child.children,
|
||||
debug: parent.debug || child.debug,
|
||||
handlers: child.handlers,
|
||||
method: child.method,
|
||||
name: child.name);
|
||||
|
@ -241,7 +242,7 @@ class Route {
|
|||
/// Adds the given route as a hierarchical child of this one.
|
||||
Route addChild(Route route, {bool join: true}) {
|
||||
Route created = join ? new Route.join(this, route) : route.._parent = this;
|
||||
return created;
|
||||
return created..debug = debug;
|
||||
}
|
||||
|
||||
/// Assigns a name to this route.
|
||||
|
|
|
@ -17,7 +17,7 @@ class Router extends Extensible {
|
|||
|
||||
/// Provide a `root` to make this Router revolve around a pre-defined route.
|
||||
/// Not recommended.
|
||||
Router([Route root]) : this.root = root ?? new Route('/', name: '<root>');
|
||||
Router([Route root]) : this.root = root ?? new _RootRoute();
|
||||
|
||||
void _printDebug(msg) {
|
||||
if (debug)
|
||||
|
@ -89,7 +89,7 @@ class Router extends Extensible {
|
|||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return result..debug = debug;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,10 @@ class Router extends Extensible {
|
|||
|
||||
void dumpRoute(Route route, {String replace: null}) {
|
||||
for (var i = 0; i < tabs; i++) buf.write(tab);
|
||||
buf.write('- ${route.method} ');
|
||||
|
||||
if (route == root)
|
||||
buf.write('(root) ${route.method} ');
|
||||
else buf.write('- ${route.method} ');
|
||||
|
||||
final p =
|
||||
replace != null ? route.path.replaceAll(replace, '') : route.path;
|
||||
|
@ -188,7 +191,7 @@ class Router extends Extensible {
|
|||
copiedMiddleware[middlewareName];
|
||||
}
|
||||
|
||||
root.addChild(router.root);
|
||||
root.child(path).addChild(router.root);
|
||||
}
|
||||
|
||||
/// Adds a route that responds to any request matching the given path.
|
||||
|
@ -231,3 +234,11 @@ class Router extends Extensible {
|
|||
return addRoute('PUT', path, handler, middleware: middleware);
|
||||
}
|
||||
}
|
||||
|
||||
class _RootRoute extends Route {
|
||||
_RootRoute():super("/", name: "<root>");
|
||||
|
||||
|
||||
@override
|
||||
String toString() => "ROOT";
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:angel_route/angel_route.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'fallback.dart' as fallback;
|
||||
import 'use.dart' as use;
|
||||
|
||||
final ABC = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
||||
|
||||
|
@ -44,4 +45,7 @@ main() {
|
|||
expect(router.resolve('letter/a/lower'), equals(lower));
|
||||
expect(router.resolve('letter/2/lower'), isNull);
|
||||
});
|
||||
|
||||
|
||||
test('use', use.main);
|
||||
}
|
||||
|
|
17
test/router/use.dart
Normal file
17
test/router/use.dart
Normal file
|
@ -0,0 +1,17 @@
|
|||
import 'package:angel_route/angel_route.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
main() {
|
||||
final parent = new Router()..debug = true;
|
||||
final child = new Router()..debug = true;
|
||||
final a = child.get('a', ['c']);
|
||||
parent.use('child', child);
|
||||
parent.dumpTree();
|
||||
|
||||
group('no params', () {
|
||||
test('resolve', () {
|
||||
expect(parent.resolve('child/a'), equals(a));
|
||||
expect(parent.resolve('a'), isNull);
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue