-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
89 lines (82 loc) · 2.28 KB
/
test.js
File metadata and controls
89 lines (82 loc) · 2.28 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
// test.js — Test suite for metatron.js parser
// Run with: node test.js
import { parseResponse } from './parser.js';
// Mock data for testing parser
const testCases = [
{
name: 'Normal case',
input: `EXPLANATION: This is the explanation.
CODE: const x = 1;
VERIFICATION: Test with assert(x === 1); OWASP A01:2021`,
expected: {
explanation: 'This is the explanation.',
code: 'const x = 1;',
verification: 'Test with assert(x === 1); OWASP A01:2021'
}
},
{
name: 'Code with CODE: in comment',
input: `EXPLANATION: Parsing tricky code.
CODE: // This comment contains "CODE:" to break parsing
const y = 2;
VERIFICATION: CWE-89 reference`,
expected: {
explanation: 'Parsing tricky code.',
code: '// This comment contains "CODE:" to break parsing\nconst y = 2;',
verification: 'CWE-89 reference'
}
},
{
name: 'Multiline code',
input: `EXPLANATION: Multiline example.
CODE: function foo() {
return 'bar';
}
VERIFICATION: MDN reference`,
expected: {
explanation: 'Multiline example.',
code: 'function foo() {\n return \'bar\';\n}',
verification: 'MDN reference'
}
},
{
name: 'Weak verification',
input: `EXPLANATION: Weak verif.
CODE: const z = 3;
VERIFICATION: Just a test`,
expected: {
explanation: 'Weak verif.',
code: 'const z = 3;',
verification: 'Just a test'
}
}
];
console.log('Running parser tests...\n');
let passed = 0;
let total = testCases.length;
testCases.forEach((test, i) => {
console.log(`Test ${i + 1}: ${test.name}`);
const result = parseResponse(test.input);
if (result) {
const match = result.explanation === test.expected.explanation &&
result.code === test.expected.code &&
result.verification === test.expected.verification;
if (match) {
console.log(' ✅ PASSED');
passed++;
} else {
console.log(' ❌ FAILED');
console.log(' Expected:', test.expected);
console.log(' Got:', result);
}
} else {
console.log(' ❌ PARSE FAILED');
}
console.log('');
});
console.log(`Results: ${passed}/${total} tests passed`);
if (passed === total) {
console.log('🎉 All tests passed!');
} else {
console.log('⚠️ Some tests failed. Check the output above.');
}