import { describe, it, expect } from 'vitest';
import { op_or } from './or.js';
describe('OR (0x17)', () => {
it('performs basic OR', () => {
const frame = createFrame({ stack: [0b1100n, 0b1010n] });
expect(op_or(frame)).toBeNull();
expect(frame.stack[0]).toBe(0b1110n);
});
it('combines flags', () => {
const flag1 = 0b0001n;
const flag2 = 0b0100n;
const frame = createFrame({ stack: [flag1, flag2] });
expect(op_or(frame)).toBeNull();
expect(frame.stack[0]).toBe(0b0101n);
});
it('handles identity (OR with zero)', () => {
const value = 0x123456n;
const frame = createFrame({ stack: [value, 0n] });
expect(op_or(frame)).toBeNull();
expect(frame.stack[0]).toBe(value);
});
it('handles null element (OR with MAX)', () => {
const MAX = (1n << 256n) - 1n;
const value = 0x123456n;
const frame = createFrame({ stack: [value, MAX] });
expect(op_or(frame)).toBeNull();
expect(frame.stack[0]).toBe(MAX);
});
it('is idempotent (a | a = a)', () => {
const value = 0x123456n;
const frame = createFrame({ stack: [value, value] });
expect(op_or(frame)).toBeNull();
expect(frame.stack[0]).toBe(value);
});
it('is commutative', () => {
const a = 0xAAAAn;
const b = 0x5555n;
const frame1 = createFrame({ stack: [a, b] });
const frame2 = createFrame({ stack: [b, a] });
op_or(frame1);
op_or(frame2);
expect(frame1.stack[0]).toBe(frame2.stack[0]);
});
it('returns StackUnderflow with insufficient stack', () => {
const frame = createFrame({ stack: [0x123n] });
expect(op_or(frame)).toEqual({ type: 'StackUnderflow' });
});
it('returns OutOfGas when insufficient gas', () => {
const frame = createFrame({ stack: [0x123n, 0x456n], gasRemaining: 2n });
expect(op_or(frame)).toEqual({ type: 'OutOfGas' });
});
});