Skip to content

Commit cebc442

Browse files
committed
fix(patterns): Allow matches(nonKey, key) to reject successfully
1 parent 0a761a4 commit cebc442

File tree

2 files changed

+15
-47
lines changed

2 files changed

+15
-47
lines changed

packages/patterns/src/patterns/patternMatchers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ const makePatternKit = () => {
270270
* @returns {boolean}
271271
*/
272272
const checkAsKeyPatt = (specimen, keyAsPattern, check) => {
273-
if (keyEQ(specimen, keyAsPattern)) {
273+
if (isKey(specimen) && keyEQ(specimen, keyAsPattern)) {
274274
return true;
275275
}
276276
return (

packages/patterns/test/test-patterns.js

+14-46
Original file line numberDiff line numberDiff line change
@@ -525,20 +525,13 @@ const runTests = (successCase, failCase) => {
525525
continue;
526526
}
527527
// This specimen is not a Key, so testing is less straightforward.
528-
if (method === 'scalar' || method === 'key') {
528+
if (method === 'scalar' || method === 'key' || method === 'null') {
529529
successCase(specimen, M.not(M[method]()));
530530
failCase(
531531
specimen,
532532
M[method](),
533533
makeMessage('"[mysteryTag]"', 'mysteryTag', 'tagged'),
534534
);
535-
} else if (method === 'null') {
536-
failCase(
537-
specimen,
538-
M[method](),
539-
simpleMethods.key('"[mysteryTag]"', 'mysteryTag', 'tagged'),
540-
true,
541-
);
542535
} else {
543536
failCase(
544537
specimen,
@@ -557,21 +550,12 @@ const runTests = (successCase, failCase) => {
557550
continue;
558551
}
559552
// This specimen is not a Key, so testing is less straightforward.
560-
if (method !== 'null') {
561-
successCase(specimen, M.not(M[method]()));
562-
failCase(
563-
specimen,
564-
M[method](),
565-
makeMessage('"[match:any]"', 'match:any', 'tagged'),
566-
);
567-
} else {
568-
failCase(
569-
specimen,
570-
M[method](),
571-
simpleMethods.key('"[match:any]"', 'match:any', 'tagged'),
572-
true,
573-
);
574-
}
553+
successCase(specimen, M.not(M[method]()));
554+
failCase(
555+
specimen,
556+
M[method](),
557+
makeMessage('"[match:any]"', 'match:any', 'tagged'),
558+
);
575559
}
576560
}
577561
{
@@ -583,21 +567,12 @@ const runTests = (successCase, failCase) => {
583567
continue;
584568
}
585569
// This specimen has an invalid payload for its tag, so testing is less straightforward.
586-
if (method !== 'null') {
587-
const message =
588-
method === 'scalar' || method === 'key'
589-
? makeMessage('"[match:any]"', 'match:any', 'tagged')
590-
: 'match:any payload: 88 - Must be undefined';
591-
successCase(specimen, M.not(M[method]()));
592-
failCase(specimen, M[method](), message);
593-
} else {
594-
failCase(
595-
specimen,
596-
M[method](),
597-
simpleMethods.key('"[match:any]"', 'match:any', 'tagged'),
598-
true,
599-
);
600-
}
570+
const message =
571+
method === 'scalar' || method === 'key' || method === 'null'
572+
? makeMessage('"[match:any]"', 'match:any', 'tagged')
573+
: 'match:any payload: 88 - Must be undefined';
574+
successCase(specimen, M.not(M[method]()));
575+
failCase(specimen, M[method](), message);
601576
}
602577
}
603578
{
@@ -609,20 +584,13 @@ const runTests = (successCase, failCase) => {
609584
continue;
610585
}
611586
// This specimen is not a Key, so testing is less straightforward.
612-
if (method === 'scalar' || method === 'key') {
587+
if (method === 'scalar' || method === 'key' || method === 'null') {
613588
successCase(specimen, M.not(M[method]()));
614589
failCase(
615590
specimen,
616591
M[method](),
617592
makeMessage('"[match:remotable]"', 'match:remotable', 'tagged'),
618593
);
619-
} else if (method === 'null') {
620-
failCase(
621-
specimen,
622-
M[method](),
623-
simpleMethods.key('"[match:remotable]"', 'match:remotable', 'tagged'),
624-
true,
625-
);
626594
} else {
627595
failCase(
628596
specimen,

0 commit comments

Comments
 (0)