about summary refs log tree commit diff stats
path: root/forth/foreforthfourth/test-help.js
blob: b3aa28e8e488b4fcfcc4146b02574fbdbc69868e (plain) (blame)
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
// Test the new help system
const ForthInterpreter = require('./forth.js');

console.log('🧪 Testing Help System\n');

let state = ForthInterpreter.createInitialState();

// Test 1: Basic help command
console.log('Test 1: Basic help command');
state = ForthInterpreter.parseAndExecute(state, 'help');
console.log('Help output (first 10 lines):');
state.output.slice(-10).forEach((line, i) => {
    console.log(`${i + 1}. ${line}`);
});

// Test 2: Document specific word
console.log('\nTest 2: Document specific word');
state = ForthInterpreter.parseAndExecute(state, 's" dup"');
state = ForthInterpreter.parseAndExecute(state, 'doc');
console.log('Doc output:');
state.output.slice(-5).forEach((line, i) => {
    console.log(`${i + 1}. ${line}`);
});

// Test 3: Document another word
console.log('\nTest 3: Document another word');
state = ForthInterpreter.parseAndExecute(state, 's" +"');
state = ForthInterpreter.parseAndExecute(state, 'doc');
console.log('Doc output:');
state.output.slice(-5).forEach((line, i) => {
    console.log(`${i + 1}. ${line}`);
});

// Test 4: Document non-existent word
console.log('\nTest 4: Document non-existent word');
state = ForthInterpreter.parseAndExecute(state, 's" nonexistent"');
state = ForthInterpreter.parseAndExecute(state, 'doc');
console.log('Doc output:');
state.output.slice(-3).forEach((line, i) => {
    console.log(`${i + 1}. ${line}`);
});

// Test 5: Words command
console.log('\nTest 5: Words command');
state = ForthInterpreter.parseAndExecute(state, 'words');
console.log('Words output:');
state.output.slice(-3).forEach((line, i) => {
    console.log(`${i + 1}. ${line}`);
});

console.log('\n✅ Help system tests completed!');
console.log('Total output lines:', state.output.length);