2024-09-25 04:04:57 +00:00
|
|
|
import 'package:platform_route/route.dart';
|
2024-09-23 01:46:14 +00:00
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
final router = Router();
|
|
|
|
|
|
|
|
router.get('/', 'GET').name = 'root';
|
|
|
|
router.get('/user/:id', 'GET');
|
|
|
|
router.get('/first/:first/last/:last', 'GET').name = 'full_name';
|
|
|
|
|
|
|
|
String navigate(params) {
|
|
|
|
final uri = router.navigate(params as Iterable);
|
|
|
|
print('Uri: $uri');
|
|
|
|
return uri;
|
|
|
|
}
|
|
|
|
|
|
|
|
router.dumpTree();
|
|
|
|
|
|
|
|
group('top-level', () {
|
|
|
|
test('named', () {
|
|
|
|
expect(navigate(['root']), equals('/'));
|
|
|
|
});
|
|
|
|
|
|
|
|
test('params', () {
|
|
|
|
expect(
|
|
|
|
navigate([
|
|
|
|
'user/:id',
|
|
|
|
{'id': 1337}
|
|
|
|
]),
|
|
|
|
equals('/user/1337'));
|
|
|
|
|
|
|
|
expect(
|
|
|
|
navigate([
|
|
|
|
'full_name',
|
|
|
|
{'first': 'John', 'last': 'Smith'}
|
|
|
|
]),
|
|
|
|
equals('/first/John/last/Smith'));
|
|
|
|
});
|
|
|
|
|
|
|
|
test('root', () {
|
|
|
|
expect(navigate(['/']), equals('/'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|