-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest-decode-quoted-printable.js
More file actions
103 lines (87 loc) · 3.37 KB
/
Copy pathtest-decode-quoted-printable.js
File metadata and controls
103 lines (87 loc) · 3.37 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
* Test script for decodeQuotedPrintable function
*
* Usage: node test-decode-quoted-printable.js
*/
const { decodeQuotedPrintable } = require('./decodeQuotedPrintable');
const fs = require('fs');
const path = require('path');
// Load test cases from JSON file
const testFile = path.join(__dirname, 'test-decode-quoted-printable.json');
let testCases = [];
try {
const testData = JSON.parse(fs.readFileSync(testFile, 'utf8'));
testCases = testData.testCases || [];
console.log(`Loaded ${testCases.length} test cases from ${testFile}\n`);
} catch (error) {
console.error(`Error loading test file: ${error.message}`);
process.exit(1);
}
// Run tests
console.log('='.repeat(80));
console.log('Testing decodeQuotedPrintable function');
console.log('='.repeat(80));
console.log();
let passed = 0;
let failed = 0;
const failures = [];
for (let i = 0; i < testCases.length; i++) {
const testCase = testCases[i];
const { name, input, expected, description } = testCase;
try {
const result = decodeQuotedPrintable(input);
const success = result === expected;
if (success) {
console.log(`✓ [${i + 1}/${testCases.length}] ${name}`);
passed++;
} else {
console.log(`✗ [${i + 1}/${testCases.length}] ${name}`);
console.log(` Description: ${description || 'No description'}`);
console.log(` Input: ${JSON.stringify(input)}`);
console.log(` Expected: ${JSON.stringify(expected)}`);
console.log(` Got: ${JSON.stringify(result)}`);
// Show character codes for debugging
if (expected && result) {
const expectedCodes = Array.from(expected).map(c => `U+${c.charCodeAt(0).toString(16).toUpperCase().padStart(4, '0')}`).join(' ');
const resultCodes = Array.from(result).map(c => `U+${c.charCodeAt(0).toString(16).toUpperCase().padStart(4, '0')}`).join(' ');
console.log(` Expected codes: ${expectedCodes}`);
console.log(` Result codes: ${resultCodes}`);
}
failed++;
failures.push({ name, input, expected, result, description });
console.log();
}
} catch (error) {
console.log(`✗ [${i + 1}/${testCases.length}] ${name}`);
console.log(` ERROR: ${error.message}`);
console.log(` Stack: ${error.stack}`);
failed++;
failures.push({ name, input, expected, error: error.message });
console.log();
}
}
// Summary
console.log('='.repeat(80));
console.log('Test Summary');
console.log('='.repeat(80));
console.log(`Total tests: ${testCases.length}`);
console.log(`Passed: ${passed}`);
console.log(`Failed: ${failed}`);
console.log(`Success rate: ${((passed / testCases.length) * 100).toFixed(1)}%`);
console.log();
if (failed > 0) {
console.log('Failed tests:');
failures.forEach((failure, index) => {
console.log(`\n${index + 1}. ${failure.name}`);
if (failure.error) {
console.log(` Error: ${failure.error}`);
} else {
console.log(` Expected: ${JSON.stringify(failure.expected)}`);
console.log(` Got: ${JSON.stringify(failure.result)}`);
}
});
process.exit(1);
} else {
console.log('All tests passed! ✓');
process.exit(0);
}