@@ -6,15 +6,41 @@ import {
66} from "./key-matching" ;
77
88describe ( "matchesKeyPattern" , ( ) => {
9- it ( "should match keys with prefix matching" , ( ) => {
9+ it ( "should match keys with separator-bounded prefix matching" , ( ) => {
1010 const patterns = [ "api" , "settings" ] ;
1111
1212 expect ( matchesKeyPattern ( "api/users" , patterns ) ) . toBe ( true ) ;
1313 expect ( matchesKeyPattern ( "api/posts" , patterns ) ) . toBe ( true ) ;
14+ expect ( matchesKeyPattern ( "api.users" , patterns ) ) . toBe ( true ) ;
1415 expect ( matchesKeyPattern ( "settings/theme" , patterns ) ) . toBe ( true ) ;
16+ expect ( matchesKeyPattern ( "settings.theme" , patterns ) ) . toBe ( true ) ;
1517 expect ( matchesKeyPattern ( "other/key" , patterns ) ) . toBe ( false ) ;
1618 } ) ;
1719
20+ it ( "should match exact keys" , ( ) => {
21+ const patterns = [ "inbox" ] ;
22+
23+ expect ( matchesKeyPattern ( "inbox" , patterns ) ) . toBe ( true ) ;
24+ } ) ;
25+
26+ it ( "should not match keys that share a prefix but lack a separator" , ( ) => {
27+ const patterns = [ "inbox" ] ;
28+
29+ expect ( matchesKeyPattern ( "inbox_url" , patterns ) ) . toBe ( false ) ;
30+ expect ( matchesKeyPattern ( "inbox_empty_title" , patterns ) ) . toBe ( false ) ;
31+ expect ( matchesKeyPattern ( "inbox_empty_body" , patterns ) ) . toBe ( false ) ;
32+ expect ( matchesKeyPattern ( "inboxes" , patterns ) ) . toBe ( false ) ;
33+ } ) ;
34+
35+ it ( "should match keys with dot, slash, or dash separator after pattern" , ( ) => {
36+ const patterns = [ "inbox" ] ;
37+
38+ expect ( matchesKeyPattern ( "inbox.title" , patterns ) ) . toBe ( true ) ;
39+ expect ( matchesKeyPattern ( "inbox/details" , patterns ) ) . toBe ( true ) ;
40+ expect ( matchesKeyPattern ( "inbox-0" , patterns ) ) . toBe ( true ) ;
41+ expect ( matchesKeyPattern ( "inbox.nested.key" , patterns ) ) . toBe ( true ) ;
42+ } ) ;
43+
1844 it ( "should match keys with glob patterns" , ( ) => {
1945 const patterns = [ "api/*/users" , "settings/*" ] ;
2046
0 commit comments