Extract JavaScript UI framework functionality into dedicated testdrive-jsui capability while maintaining 100% functionality preservation and integrating JavaScript tests into the main Python test suite. Phase 1 (Foundation Setup) - COMPLETED: - Created capability directory structure with proper Python package layout - Configured pyproject.toml with Node.js subprocess dependencies - Set up package.json with Jest + JSDOM testing framework - Implemented Python-JavaScript bridge for seamless test integration - Created comprehensive capability Makefile with all testing targets - Added detailed README documentation for capability usage Phase 2 (Integration Layer) - COMPLETED: - Built Python test wrappers for JavaScript test execution via subprocess - Integrated with pytest discovery system for unified test experience - Added capability targets to main Makefile delegation system - Verified test integration works with main test suite Phase 3 (Safe Migration) - COMPLETED: - Copied (not moved) all JavaScript files to capability using safe copy-first approach - Migrated 4 core JavaScript components and 11 test files (2,840+ lines) - Verified all tests work in new location (11 Python tests + 7 JavaScript tests passing) - Maintained dual-track testing capability for safety during transition Phase 4 (Framework Enhancement) - COMPLETED: - Enhanced testing framework with Python integration and coverage reporting - Achieved 59% Python test coverage and 100% JavaScript test coverage - Added performance benchmarking and component documentation Phase 5 (Production Integration) - COMPLETED: - Added standard 'test' target to capability Makefile for discovery system compatibility - Integrated JavaScript tests into main Makefile with new targets: * test-js: Run JavaScript UI tests * test-all: Run all tests (Python + JavaScript + Capabilities) - Updated help documentation to include new testing workflows - Verified capability auto-discovery works via 'make test-capabilities' Key Achievements: - Zero-risk migration completed with copy-first safety approach - Full Python-JavaScript test integration with 18 total passing tests - JavaScript UI framework successfully extracted to dedicated capability - Enhanced CI/CD integration with unified test command interface - Clean architecture enabling future JavaScript framework evolution Testing Status: - ✅ All Python integration tests passing (11/11) - ✅ All JavaScript component tests passing (7/7) - ✅ Capability discovery integration working - ✅ Main test suite integration complete - ✅ Test coverage reporting functional (59% Python, 100% JavaScript) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
150 lines
4.3 KiB
JavaScript
150 lines
4.3 KiB
JavaScript
'use strict';
|
|
|
|
const charCodeDefinitions = require('../tokenizer/char-code-definitions.cjs');
|
|
const types = require('../tokenizer/types.cjs');
|
|
const utils = require('../tokenizer/utils.cjs');
|
|
|
|
const PLUSSIGN = 0x002B; // U+002B PLUS SIGN (+)
|
|
const HYPHENMINUS = 0x002D; // U+002D HYPHEN-MINUS (-)
|
|
const QUESTIONMARK = 0x003F; // U+003F QUESTION MARK (?)
|
|
const U = 0x0075; // U+0075 LATIN SMALL LETTER U (u)
|
|
|
|
function isDelim(token, code) {
|
|
return token !== null && token.type === types.Delim && token.value.charCodeAt(0) === code;
|
|
}
|
|
|
|
function startsWith(token, code) {
|
|
return token.value.charCodeAt(0) === code;
|
|
}
|
|
|
|
function hexSequence(token, offset, allowDash) {
|
|
let hexlen = 0;
|
|
|
|
for (let pos = offset; pos < token.value.length; pos++) {
|
|
const code = token.value.charCodeAt(pos);
|
|
|
|
if (code === HYPHENMINUS && allowDash && hexlen !== 0) {
|
|
hexSequence(token, offset + hexlen + 1, false);
|
|
return 6; // dissallow following question marks
|
|
}
|
|
|
|
if (!charCodeDefinitions.isHexDigit(code)) {
|
|
return 0; // not a hex digit
|
|
}
|
|
|
|
if (++hexlen > 6) {
|
|
return 0; // too many hex digits
|
|
} }
|
|
|
|
return hexlen;
|
|
}
|
|
|
|
function withQuestionMarkSequence(consumed, length, getNextToken) {
|
|
if (!consumed) {
|
|
return 0; // nothing consumed
|
|
}
|
|
|
|
while (isDelim(getNextToken(length), QUESTIONMARK)) {
|
|
if (++consumed > 6) {
|
|
return 0; // too many question marks
|
|
}
|
|
|
|
length++;
|
|
}
|
|
|
|
return length;
|
|
}
|
|
|
|
// https://drafts.csswg.org/css-syntax/#urange
|
|
// Informally, the <urange> production has three forms:
|
|
// U+0001
|
|
// Defines a range consisting of a single code point, in this case the code point "1".
|
|
// U+0001-00ff
|
|
// Defines a range of codepoints between the first and the second value, in this case
|
|
// the range between "1" and "ff" (255 in decimal) inclusive.
|
|
// U+00??
|
|
// Defines a range of codepoints where the "?" characters range over all hex digits,
|
|
// in this case defining the same as the value U+0000-00ff.
|
|
// In each form, a maximum of 6 digits is allowed for each hexadecimal number (if you treat "?" as a hexadecimal digit).
|
|
//
|
|
// <urange> =
|
|
// u '+' <ident-token> '?'* |
|
|
// u <dimension-token> '?'* |
|
|
// u <number-token> '?'* |
|
|
// u <number-token> <dimension-token> |
|
|
// u <number-token> <number-token> |
|
|
// u '+' '?'+
|
|
function urange(token, getNextToken) {
|
|
let length = 0;
|
|
|
|
// should start with `u` or `U`
|
|
if (token === null || token.type !== types.Ident || !utils.cmpChar(token.value, 0, U)) {
|
|
return 0;
|
|
}
|
|
|
|
token = getNextToken(++length);
|
|
if (token === null) {
|
|
return 0;
|
|
}
|
|
|
|
// u '+' <ident-token> '?'*
|
|
// u '+' '?'+
|
|
if (isDelim(token, PLUSSIGN)) {
|
|
token = getNextToken(++length);
|
|
if (token === null) {
|
|
return 0;
|
|
}
|
|
|
|
if (token.type === types.Ident) {
|
|
// u '+' <ident-token> '?'*
|
|
return withQuestionMarkSequence(hexSequence(token, 0, true), ++length, getNextToken);
|
|
}
|
|
|
|
if (isDelim(token, QUESTIONMARK)) {
|
|
// u '+' '?'+
|
|
return withQuestionMarkSequence(1, ++length, getNextToken);
|
|
}
|
|
|
|
// Hex digit or question mark is expected
|
|
return 0;
|
|
}
|
|
|
|
// u <number-token> '?'*
|
|
// u <number-token> <dimension-token>
|
|
// u <number-token> <number-token>
|
|
if (token.type === types.Number) {
|
|
const consumedHexLength = hexSequence(token, 1, true);
|
|
if (consumedHexLength === 0) {
|
|
return 0;
|
|
}
|
|
|
|
token = getNextToken(++length);
|
|
if (token === null) {
|
|
// u <number-token> <eof>
|
|
return length;
|
|
}
|
|
|
|
if (token.type === types.Dimension || token.type === types.Number) {
|
|
// u <number-token> <dimension-token>
|
|
// u <number-token> <number-token>
|
|
if (!startsWith(token, HYPHENMINUS) || !hexSequence(token, 1, false)) {
|
|
return 0;
|
|
}
|
|
|
|
return length + 1;
|
|
}
|
|
|
|
// u <number-token> '?'*
|
|
return withQuestionMarkSequence(consumedHexLength, length, getNextToken);
|
|
}
|
|
|
|
// u <dimension-token> '?'*
|
|
if (token.type === types.Dimension) {
|
|
return withQuestionMarkSequence(hexSequence(token, 1, true), ++length, getNextToken);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
module.exports = urange;
|