| 2745 | } |
| 2746 | |
| 2747 | func TestRoutes_Reverse(t *testing.T) { |
| 2748 | var testCases = []struct { |
| 2749 | name string |
| 2750 | when string |
| 2751 | expect string |
| 2752 | expectErr string |
| 2753 | whenArgs []any |
| 2754 | }{ |
| 2755 | { |
| 2756 | name: "ok, static", |
| 2757 | when: "/static", |
| 2758 | expect: "/static", |
| 2759 | }, |
| 2760 | { |
| 2761 | name: "ok, static + args", |
| 2762 | when: "/static", |
| 2763 | whenArgs: []any{"missing param"}, |
| 2764 | expect: "/static", |
| 2765 | }, |
| 2766 | { |
| 2767 | name: "ok, static/*", |
| 2768 | when: "/static/*", |
| 2769 | expect: "/static/*", |
| 2770 | }, |
| 2771 | { |
| 2772 | name: "ok, static/*", |
| 2773 | when: "/static/*", |
| 2774 | whenArgs: []any{"foo.txt"}, |
| 2775 | expect: "/static/foo.txt", |
| 2776 | }, |
| 2777 | { |
| 2778 | name: "ok, /params/:foo", |
| 2779 | when: "/params/:foo", |
| 2780 | expect: "/params/:foo", |
| 2781 | }, |
| 2782 | { |
| 2783 | name: "ok, /params/:foo + args", |
| 2784 | when: "/params/:foo", |
| 2785 | whenArgs: []any{"one"}, |
| 2786 | expect: "/params/one", |
| 2787 | }, |
| 2788 | { |
| 2789 | name: "ok, /params/:foo/bar/:qux", |
| 2790 | when: "/params/:foo/bar/:qux", |
| 2791 | expect: "/params/:foo/bar/:qux", |
| 2792 | }, |
| 2793 | { |
| 2794 | name: "ok, /params/:foo/bar/:qux + args1", |
| 2795 | when: "/params/:foo/bar/:qux", |
| 2796 | whenArgs: []any{"one"}, |
| 2797 | expect: "/params/one/bar/:qux", |
| 2798 | }, |
| 2799 | { |
| 2800 | name: "ok, /params/:foo/bar/:qux + args2", |
| 2801 | when: "/params/:foo/bar/:qux", |
| 2802 | whenArgs: []any{"one", "two"}, |
| 2803 | expect: "/params/one/bar/two", |
| 2804 | }, |