Search in sources :

Example 11 with YarnLockParser

use of com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockParser 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)

Example 12 with YarnLockParser

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

the class YarnLockParserTest method testOptionalSetFromMeta.

@Test
void testOptionalSetFromMeta() {
    List<String> yarnLockText = Arrays.asList("any-root-dep@1:", // must have a version to create an entry
    "  version: 1", "  dependencies:", "    should-be-optional: 1.0.0", "    should-not-be-optional: 2.0.0", "  dependenciesMeta:", "    should-be-optional:", "      optional: true");
    YarnLockParser yarnLockParser = createYarnLockParser();
    YarnLock yarnLock = yarnLockParser.parseYarnLock(yarnLockText);
    Assertions.assertTrue(yarnLock.getEntries().size() > 0);
    YarnLockEntry first = yarnLock.getEntries().get(0);
    YarnLockDependency optDep = first.getDependencies().stream().filter(it -> it.getName().equals("should-be-optional")).findFirst().get();
    YarnLockDependency reqDep = first.getDependencies().stream().filter(it -> it.getName().equals("should-not-be-optional")).findFirst().get();
    Assertions.assertTrue(optDep.isOptional());
    Assertions.assertFalse(reqDep.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)

Example 13 with YarnLockParser

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

the class YarnLockParserTest method testDetectYarn2.

@Test
void testDetectYarn2() {
    List<String> yarnLockText = new ArrayList<>();
    yarnLockText.add("# This file is generated by running \"yarn install\" inside your project.");
    yarnLockText.add("# Manual changes might be lost - proceed with caution!");
    yarnLockText.add("");
    yarnLockText.add("__metadata:");
    yarnLockText.add("  version: 4");
    yarnLockText.add("  cacheKey: 7");
    yarnLockText.add("");
    yarnLockText.add("\"@babel/code-frame@npm:^7.0.0\":");
    yarnLockText.add("  version: 7.12.13");
    yarnLockText.add("  dependencies:");
    yarnLockText.add("    \"@babel/highlight\": ^7.12.13");
    YarnLockParser yarnLockParser = createYarnLockParser();
    YarnLock yarnLock = yarnLockParser.parseYarnLock(yarnLockText);
    YarnLockDependency dep = new YarnLockDependency("@babel/highlight", "^7.12.13", false);
    assertEntry(yarnLock, "@babel/code-frame", "^7.0.0", "7.12.13", dep);
    assertTrue(yarnLock.getFileFormatVersion().isPresent());
    assertEquals("4", yarnLock.getFileFormatVersion().get());
}
Also used : YarnLock(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock) YarnLockParser(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockParser) ArrayList(java.util.ArrayList) YarnLockDependency(com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency) Test(org.junit.jupiter.api.Test) UnitTest(com.synopsys.integration.detectable.annotations.UnitTest)

Aggregations

YarnLockParser (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockParser)13 YarnLock (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLock)11 Test (org.junit.jupiter.api.Test)11 UnitTest (com.synopsys.integration.detectable.annotations.UnitTest)10 YarnLockDependency (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockDependency)8 ArrayList (java.util.ArrayList)6 YarnLockEntry (com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntry)4 YarnLockLineAnalyzer (com.synopsys.integration.detectable.detectables.yarn.parse.YarnLockLineAnalyzer)3 YarnLockEntryParser (com.synopsys.integration.detectable.detectables.yarn.parse.entry.YarnLockEntryParser)3 YarnLockDependencySpecParser (com.synopsys.integration.detectable.detectables.yarn.parse.entry.section.YarnLockDependencySpecParser)3 YarnLockEntrySectionParserSet (com.synopsys.integration.detectable.detectables.yarn.parse.entry.section.YarnLockEntrySectionParserSet)3 File (java.io.File)1 NotNull (org.jetbrains.annotations.NotNull)1