|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { StackFrame } from './stack-frame'; |
| 3 | +import { SymbolTable } from '../execution/scope/symbol-table'; |
| 4 | + |
| 5 | +describe('StackFrame', () => { |
| 6 | + it('should be instantiated correctly', () => { |
| 7 | + const symbolTable = new SymbolTable(); |
| 8 | + const returnAddress = { |
| 9 | + functionName: 'callerFunction', |
| 10 | + blockLabel: 'entry', |
| 11 | + instructionIndex: 5, |
| 12 | + }; |
| 13 | + const frame = new StackFrame('testFunction', symbolTable, returnAddress); |
| 14 | + |
| 15 | + expect(frame).toBeInstanceOf(StackFrame); |
| 16 | + expect(frame.functionName).toBe('testFunction'); |
| 17 | + expect(frame.localScope).toBe(symbolTable); |
| 18 | + expect(frame.returnAddress).toBe(returnAddress); |
| 19 | + expect(frame.returnValue).toBe(null); |
| 20 | + }); |
| 21 | + |
| 22 | + it('should allow setting return value', () => { |
| 23 | + const symbolTable = new SymbolTable(); |
| 24 | + const returnAddress = { |
| 25 | + functionName: 'callerFunction', |
| 26 | + blockLabel: 'entry', |
| 27 | + instructionIndex: 5, |
| 28 | + }; |
| 29 | + const frame = new StackFrame('testFunction', symbolTable, returnAddress); |
| 30 | + |
| 31 | + frame.returnValue = 42; |
| 32 | + expect(frame.returnValue).toBe(42); |
| 33 | + |
| 34 | + frame.returnValue = 'test string'; |
| 35 | + expect(frame.returnValue).toBe('test string'); |
| 36 | + }); |
| 37 | +}); |
0 commit comments