Skip to content

Commit c81f3c2

Browse files
committed
Add tests for reversed matching priority
1 parent 5e67eaf commit c81f3c2

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/lib.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,39 @@ fn star() {
347347
assert_eq!(m.params, params("foo", "foo"));
348348
}
349349

350+
#[test]
351+
fn star_colon() {
352+
let mut router = Router::new();
353+
354+
router.add("/a/*b", "ab".to_string());
355+
router.add("/a/*b/c", "abc".to_string());
356+
router.add("/a/*b/c/:d", "abcd".to_string());
357+
358+
let m = router.recognize("/a/foo").unwrap();
359+
assert_eq!(*m.handler, "ab".to_string());
360+
assert_eq!(m.params, params("b", "foo"));
361+
362+
let m = router.recognize("/a/foo/bar").unwrap();
363+
assert_eq!(*m.handler, "ab".to_string());
364+
assert_eq!(m.params, params("b", "foo/bar"));
365+
366+
let m = router.recognize("/a/foo/c").unwrap();
367+
assert_eq!(*m.handler, "abc".to_string());
368+
assert_eq!(m.params, params("b", "foo"));
369+
370+
let m = router.recognize("/a/foo/bar/c").unwrap();
371+
assert_eq!(*m.handler, "abc".to_string());
372+
assert_eq!(m.params, params("b", "foo/bar"));
373+
374+
let m = router.recognize("/a/foo/c/baz").unwrap();
375+
assert_eq!(*m.handler, "abcd".to_string());
376+
assert_eq!(m.params, two_params("b", "foo", "d", "baz"));
377+
378+
let m = router.recognize("/a/foo/bar/c/baz").unwrap();
379+
assert_eq!(*m.handler, "abcd".to_string());
380+
assert_eq!(m.params, two_params("b", "foo/bar", "d", "baz"));
381+
}
382+
350383
#[test]
351384
fn unnamed_parameters() {
352385
let mut router = Router::new();

0 commit comments

Comments
 (0)