<?php

use Doom\Texture\PNamesParser;

test('parses PNAMES lump names', function (): void {
    $data = pack('V', 3)
        . pack('a8', 'BROWN1')
        . pack('a8', 'STARTAN3')
        . pack('a8', 'BIGDOOR2');

    $pNames = PNamesParser::parseBytes($data);

    expect($pNames)->toHaveCount(3);
    expect($pNames)->toBe(['BROWN1', 'STARTAN3', 'BIGDOOR2']);
    expect($pNames[1] ?? null)->toBe('STARTAN3');
    expect($pNames[10] ?? null)->toBeNull();
    expect(array_search('BIGDOOR2', $pNames, true))->toBe(2);
    expect(array_search('MISSING', $pNames, true))->toBeFalse();
});

test('throws on truncated PNAMES lump', function (): void {
    $data = pack('V', 2) . pack('a8', 'ONLYONE');

    expect(fn () => PNamesParser::parseBytes($data))->toThrow(RuntimeException::class);
});
