-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
146 lines (131 loc) · 4.14 KB
/
test.js
File metadata and controls
146 lines (131 loc) · 4.14 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// APL Framework Test Suite
// Run: node test.js
const APL = require('./src/index.js');
async function runTests() {
console.log('🧪 APL Framework Test Suite\n');
let passed = 0;
let failed = 0;
// Test 1: Initialization
try {
const apl = new APL();
console.log('✅ Test 1: APL initialization');
passed++;
} catch (e) {
console.log('❌ Test 1: APL initialization -', e.message);
failed++;
}
// Test 2: ASCII to Runic conversion
try {
const apl = new APL();
const runic = apl.toRunic('Q.super');
if (runic === 'ᛩ') {
console.log('✅ Test 2: ASCII to Runic conversion');
passed++;
} else {
throw new Error(`Expected ᛩ, got ${runic}`);
}
} catch (e) {
console.log('❌ Test 2: ASCII to Runic conversion -', e.message);
failed++;
}
// Test 3: Runic to ASCII conversion
try {
const apl = new APL();
const ascii = apl.toAscii('ᛩ');
if (ascii === 'Q.super') {
console.log('✅ Test 3: Runic to ASCII conversion');
passed++;
} else {
throw new Error(`Expected Q.super, got ${ascii}`);
}
} catch (e) {
console.log('❌ Test 3: Runic to ASCII conversion -', e.message);
failed++;
}
// Test 4: Compilation
try {
const apl = new APL();
const compiled = apl.compile('// test\nprint("hello")');
if (compiled.success) {
console.log('✅ Test 4: Code compilation');
passed++;
} else {
throw new Error(compiled.error);
}
} catch (e) {
console.log('❌ Test 4: Code compilation -', e.message);
failed++;
}
// Test 5: Native function registration
try {
const apl = new APL();
let called = false;
apl.registerNative('testFunc', () => { called = true; return 42; });
if (called === false) { // Should not be called yet
console.log('✅ Test 5: Native function registration');
passed++;
} else {
throw new Error('Function called prematurely');
}
} catch (e) {
console.log('❌ Test 5: Native function registration -', e.message);
failed++;
}
// Test 6: Standard library functions
try {
const apl = new APL();
if (apl.runtime.globals.has('sqrt') &&
apl.runtime.globals.has('print')) {
console.log('✅ Test 6: Standard library loaded');
passed++;
} else {
throw new Error('Standard library not loaded');
}
} catch (e) {
console.log('❌ Test 6: Standard library loaded -', e.message);
failed++;
}
// Test 7: Mode detection
try {
const apl = new APL();
const asciiMode = apl.runicMap.normalize('Q.super');
const runicMode = apl.runicMap.normalize('ᛩ');
if (asciiMode.mode === 'ascii' && runicMode.mode === 'runic') {
console.log('✅ Test 7: Mode detection');
passed++;
} else {
throw new Error(`Modes incorrect: ${asciiMode.mode}, ${runicMode.mode}`);
}
} catch (e) {
console.log('❌ Test 7: Mode detection -', e.message);
failed++;
}
// Test 8: Version check
try {
if (APL.version === '1.0.0') {
console.log('✅ Test 8: Version check');
passed++;
} else {
throw new Error(`Expected 1.0.0, got ${APL.version}`);
}
} catch (e) {
console.log('❌ Test 8: Version check -', e.message);
failed++;
}
// Summary
console.log(`\n📊 Test Results: ${passed} passed, ${failed} failed`);
if (failed === 0) {
console.log('🎉 All tests passed! Framework is ready for launch.');
return 0;
} else {
console.log('⚠️ Some tests failed. Please review.');
return 1;
}
}
// Run tests
runTests().then(code => {
process.exit(code);
}).catch(err => {
console.error('Fatal error:', err);
process.exit(1);
});