Search in sources :

Example 6 with YarnLockEntry

use of com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntry in project synopsys-detect by blackducksoftware.

the class YarnLockHeaderSectionParserTest method testParserHandlesMissingSymbol.

@Test
void testParserHandlesMissingSymbol() {
    String line = "example, example@1";
    List<String> lines = Arrays.asList(line);
    Assertions.assertTrue(yarnLockParser.applies(line));
    YarnLockEntryBuilder builder = new YarnLockEntryBuilder();
    yarnLockParser.parseSection(builder, lines, 0);
    // Complete the builder requirements and build the entry
    builder.setVersion("testVersion");
    YarnLockEntry entry = builder.build();
    List<YarnLockEntryId> ids = entry.getIds();
    Assertions.assertEquals(2, ids.size());
    Assertions.assertEquals("example", ids.get(0).getName());
    Assertions.assertEquals("", ids.get(0).getVersion());
    Assertions.assertEquals("example", ids.get(1).getName());
    Assertions.assertEquals("1", ids.get(1).getVersion());
}
Also used : YarnLockEntryId(com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryId) YarnLockEntry(com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntry) YarnLockEntryBuilder(com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryBuilder) Test(org.junit.jupiter.api.Test)

Example 7 with YarnLockEntry

use of com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntry in project synopsys-detect by blackducksoftware.

the class YarnLockHeaderSectionParserTest method handlesSymbolInName.

@Test
void handlesSymbolInName() {
    String line = "@example";
    List<String> lines = Arrays.asList(line);
    Assertions.assertTrue(yarnLockParser.applies(line));
    YarnLockEntryBuilder builder = new YarnLockEntryBuilder();
    yarnLockParser.parseSection(builder, lines, 0);
    // Complete the builder requirements and build the entry
    builder.setVersion("testVersion");
    YarnLockEntry entry = builder.build();
    List<YarnLockEntryId> ids = entry.getIds();
    Assertions.assertEquals(1, ids.size());
    Assertions.assertEquals("@example", ids.get(0).getName());
    Assertions.assertEquals("", ids.get(0).getVersion());
}
Also used : YarnLockEntryId(com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryId) YarnLockEntry(com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntry) YarnLockEntryBuilder(com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryBuilder) Test(org.junit.jupiter.api.Test)

Example 8 with YarnLockEntry

use of com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntry in project synopsys-detect by blackducksoftware.

the class YarnLockKeyValuePairSectionParserTest method doTest.

private void doTest(String line, String versionValue) {
    Assertions.assertTrue(yarnLockKeyValuePairElementParser.applies(line));
    YarnLockEntryBuilder builder = new YarnLockEntryBuilder();
    builder.addId(new YarnLockEntryId("idname", "idversion"));
    List<String> lines = Arrays.asList(line);
    yarnLockKeyValuePairElementParser.parseSection(builder, lines, 0);
    YarnLockEntry entry = builder.build();
    Assertions.assertEquals(versionValue, entry.getVersion());
}
Also used : YarnLockEntryId(com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryId) YarnLockEntry(com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntry) YarnLockEntryBuilder(com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryBuilder)

Example 9 with YarnLockEntry

use of com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntry in project synopsys-detect by blackducksoftware.

the class YarnLockParserTest method testThatYarnLockPeerNotAdded.

@Test
void testThatYarnLockPeerNotAdded() {
    List<String> yarnLockText = Arrays.asList("any-root-dep@1:", // must have a version to create an entry
    "  version: 1", "  peerDependencies:", "    some-peer: ^10.0.0", "  peerDependenciesMeta:", "    some-peer:", "      optional: true");
    YarnLockParser yarnLockParser = createYarnLockParser();
    YarnLock yarnLock = yarnLockParser.parseYarnLock(yarnLockText);
    Assertions.assertEquals(1, yarnLock.getEntries().size());
    YarnLockEntry first = yarnLock.getEntries().get(0);
    Assertions.assertEquals(0, first.getDependencies().size());
}
Also used : YarnLock(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock) YarnLockEntry(com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntry) YarnLockParser(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockParser) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Example 10 with YarnLockEntry

use of com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntry in project synopsys-detect by blackducksoftware.

the class YarnLockParserTest method testThatYarnParsesSemiColon.

@Test
void testThatYarnParsesSemiColon() {
    List<String> yarnLockText = Arrays.asList("any-root-dep@1:", // must have a version to create an entry
    "  version: 1.0.0", "  dependencies:", "    some-peer: ^10.0.0");
    YarnLockParser yarnLockParser = createYarnLockParser();
    YarnLock yarnLock = yarnLockParser.parseYarnLock(yarnLockText);
    Assertions.assertEquals(1, yarnLock.getEntries().size());
    YarnLockEntry first = yarnLock.getEntries().get(0);
    Assertions.assertEquals("1.0.0", first.getVersion());
    Assertions.assertEquals(1, first.getDependencies().size());
    YarnLockDependency dep = first.getDependencies().get(0);
    Assertions.assertEquals("some-peer", dep.getName());
    Assertions.assertEquals("^10.0.0", dep.getVersion());
    Assertions.assertFalse(dep.isOptional());
}
Also used : YarnLock(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock) YarnLockEntry(com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntry) YarnLockParser(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockParser) YarnLockDependency(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Aggregations

YarnLockEntry (com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntry)17 YarnLockEntryId (com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryId)12 Test (org.junit.jupiter.api.Test)10 YarnLockDependency (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency)7 YarnLock (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock)6 YarnLockEntryBuilder (com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryBuilder)6 UnitTest (com.synopsys.integration.detectable.annotations.UnitTest)5 YarnLockParser (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockParser)4 PackageJson (com.synopsys.integration.detectable.detectables.npm.packagejson.model.PackageJson)2 NullSafePackageJson (com.synopsys.integration.detectable.detectables.yarn.packagejson.NullSafePackageJson)2 WorkspacePackageJson (com.synopsys.integration.detectable.detectables.yarn.packagejson.WorkspacePackageJson)2 YarnLockResult (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockResult)2 LinkedList (java.util.LinkedList)2 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)1 LazyExternalIdDependencyGraphBuilder (com.synopsys.integration.bdio.graph.builder.LazyExternalIdDependencyGraphBuilder)1 LazyId (com.synopsys.integration.bdio.graph.builder.LazyId)1 ExternalId (com.synopsys.integration.bdio.model.externalid.ExternalId)1 CodeLocation (com.synopsys.integration.detectable.detectable.codelocation.CodeLocation)1 YarnLockEntryParseResult (com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryParseResult)1 YarnWorkspace (com.synopsys.integration.detectable.detectables.yarn.workspace.YarnWorkspace)1