update
This commit is contained in:
@ -4,11 +4,7 @@ import * as plugins from '../../plugins.js';
|
||||
import { CorpusLoader } from '../../helpers/corpus.loader.js';
|
||||
import { PerformanceTracker } from '../../helpers/performance.tracker.js';
|
||||
|
||||
tap.test('PARSE-07: XML Schema Validation - Validate against XSD schemas', async (t) => {
|
||||
const performanceTracker = new PerformanceTracker('PARSE-07');
|
||||
|
||||
await t.test('Schema validation basics', async () => {
|
||||
performanceTracker.startOperation('schema-basics');
|
||||
tap.test('PARSE-07: Schema validation basics', async () => {
|
||||
|
||||
const schemaTests = [
|
||||
{
|
||||
@ -123,14 +119,13 @@ tap.test('PARSE-07: XML Schema Validation - Validate against XSD schemas', async
|
||||
console.log(` ✗ Validation error: ${error.message}`);
|
||||
}
|
||||
|
||||
performanceTracker.recordMetric('schema-validation', performance.now() - startTime);
|
||||
await PerformanceTracker.track('schema-validation', async () => {
|
||||
return simulateSchemaValidation(test.xml, test.schema);
|
||||
});
|
||||
}
|
||||
|
||||
performanceTracker.endOperation('schema-basics');
|
||||
});
|
||||
|
||||
await t.test('Complex schema features', async () => {
|
||||
performanceTracker.startOperation('complex-schemas');
|
||||
});
|
||||
|
||||
tap.test('PARSE-07: Complex schema features', async () => {
|
||||
|
||||
const complexTests = [
|
||||
{
|
||||
@ -229,14 +224,13 @@ tap.test('PARSE-07: XML Schema Validation - Validate against XSD schemas', async
|
||||
const invalidResult = simulateSchemaValidation(test.invalidXml, test.schema);
|
||||
console.log(` Result: ${invalidResult.valid ? '✗ Should be invalid' : `✓ Invalid as expected: ${invalidResult.error}`}`);
|
||||
|
||||
performanceTracker.recordMetric(`complex-${test.name}`, performance.now() - startTime);
|
||||
await PerformanceTracker.track(`complex-${test.name}`, async () => {
|
||||
return { validResult, invalidResult };
|
||||
});
|
||||
}
|
||||
|
||||
performanceTracker.endOperation('complex-schemas');
|
||||
});
|
||||
|
||||
await t.test('E-invoice schema validation', async () => {
|
||||
performanceTracker.startOperation('einvoice-schemas');
|
||||
});
|
||||
|
||||
tap.test('PARSE-07: E-invoice schema validation', async () => {
|
||||
|
||||
const einvoiceSchemas = [
|
||||
{
|
||||
@ -321,12 +315,9 @@ tap.test('PARSE-07: XML Schema Validation - Validate against XSD schemas', async
|
||||
console.log(` ⚠️ Parse error: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
performanceTracker.endOperation('einvoice-schemas');
|
||||
});
|
||||
|
||||
await t.test('Schema validation errors', async () => {
|
||||
performanceTracker.startOperation('validation-errors');
|
||||
});
|
||||
|
||||
tap.test('PARSE-07: Schema validation errors', async () => {
|
||||
|
||||
const errorTypes = [
|
||||
{
|
||||
@ -375,15 +366,24 @@ tap.test('PARSE-07: XML Schema Validation - Validate against XSD schemas', async
|
||||
|
||||
console.log(` ✓ Error details captured correctly`);
|
||||
}
|
||||
});
|
||||
|
||||
tap.test('PARSE-07: Corpus schema validation', async () => {
|
||||
|
||||
performanceTracker.endOperation('validation-errors');
|
||||
});
|
||||
|
||||
await t.test('Corpus schema validation', async () => {
|
||||
performanceTracker.startOperation('corpus-validation');
|
||||
// Load files from various categories
|
||||
const allFiles: CorpusFile[] = [];
|
||||
const categories = ['CII_XMLRECHNUNG', 'UBL_XMLRECHNUNG', 'EN16931_CII', 'EN16931_UBL_EXAMPLES'] as const;
|
||||
|
||||
const corpusLoader = new CorpusLoader();
|
||||
const xmlFiles = await corpusLoader.getFiles(/\.(xml|ubl|cii)$/);
|
||||
for (const category of categories) {
|
||||
try {
|
||||
const files = await CorpusLoader.loadCategory(category);
|
||||
allFiles.push(...files);
|
||||
} catch (error) {
|
||||
console.log(` Skipping category ${category}: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
const xmlFiles = allFiles.filter(f => f.path.match(/\.(xml|ubl|cii)$/));
|
||||
|
||||
console.log(`\nValidating ${xmlFiles.length} corpus files against schemas...`);
|
||||
|
||||
@ -402,7 +402,8 @@ tap.test('PARSE-07: XML Schema Validation - Validate against XSD schemas', async
|
||||
validationStats.total++;
|
||||
|
||||
try {
|
||||
const content = await plugins.fs.readFile(file.path, 'utf8');
|
||||
const fullPath = plugins.path.join(process.cwd(), 'test/assets/corpus', file.path);
|
||||
const content = await plugins.fs.readFile(fullPath, 'utf8');
|
||||
|
||||
// Detect format and schema
|
||||
const format = detectInvoiceFormat(content);
|
||||
@ -439,12 +440,9 @@ tap.test('PARSE-07: XML Schema Validation - Validate against XSD schemas', async
|
||||
console.log(` ${error}: ${count}`);
|
||||
}
|
||||
}
|
||||
|
||||
performanceTracker.endOperation('corpus-validation');
|
||||
});
|
||||
|
||||
await t.test('Schema caching and performance', async () => {
|
||||
performanceTracker.startOperation('schema-caching');
|
||||
});
|
||||
|
||||
tap.test('PARSE-07: Schema caching and performance', async () => {
|
||||
|
||||
class SchemaCache {
|
||||
private cache = new Map<string, any>();
|
||||
@ -527,12 +525,10 @@ tap.test('PARSE-07: XML Schema Validation - Validate against XSD schemas', async
|
||||
console.log(` Without cache: ${withoutCacheTime.toFixed(2)}ms`);
|
||||
console.log(` With cache: ${withCacheTime.toFixed(2)}ms`);
|
||||
console.log(` Speedup: ${(withoutCacheTime / withCacheTime).toFixed(2)}x`);
|
||||
|
||||
performanceTracker.endOperation('schema-caching');
|
||||
});
|
||||
|
||||
// Helper functions
|
||||
function simulateSchemaValidation(xml: string, schema: string): { valid: boolean; error?: string } {
|
||||
});
|
||||
|
||||
// Helper functions
|
||||
function simulateSchemaValidation(xml: string, schema: string): { valid: boolean; error?: string } {
|
||||
// Simple simulation - in reality would use a proper XML validator
|
||||
|
||||
// Check for basic structure
|
||||
@ -575,7 +571,7 @@ tap.test('PARSE-07: XML Schema Validation - Validate against XSD schemas', async
|
||||
return { valid: true };
|
||||
}
|
||||
|
||||
function detectInvoiceFormat(xml: string): string {
|
||||
function detectInvoiceFormat(xml: string): string {
|
||||
if (xml.includes('urn:oasis:names:specification:ubl:schema:xsd:Invoice-2')) {
|
||||
return 'UBL';
|
||||
} else if (xml.includes('urn:un:unece:uncefact:data:standard:CrossIndustryInvoice')) {
|
||||
@ -586,8 +582,15 @@ tap.test('PARSE-07: XML Schema Validation - Validate against XSD schemas', async
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
tap.test('PARSE-07: Performance summary', async () => {
|
||||
// Performance summary
|
||||
console.log('\n' + performanceTracker.getSummary());
|
||||
const stats = PerformanceTracker.getStats('schema-validation');
|
||||
if (stats) {
|
||||
console.log('\nSchema Validation Performance:');
|
||||
console.log(` Average: ${stats.avg.toFixed(2)}ms`);
|
||||
console.log(` Min: ${stats.min.toFixed(2)}ms`);
|
||||
console.log(` Max: ${stats.max.toFixed(2)}ms`);
|
||||
}
|
||||
|
||||
// Schema validation best practices
|
||||
console.log('\nXML Schema Validation Best Practices:');
|
||||
|
Reference in New Issue
Block a user