parser_test.dart 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * fluro
  3. * Created by Yakka
  4. * https://theyakka.com
  5. *
  6. * Copyright (c) 2019 Yakka, LLC. All rights reserved.
  7. * See LICENSE for distribution and usage details.
  8. */
  9. import 'package:flutter_test/flutter_test.dart';
  10. import 'package:fluro/fluro.dart';
  11. void main() {
  12. test("FluroRouter correctly parses named parameters", () async {
  13. String path = "/users/1234";
  14. String route = "/users/:id";
  15. FluroRouter router = FluroRouter();
  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. test("FluroRouter correctly parses named parameters with query", () async {
  25. String path = "/users/1234?name=luke";
  26. String route = "/users/:id";
  27. FluroRouter router = FluroRouter();
  28. router.define(route, handler: null);
  29. AppRouteMatch? match = router.match(path);
  30. expect(
  31. match?.parameters,
  32. equals(<String, List<String>>{
  33. "id": ["1234"],
  34. "name": ["luke"],
  35. }));
  36. });
  37. test("FluroRouter correctly parses query parameters", () async {
  38. String path = "/users/create?name=luke&phrase=hello%20world&number=7";
  39. String route = "/users/create";
  40. FluroRouter router = FluroRouter();
  41. router.define(route, handler: null);
  42. AppRouteMatch? match = router.match(path);
  43. expect(
  44. match?.parameters,
  45. equals(<String, List<String>>{
  46. "name": ["luke"],
  47. "phrase": ["hello world"],
  48. "number": ["7"],
  49. }));
  50. });
  51. test("FluroRouter correctly parses array parameters", () async {
  52. String path =
  53. "/users/create?name=luke&phrase=hello%20world&number=7&number=10&number=13";
  54. String route = "/users/create";
  55. FluroRouter router = FluroRouter();
  56. router.define(route, handler: null);
  57. AppRouteMatch? match = router.match(path);
  58. expect(
  59. match?.parameters,
  60. equals(<String, List<String>>{
  61. "name": ["luke"],
  62. "phrase": ["hello world"],
  63. "number": ["7", "10", "13"],
  64. }));
  65. });
  66. test("FluroRouter correctly matches route and transition type", () async {
  67. String path = "/users/1234";
  68. String route = "/users/:id";
  69. FluroRouter router = FluroRouter();
  70. router.define(route,
  71. handler: null, transitionType: TransitionType.inFromRight);
  72. AppRouteMatch? match = router.match(path);
  73. expect(TransitionType.inFromRight, match?.route.transitionType);
  74. });
  75. }