import {
  describe,
  it,
  expect
} from 'vitest';
import { estimateStructuredBytes } from './state-size.rules';

describe('estimateStructuredBytes', () => {
  it('returns zero for nullish values', () => {
    expect(estimateStructuredBytes(null)).toBe(0);
    expect(estimateStructuredBytes(undefined)).toBe(0);
  });

  it('estimates primitive and shallow object sizes', () => {
    expect(estimateStructuredBytes('hello')).toBeGreaterThan(0);
    expect(estimateStructuredBytes({ a: 1, b: 'two' })).toBeGreaterThan(estimateStructuredBytes({ a: 1 }));
  });

  it('stops walking once the node budget is exhausted', () => {
    const deep = {
      level1: {
        level2: {
          level3: {
            payload: 'value'
          }
        }
      }
    };
    const full = estimateStructuredBytes(deep, { maxNodes: 50 });
    const shallow = estimateStructuredBytes(deep, { maxNodes: 2 });

    expect(shallow).toBeLessThan(full);
  });
});
