fluro/test/parser_test.dart

42 lines
1.3 KiB
Dart
Raw Normal View History

import 'package:flutter_test/flutter_test.dart';
2017-05-14 00:39:50 -04:00
import 'package:fluro/router.dart';
void main() {
testWidgets("Router correctly parses named parameters", (WidgetTester tester) async {
String path = "/users/1234";
String route = "/users/:id";
Router router = new Router();
router.define(route, handler: null);
AppRouteMatch match = router.match(path);
expect(match?.parameters, equals(<String, String>{
"id" : "1234",
}));
});
testWidgets("Router correctly parses named parameters with query", (WidgetTester tester) async {
String path = "/users/1234?name=luke";
String route = "/users/:id";
Router router = new Router();
router.define(route, handler: null);
AppRouteMatch match = router.match(path);
expect(match?.parameters, equals(<String, String>{
"id" : "1234",
"name" : "luke",
}));
});
testWidgets("Router correctly parses query parameters", (WidgetTester tester) async {
String path = "/users/create?name=luke&phrase=hello%20world&number=7";
String route = "/users/create";
Router router = new Router();
router.define(route, handler: null);
AppRouteMatch match = router.match(path);
expect(match?.parameters, equals(<String, String>{
"name" : "luke",
"phrase" : "hello world",
"number" : "7",
}));
});
}