import { Address } from "../src/address";
import { describe, it, expect } from "vitest";

describe("Address extension handling", () => {
  it("encodes and decodes extension", () => {
    const addr = new Address("NOCALL", 7, false, 0b11, true);
    const bytes = addr.toBytes();
    expect((bytes[6] & 0x01)).toBe(1); // extension set
    const decoded = Address.fromBytes(bytes);
    expect(decoded.getExtension()).toBe(true);
    expect(decoded.callsign).toBe("NOCALL");
    expect(decoded.ssid).toBe(7);
  });

  it("can set and clear extension", () => {
    const addr = new Address("TEST", 1);
    addr.setExtension(true);
    let bytes = addr.toBytes();
    expect((bytes[6] & 0x01)).toBe(1);
    addr.setExtension(false);
    bytes = addr.toBytes();
    expect((bytes[6] & 0x01)).toBe(0);
  });
});
