// ---------------------------------------------------------------------------
// BT.Framework.Tests
// KeyMakerTests.cs — KeyMaker 합성 키 단위 테스트
// ---------------------------------------------------------------------------
using NUnit.Framework;
using BurningTimes.Core.Util;

namespace BurningTimes.Tests.Core.Util
{
    public class KeyMakerTests
    {
        [Test]
        public void Separator_IsColon()
        {
            Assert.That(KeyMaker.Separator, Is.EqualTo(':'));
        }

        [Test]
        public void Make_TwoStrings_JoinsWithSeparator()
        {
            Assert.That(KeyMaker.Make("card", "101"), Is.EqualTo("card:101"));
        }

        [Test]
        public void Make_StringAndInt_UsesInvariantFormat()
        {
            Assert.That(KeyMaker.Make("card", 101), Is.EqualTo("card:101"));
            Assert.That(KeyMaker.Make("card", -5), Is.EqualTo("card:-5"));
        }

        [Test]
        public void Make_ThreeTokens_JoinsAll()
        {
            Assert.That(KeyMaker.Make("a", "b", "c"), Is.EqualTo("a:b:c"));
        }

        [Test]
        public void MakeParams_VarArgsJoin()
        {
            Assert.That(KeyMaker.MakeParams("a", "b", "c", "d"), Is.EqualTo("a:b:c:d"));
            Assert.That(KeyMaker.MakeParams(), Is.EqualTo(string.Empty));
            Assert.That(KeyMaker.MakeParams(null), Is.EqualTo(string.Empty));
        }

        [Test]
        public void SplitRoot_ReturnsFirstToken()
        {
            Assert.That(KeyMaker.SplitRoot("card:101"), Is.EqualTo("card"));
            Assert.That(KeyMaker.SplitRoot("card:101:x"), Is.EqualTo("card"));
        }

        [Test]
        public void SplitRoot_NoSeparator_ReturnsWhole()
        {
            Assert.That(KeyMaker.SplitRoot("card"), Is.EqualTo("card"));
            Assert.That(KeyMaker.SplitRoot(""), Is.EqualTo(""));
            Assert.That(KeyMaker.SplitRoot(null), Is.EqualTo(""));
        }

        [Test]
        public void StartsWithCategory_RequiresSeparatorBoundary()
        {
            Assert.IsTrue(KeyMaker.StartsWithCategory("card:101", "card"));
            Assert.IsTrue(KeyMaker.StartsWithCategory("card", "card"));
            // prefix가 substring만 일치하는 경우는 false (card ≠ cards)
            Assert.IsFalse(KeyMaker.StartsWithCategory("cards:101", "card"));
            Assert.IsFalse(KeyMaker.StartsWithCategory("", "card"));
        }
    }
}
