using RioJoy.Core.Mapping;
using Xunit;

namespace RioJoy.Core.Tests.Mapping;

public class KeyCatalogTests
{
    [Theory]
    [InlineData("A", 0x41)]
    [InlineData("Z", 0x5A)]
    [InlineData("0", 0x30)]
    [InlineData("F1", 0x70)]
    [InlineData("F12", 0x7B)]
    [InlineData("Enter", 0x0D)]
    [InlineData("Space", 0x20)]
    [InlineData("Left", 0x25)]
    [InlineData("NumPad 5", 0x65)]
    public void NameAndValue_RoundTrip(string name, int vk)
    {
        Assert.True(KeyCatalog.TryGetValue(name, out byte v));
        Assert.Equal((byte)vk, v);
        Assert.Equal(name, KeyCatalog.NameFor((byte)vk));
    }

    [Fact]
    public void NameFor_UnknownVk_ReturnsHex()
    {
        Assert.Equal("0xFF", KeyCatalog.NameFor(0xFF));
    }

    [Fact]
    public void TryGetValue_Unknown_ReturnsFalse()
    {
        Assert.False(KeyCatalog.TryGetValue("NotAKey", out _));
    }

    [Fact]
    public void Entries_AreUniqueByName()
    {
        Assert.Equal(KeyCatalog.Entries.Count, KeyCatalog.Entries.Select(e => e.Name).Distinct().Count());
    }
}
