Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

2.9 KB
Raw Blame
<!doctype html>
<meta charset="utf-8">
<body>
<script src="/wpt/resources/testharness.js"></script>
<script src="/wpt/resources/testharnessreport.js"></script>
<script src="/wpt/resources/moli-wpt-adapter.js"></script>
<script>
function textInput(value, pattern) {
  const input = document.createElement("input");
  input.type = "text";
  input.value = value;
  input.pattern = pattern;
  document.body.appendChild(input);
  return input;
}

test(function () {
  const asciiLetters = textInput("Moli", "[\\p{Letter}&&\\p{ASCII}]+");
  assert_false(asciiLetters.validity.patternMismatch, "ASCII letters should satisfy an intersected Unicode set");
  assert_true(asciiLetters.validity.valid, "matching Unicode set pattern should keep the control valid");

  const nonAsciiLetter = textInput("cafe\u00e9", "[\\p{Letter}&&\\p{ASCII}]+");
  assert_true(nonAsciiLetter.validity.patternMismatch, "non-ASCII letters should be excluded by the ASCII intersection");
  assert_false(nonAsciiLetter.checkValidity(), "Unicode set mismatch should participate in checkValidity");
}, "patternMismatch supports Unicode set intersection under the v flag");

test(function () {
  const identifier = textInput("field_name", "[\\p{ASCII}--\\p{Decimal_Number}]+");
  assert_false(identifier.validity.patternMismatch, "ASCII non-decimal characters should satisfy a subtracted Unicode set");

  const withDigits = textInput("field1", "[\\p{ASCII}--\\p{Decimal_Number}]+");
  assert_true(withDigits.validity.patternMismatch, "decimal digits should be excluded by the subtracted Unicode set");
}, "patternMismatch supports Unicode set subtraction under the v flag");

test(function () {
  const consonants = textInput("rhythm", "[[a-z]--[aeiou]]+");
  assert_false(consonants.validity.patternMismatch, "nested class subtraction should accept lowercase consonants");

  const withVowel = textInput("rhythmical", "[[a-z]--[aeiou]]+");
  assert_true(withVowel.validity.patternMismatch, "nested class subtraction should reject excluded lowercase vowels");
}, "patternMismatch supports nested character class operands in Unicode set subtraction");

test(function () {
  const middleLetters = textInput("def", "[[a-z]&&[d-f]]+");
  assert_false(middleLetters.validity.patternMismatch, "nested class intersection should accept characters in both operands");

  const outsideIntersection = textInput("abc", "[[a-z]&&[d-f]]+");
  assert_true(outsideIntersection.validity.patternMismatch, "nested class intersection should reject characters outside the right operand");
}, "patternMismatch supports nested character class operands in Unicode set intersection");

test(function () {
  const input = textInput("abc", "[\\p{ASCII}&&[a-z]+");
  assert_false(input.validity.patternMismatch, "invalid Unicode set syntax should be ignored");
  assert_true(input.validity.valid, "invalid Unicode set syntax should not invalidate the control");
}, "invalid Unicode set syntax remains ignored");
</script>