From 1521ba8691a7d1a6f5680420126c60907feb8d5d Mon Sep 17 00:00:00 2001 From: Andreas Haller Date: Tue, 11 Jun 2024 23:12:16 +0200 Subject: [PATCH] Add failing test about conflicting routes --- test/lib/lennarb/test_route_node.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/lib/lennarb/test_route_node.rb b/test/lib/lennarb/test_route_node.rb index 0320f68..6f1c5ba 100644 --- a/test/lib/lennarb/test_route_node.rb +++ b/test/lib/lennarb/test_route_node.rb @@ -41,5 +41,22 @@ def test_match_invalid_route assert_nil block assert_nil params end + + def test_different_variables_in_common_nested_routes + router = Lennarb::RouteNode.new + router.add_route(['foo', ':foo'], 'GET', proc { 'foo' }) + router.add_route(%w[foo special], 'GET', proc { 'special' }) + router.add_route(['foo', ':id', 'bar'], 'GET', proc { 'bar' }) + + _, params = router.match_route(%w[foo 23], 'GET') + + assert_equal({ foo: '23' }, params) + _, params = router.match_route(%w[foo special], 'GET') + + assert_empty(params) + _, params = router.match_route(%w[foo 24 bar], 'GET') + + assert_equal({ id: '24' }, params) + end end end