Skip to content

Commit 4fce65e

Browse files
committed
docs(equiv-checker): more post-validation
1 parent 0718eb9 commit 4fce65e

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

equiv-checker.html

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -446,15 +446,6 @@ <h4>Powered by:</h4>
446446
anchorInfoBanner.style.display = 'none';
447447
}
448448

449-
function assertMatchRegex(regex, strings) {
450-
for (const str of strings) {
451-
if (!regex.test(str)) {
452-
return false;
453-
}
454-
}
455-
return true;
456-
}
457-
458449
// clear results on new input and update URL:
459450
regex1Input.addEventListener('input', () => {
460451
clearResults()
@@ -509,22 +500,23 @@ <h4>Powered by:</h4>
509500
} else if (diffABEmpty && !diffBAEmpty) {
510501
// A is subset of B: no strings in A that aren't in B
511502
const stringsMatchingBButNotA = Array.from(diffBA.enumerate().take(5));
512-
const hasValidationIssue = !assertMatchRegex(regexB, stringsMatchingBButNotA);
503+
const hasValidationIssue = !stringsMatchingBButNotA.every(str => regexB.test(str) && !regexA.test(str));
513504
const examples = stringsMatchingBButNotA.length > 0 ? {regex2Only: stringsMatchingBButNotA} : null;
514505
showResultWithDiagram('📊 RegExp 1 matches a subset of RegExp 2. Every string matched by RegExp 1 is also matched by RegExp 2, but not vice versa.', 'subset', examples, hasValidationIssue);
515506
} else if (!diffABEmpty && diffBAEmpty) {
516507
// B is subset of A: no strings in B that aren't in A
517508
const stringsMatchingAButNotB = Array.from(diffAB.enumerate().take(5));
518-
const hasValidationIssue = !assertMatchRegex(regexA, stringsMatchingAButNotB);
509+
const hasValidationIssue = !stringsMatchingAButNotB.every(str => regexA.test(str) && !regexB.test(str));
519510
const examples = stringsMatchingAButNotB.length > 0 ? {regex1Only: stringsMatchingAButNotB} : null;
520511
showResultWithDiagram('📊 RegExp 1 matches a superset of RegExp 2. Every string matched by RegExp 2 is also matched by RegExp 1, but not vice versa.', 'superset', examples, hasValidationIssue);
521512
} else {
522513
// Neither subset nor equivalent: both differences are non-empty
523514
const stringsMatchingAButNotB = Array.from(diffAB.enumerate().take(5));
524-
const hasValidationIssue1 = !assertMatchRegex(regexA, stringsMatchingAButNotB);
525515
const stringsMatchingBButNotA = Array.from(diffBA.enumerate().take(5));
526-
const hasValidationIssue2 = !assertMatchRegex(regexB, stringsMatchingBButNotA);
527-
const hasValidationIssue = hasValidationIssue1 || hasValidationIssue2;
516+
const hasValidationIssue = !(
517+
stringsMatchingAButNotB.every(str => regexA.test(str) && !regexB.test(str)) &&
518+
stringsMatchingBButNotA.every(str => regexB.test(str) && !regexA.test(str))
519+
);
528520
const examples = {
529521
regex1Only: stringsMatchingAButNotB.length > 0 ? stringsMatchingAButNotB : null,
530522
regex2Only: stringsMatchingBButNotA.length > 0 ? stringsMatchingBButNotA : null
@@ -585,7 +577,7 @@ <h4>Powered by:</h4>
585577

586578
// Add warning banner if there's a validation issue
587579
if (hasValidationIssue) {
588-
html += '<div class="mismatch-warning">Something went wrong. The presented example strings don\'t match the regex as claimed. Please create bug ticket on GitHub.</div>';
580+
html += '<div class="mismatch-warning">Something went wrong. The presented example strings don\'t match the regex as claimed. Please file an issue on GitHub with your input regex.</div>';
589581
}
590582

591583
html += message;

0 commit comments

Comments
 (0)