parser_test.dart 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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",
  12. (WidgetTester tester) async {
  13. String path = "/users/1234";
  14. String route = "/users/:id";
  15. Router router = new Router();
  16. router.define(route, handler: null);
  17. AppRouteMatch match = router.match(path);
  18. expect(
  19. match?.parameters,
  20. equals(<String, List<String>>{
  21. "id": ["1234"],
  22. }));
  23. });
  24. testWidgets("Router correctly parses named parameters with query",
  25. (WidgetTester tester) async {
  26. String path = "/users/1234?name=luke";
  27. String route = "/users/:id";
  28. Router router = new Router();
  29. router.define(route, handler: null);
  30. AppRouteMatch match = router.match(path);
  31. expect(
  32. match?.parameters,
  33. equals(<String, List<String>>{
  34. "id": ["1234"],
  35. "name": ["luke"],
  36. }));
  37. });
  38. testWidgets("Router correctly parses query parameters",
  39. (WidgetTester tester) async {
  40. String path = "/users/create?name=luke&phrase=hello%20world&number=7";
  41. String route = "/users/create";
  42. Router router = new Router();
  43. router.define(route, handler: null);
  44. AppRouteMatch match = router.match(path);
  45. expect(
  46. match?.parameters,
  47. equals(<String, List<String>>{
  48. "name": ["luke"],
  49. "phrase": ["hello world"],
  50. "number": ["7"],
  51. }));
  52. });
  53. testWidgets("Router correctly parses array parameters",
  54. (WidgetTester tester) async {
  55. String path =
  56. "/users/create?name=luke&phrase=hello%20world&number=7&number=10&number=13";
  57. String route = "/users/create";
  58. Router router = new Router();
  59. router.define(route, handler: null);
  60. AppRouteMatch match = router.match(path);
  61. expect(
  62. match?.parameters,
  63. equals(<String, List<String>>{
  64. "name": ["luke"],
  65. "phrase": ["hello world"],
  66. "number": ["7", "10", "13"],
  67. }));
  68. });
  69. }