-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-whitespace.js
More file actions
39 lines (35 loc) · 1.24 KB
/
test-whitespace.js
File metadata and controls
39 lines (35 loc) · 1.24 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
// Test whitespace validation
import { generateLeftmostDerivation } from './src/lib/LeftmostDerivation.ts';
import { checkSyntax } from './src/lib/Parser.ts';
const testCases = [
{ input: '2+3', shouldWork: true },
{ input: '2 + 3', shouldWork: false },
{ input: '4+12+2', shouldWork: true },
{ input: '4 + 12 + 2', shouldWork: false },
{ input: 'a|b', shouldWork: true },
{ input: 'a | b', shouldWork: false }
];
console.log('Testing Whitespace Validation\n');
console.log('==============================\n');
testCases.forEach(({ input, shouldWork }) => {
console.log(`Input: "${input}"`);
try {
const result = checkSyntax(input);
if (shouldWork) {
console.log(`✅ Expected to work - Result: ${result.isValid ? 'Valid' : 'Invalid'}`);
if (result.isValid) {
const derivation = generateLeftmostDerivation(input);
console.log(` Last step: "${derivation[derivation.length - 1]}"`);
}
} else {
console.log(`❌ Expected to fail but worked - Result: Valid`);
}
} catch (error) {
if (shouldWork) {
console.log(`❌ Expected to work but failed - Error: ${error.message}`);
} else {
console.log(`✅ Expected to fail - Error: ${error.message}`);
}
}
console.log('');
});