Skip to content

Commit

Permalink
Test the key for workspace match.
Browse files Browse the repository at this point in the history
See #415
  • Loading branch information
waynebeaton committed Dec 20, 2024
1 parent ebc42f4 commit 25729a8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ private boolean isLink() {
}

public boolean isProjectContent() {
if (isInWorkspace(key)) return true;
return isLink() && isInWorkspace(getResolved());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,63 @@ void testV3Format() throws IOException {
// in the results. This record should manifest as langium-statemachine-dsl (see
// below)
assertFalse(ids.stream().anyMatch(each -> "statemachine".equals(each.getName())));


// Test that a handful of content ids are detected as expected.
var includes = new IContentId[] { ContentId.getContentId("npm", "npmjs", "-", "ansi-styles", "3.2.1"),
ContentId.getContentId("npm", "npmjs", "@typescript-eslint", "eslint-plugin", "6.4.1"),
ContentId.getContentId("npm", "npmjs", "@types", "minimatch", "3.0.5"),
// Test that a handful of content ids are absent as expected.
var absent = new IContentId[] {
ContentId.getContentId("npm", "npmjs", "-", "langium-requirements-dsl", "2.1.0"),
ContentId.getContentId("npm", "npmjs", "-", "langium-domainmodel-dsl", "2.1.0"),
ContentId.getContentId("npm", "npmjs", "-", "langium-statemachine-dsl", "2.1.0") };
ContentId.getContentId("npm", "npmjs", "-", "langium-statemachine-dsl", "2.1.0")
};

assertFalse(Arrays.stream(absent).anyMatch(each -> ids.contains(each)));

// Test that a handful of content ids are detected as expected.
var includes = new IContentId[] {
ContentId.getContentId("npm", "npmjs", "-", "ansi-styles", "3.2.1"),
ContentId.getContentId("npm", "npmjs", "@typescript-eslint", "eslint-plugin", "6.4.1"),
ContentId.getContentId("npm", "npmjs", "@types", "minimatch", "3.0.5")
};

assertTrue(Arrays.stream(includes).allMatch(each -> ids.contains(each)));
}
}

@Test
void testV3FormatWorkspaceIgnore() throws IOException {
try (InputStream input = this.getClass().getResourceAsStream("/test_data_package-lock-v3-theia.json")) {
PackageLockFileReader reader = new PackageLockFileReader(input);
var ids = reader.contentIds().collect(Collectors.toList());

assertTrue(ids.stream().allMatch(each -> each.isValid()));

// Test that a handful of content ids are absent as expected.
var absent = new IContentId[] {
ContentId.getContentId("npm", "npmjs", "@theia", "terminal", "1.55.0"),
ContentId.getContentId("npm", "npmjs", "@theia", "toolbar", "1.55.0"),
ContentId.getContentId("npm", "npmjs", "-", "e2e-tests", "1.12.0-next"),
ContentId.getContentId("npm", "npmjs", "sample-namespace", "plugin-a", "1.55.0"),
ContentId.getContentId("npm", "npmjs", "sample-namespace", "plugin-b", "1.55.0")
};

assertFalse(Arrays.stream(absent).anyMatch(each -> ids.contains(each)));

// Test that a handful of content ids are detected as expected.
var includes = new IContentId[] {
ContentId.getContentId("npm", "npmjs", "-", "p-timeout", "3.2.0"),
ContentId.getContentId("npm", "npmjs", "-", "xterm-addon-fit", "0.8.0"),
ContentId.getContentId("npm", "npmjs", "-", "async-mutex", "0.4.1")
};

var exists = Arrays.stream(includes).filter(each -> ids.contains(each)).collect(Collectors.toList());

assertTrue(Arrays.stream(includes).allMatch(each -> ids.contains(each)));

var matches = ids.stream().filter(each -> "toolbar".equals(each.getName())).collect(Collectors.toList());
assertFalse(ids.stream().anyMatch(each -> "plugin-a".equals(each.getName())));
}
}

@Test
void testAllRecordsDetected() throws IOException {
try (InputStream input = this.getClass().getResourceAsStream("/differentResolved.json")) {
Expand Down

0 comments on commit 25729a8

Please sign in to comment.