parser_test.dart 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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, List<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, List<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, List<String>>{
  39. "name" : ["luke"],
  40. "phrase" : ["hello world"],
  41. "number" : ["7"],
  42. }));
  43. });
  44. testWidgets("Router correctly parses array parameters", (WidgetTester tester) async {
  45. String path = "/users/create?name=luke&phrase=hello%20world&number=7&number=10&number=13";
  46. String route = "/users/create";
  47. Router router = new Router();
  48. router.define(route, handler: null);
  49. AppRouteMatch match = router.match(path);
  50. expect(match?.parameters, equals(<String, List<String>>{
  51. "name" : ["luke"],
  52. "phrase" : ["hello world"],
  53. "number" : ["7", "10", "13"],
  54. }));
  55. });
  56. }