package com.synopsys.integration.detectable.detectables.dart.functional;

import java.util.Arrays;
import java.util.List;

import org.junit.jupiter.api.Test;

import com.synopsys.integration.bdio.graph.DependencyGraph;
import com.synopsys.integration.bdio.model.Forge;
import com.synopsys.integration.detectable.detectables.dart.pubspec.PubSpecLockParser;
import com.synopsys.integration.detectable.util.graph.NameVersionGraphAssert;

public class PubSpecLockParserTest {
    @Test
    public void test() {
        List<String> pubSpecLockLines = Arrays.asList(
            "# Generated by pub",
            "# See https://dart.dev/tools/pub/glossary#lockfile",
            "packages:",
            "  async:",
            "    dependency: transitive",
            "    description:",
            "      name: async",
            "    source: hosted",
            "    version: \"2.6.1\"",
            "  boolean_selector:",
            "    dependency: transitive",
            "    description:",
            "      name: boolean_selector",
            "      url: \"https://pub.dartlang.org\"",
            "    version: \"2.1.0\"",
            "  characters:",
            "    description:",
            "      name: characters",
            "    version: \"1.1.0\""
        );

        PubSpecLockParser pubSpecLockParser = new PubSpecLockParser();

        DependencyGraph dependencyGraph = pubSpecLockParser.parse(pubSpecLockLines);

        NameVersionGraphAssert graphAssert = new NameVersionGraphAssert(Forge.DART, dependencyGraph);

        graphAssert.hasRootSize(3);
        graphAssert.hasRootDependency("async", "2.6.1");
        graphAssert.hasRootDependency("boolean_selector", "2.1.0");
        graphAssert.hasRootDependency("characters", "1.1.0");
    }
}
