using System.Linq;
using StellaOps.Feedser.Source.CertCc.Internal;
using Xunit;

namespace StellaOps.Feedser.Source.CertCc.Tests.Internal;

public sealed class CertCcVendorStatementParserTests
{
    [Fact]
    public void Parse_ReturnsPatchesForTabDelimitedList()
    {
        const string statement =
            "V3912/V3910/V2962/V1000B\t4.4.3.6/4.4.5.1\n" +
            "V2927/V2865/V2866\t4.5.1\n" +
            "V2765/V2766/V2763/V2135\t4.5.1";

        var patches = CertCcVendorStatementParser.Parse(statement);

        Assert.Equal(11, patches.Count);
        Assert.Contains(patches, patch => patch.Product == "V3912" && patch.Version == "4.4.3.6");
        Assert.Contains(patches, patch => patch.Product == "V2962" && patch.Version == "4.4.5.1");
        Assert.Equal(7, patches.Count(patch => patch.Version == "4.5.1"));
    }

    [Fact]
    public void Parse_ReturnsEmptyWhenStatementMissing()
    {
        var patches = CertCcVendorStatementParser.Parse(null);
        Assert.Empty(patches);
    }
}
