2017-11-28 21:07:14 +00:00
|
|
|
import 'package:angel_route/angel_route.dart';
|
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
|
|
|
void main() {
|
2019-11-28 17:40:32 +00:00
|
|
|
var router = Router();
|
2017-11-28 21:07:14 +00:00
|
|
|
router.get('/songs/*/key', 'of life');
|
|
|
|
router.get('/isnt/she/*', 'lovely');
|
|
|
|
router.all('*', 'stevie');
|
|
|
|
|
|
|
|
test('match until end if * is last', () {
|
|
|
|
var result = router.resolveAbsolute('/wonder').first;
|
|
|
|
expect(result.handlers, ['stevie']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('match if not last', () {
|
|
|
|
var result = router.resolveAbsolute('/songs/what/key').first;
|
|
|
|
expect(result.handlers, ['of life']);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('match if segments before', () {
|
2018-08-20 19:34:00 +00:00
|
|
|
var result =
|
|
|
|
router.resolveAbsolute('/isnt/she/fierce%20harmonica%solo').first;
|
2017-11-28 21:07:14 +00:00
|
|
|
expect(result.handlers, ['lovely']);
|
|
|
|
});
|
2019-02-03 16:44:44 +00:00
|
|
|
|
|
|
|
test('tail explicitly set intermediate', () {
|
|
|
|
var results = router.resolveAbsolute('/songs/in_the/key');
|
|
|
|
var result = results.first;
|
2021-04-03 05:50:52 +00:00
|
|
|
print(results.map((r) => {r.route.path: r.tail}));
|
2019-02-03 16:44:44 +00:00
|
|
|
expect(result.tail, 'in_the');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('tail explicitly set at end', () {
|
|
|
|
var results = router.resolveAbsolute('/isnt/she/epic');
|
|
|
|
var result = results.first;
|
2021-04-03 05:50:52 +00:00
|
|
|
print(results.map((r) => {r.route.path: r.tail}));
|
2019-02-03 16:44:44 +00:00
|
|
|
expect(result.tail, 'epic');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('tail with trailing', () {
|
|
|
|
var results = router.resolveAbsolute('/isnt/she/epic/fail');
|
|
|
|
var result = results.first;
|
2021-04-03 05:50:52 +00:00
|
|
|
print(results.map((r) => {r.route.path: r.tail}));
|
2019-02-03 16:44:44 +00:00
|
|
|
expect(result.tail, 'epic/fail');
|
|
|
|
});
|
2018-08-20 19:34:00 +00:00
|
|
|
}
|