parser_test.dart 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import 'package:flutter_test/flutter_test.dart';
  2. import 'package:router/router.dart';
  3. void main() {
  4. testWidgets("Router correctly parses named parameters", (WidgetTester tester) async {
  5. String path = "/users/1234";
  6. String route = "/users/:id";
  7. Router router = new Router();
  8. router.define(route, handler: null);
  9. AppRouteMatch match = router.match(path);
  10. expect(match?.parameters, equals(<String, String>{
  11. "id" : "1234",
  12. }));
  13. });
  14. testWidgets("Router correctly parses named parameters with query", (WidgetTester tester) async {
  15. String path = "/users/1234?name=luke";
  16. String route = "/users/:id";
  17. Router router = new Router();
  18. router.define(route, handler: null);
  19. AppRouteMatch match = router.match(path);
  20. expect(match?.parameters, equals(<String, String>{
  21. "id" : "1234",
  22. "name" : "luke",
  23. }));
  24. });
  25. testWidgets("Router correctly parses query parameters", (WidgetTester tester) async {
  26. String path = "/users/create?name=luke&phrase=hello%20world&number=7";
  27. String route = "/users/create";
  28. Router router = new Router();
  29. router.define(route, handler: null);
  30. AppRouteMatch match = router.match(path);
  31. expect(match?.parameters, equals(<String, String>{
  32. "name" : "luke",
  33. "phrase" : "hello world",
  34. "number" : "7",
  35. }));
  36. });
  37. }