import { describe, it } from 'node:test'; import assert from 'node:assert/strict'; import { SweepService } from '../src/services/sweep.service.js'; const none = null as any; const svc = new SweepService(none, none, none, none, none, none, none); describe('SweepService.parse', () => { it('parses /24 bounds', () => { const r = svc.parse('10.0.0.0/24'); assert.equal(svc.ip(r.start), '10.0.0.0'); assert.equal(svc.ip(r.end), '10.0.0.255'); }); it('rejects non-IPv4 CIDRs', () => { assert.throws(() => svc.parse('not-a-cidr')); assert.throws(() => svc.parse('10.0.0.0/33')); assert.throws(() => svc.parse('::1/128')); }); }); describe('SweepService.size/ip', () => { it('sizes /32 as 1 and /24 as 256', () => { assert.equal(svc.size('1.2.3.4/32'), 1); assert.equal(svc.size('1.2.3.0/24'), 256); }); it('round-trips ip encoding', () => { assert.equal(svc.ip(svc.parse('192.168.1.0/24').start), '192.168.1.0'); }); }); describe('SweepService.contains', () => { it('detects covering ranges', () => { const outer = svc.parse('10.0.0.0/8'); assert.ok(svc.contains(outer, svc.parse('10.1.2.0/24'))); assert.ok(!svc.contains(svc.parse('10.1.2.0/24'), outer)); }); });