parser_test.dart 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * fluro
  3. * A Posse Production
  4. * http://goposse.com
  5. * Copyright (c) 2018 Posse Productions LLC. All rights reserved.
  6. * See LICENSE for distribution and usage details.
  7. */
  8. import 'package:flutter_test/flutter_test.dart';
  9. import 'package:fluro/fluro.dart';
  10. void main() {
  11. testWidgets("Router correctly parses named parameters", (WidgetTester tester) async {
  12. String path = "/users/1234";
  13. String route = "/users/:id";
  14. Router router = new Router();
  15. router.define(route, handler: null);
  16. AppRouteMatch match = router.match(path);
  17. expect(match?.parameters, equals(<String, String>{
  18. "id" : "1234",
  19. }));
  20. });
  21. testWidgets("Router correctly parses named parameters with query", (WidgetTester tester) async {
  22. String path = "/users/1234?name=luke";
  23. String route = "/users/:id";
  24. Router router = new Router();
  25. router.define(route, handler: null);
  26. AppRouteMatch match = router.match(path);
  27. expect(match?.parameters, equals(<String, String>{
  28. "id" : "1234",
  29. "name" : "luke",
  30. }));
  31. });
  32. testWidgets("Router correctly parses query parameters", (WidgetTester tester) async {
  33. String path = "/users/create?name=luke&phrase=hello%20world&number=7";
  34. String route = "/users/create";
  35. Router router = new Router();
  36. router.define(route, handler: null);
  37. AppRouteMatch match = router.match(path);
  38. expect(match?.parameters, equals(<String, String>{
  39. "name" : "luke",
  40. "phrase" : "hello world",
  41. "number" : "7",
  42. }));
  43. });
  44. }