Spaces:
Running
Running
File size: 1,795 Bytes
a9e27c0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | """Compare emitted regexes with the client's JavaScript Unicode semantics."""
import unicodedata
from free_claude_code.core.tool_schema_patterns import translate_tool_schema_patterns
from tests.core.test_tool_schema_patterns import ARTIFACT_PATTERN
def test_artifact_pattern_matches_javascript_reference(page):
converted = translate_tool_schema_patterns({"pattern": ARTIFACT_PATTERN})["pattern"]
samples = [
"",
"demo",
"é名字😀",
"__name__",
"__name",
"name__",
"-name-",
"a" * 200,
"a" * 201,
*["x" + char + "y" for char in r'"\/.[]'],
*[
chr(point)
for point in range(0x110000)
if unicodedata.category(chr(point)) in {"Cc", "Cf", "Zl", "Zp"}
],
"\U000110bc",
"\U000110be",
"\U000e0000",
"\U000e0080",
]
mismatches = page.evaluate(
"""({original, converted, samples}) => {
const before = new RegExp(original, 'u');
const after = new RegExp(converted, 'u');
const mismatches = samples.filter(text => before.test(text) !== after.test(text));
for (let point = 0; point < 0x110000; point++) {
if (point >= 0xD800 && point <= 0xDFFF) continue;
const text = String.fromCodePoint(point);
if (before.test(text) !== after.test(text)) {
mismatches.push(`U+${point.toString(16)}`);
if (mismatches.length >= 10) break;
}
}
return mismatches;
}""",
{"original": ARTIFACT_PATTERN, "converted": converted, "samples": samples},
)
assert mismatches == [], f"Unicode {unicodedata.unidata_version}: {mismatches!r}"
|