// ---------------------------------------------------------------------------
// BT.Framework.Tests
// EnumExTests.cs — EnumEx 메타데이터·파싱 유틸 단위 테스트
// ---------------------------------------------------------------------------
using NUnit.Framework;
using BurningTimes.Core.Util;

namespace BurningTimes.Tests.Core.Util
{
    public class EnumExTests
    {
        private enum Color { Red = 1, Green = 2, Blue = 4 }

        [Test]
        public void GetValues_ReturnsAllDefinedValues()
        {
            var values = EnumEx.GetValues<Color>();
            Assert.That(values.Length, Is.EqualTo(3));
            CollectionAssert.AreEquivalent(new[] { Color.Red, Color.Green, Color.Blue }, values);
        }

        [Test]
        public void GetValues_ReturnsCachedInstance()
        {
            var first = EnumEx.GetValues<Color>();
            var second = EnumEx.GetValues<Color>();
            Assert.AreSame(first, second, "배열 재할당이 발생하면 hot-path 비용이 증가한다");
        }

        [Test]
        public void GetNames_ReturnsDefinedNames()
        {
            var names = EnumEx.GetNames<Color>();
            CollectionAssert.AreEquivalent(new[] { "Red", "Green", "Blue" }, names);
        }

        [Test]
        public void Count_ReturnsDefinedValueCount()
        {
            Assert.That(EnumEx.Count<Color>(), Is.EqualTo(3));
        }

        [Test]
        public void IsDefined_TrueForDefinedValue()
        {
            Assert.IsTrue(EnumEx.IsDefined(Color.Green));
        }

        [Test]
        public void IsDefined_FalseForUndefinedIntCastValue()
        {
            Color invalid = (Color)999;
            Assert.IsFalse(EnumEx.IsDefined(invalid));
        }

        [Test]
        public void TryParse_CaseInsensitiveByDefault()
        {
            Assert.IsTrue(EnumEx.TryParse<Color>("green", out var result));
            Assert.That(result, Is.EqualTo(Color.Green));
        }

        [Test]
        public void TryParse_ReturnsFalseForNullOrEmpty()
        {
            Assert.IsFalse(EnumEx.TryParse<Color>("", out _));
            Assert.IsFalse(EnumEx.TryParse<Color>(null, out _));
        }

        [Test]
        public void TryParse_RespectsCaseSensitivity()
        {
            Assert.IsFalse(EnumEx.TryParse<Color>("green", ignoreCase: false, out _));
            Assert.IsTrue(EnumEx.TryParse<Color>("Green", ignoreCase: false, out var r));
            Assert.That(r, Is.EqualTo(Color.Green));
        }
    }
}
