Skip to content

Commit

Permalink
Impelement language agnostic files() method for ProjectFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
Muntazir Fadhel committed Dec 14, 2022
1 parent 98aaa52 commit b8a99c7
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>com.github.hadii-tech</groupId>
<artifactId>clarpse</artifactId>
<version>7.1.0</version>
<version>7.1.1</version>
<packaging>jar</packaging>

<name>${project.groupId}:${project.artifactId}</name>
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/hadii/clarpse/compiler/ProjectFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ public final Collection<ProjectFile> files(Lang language) {
return this.langToFilesMap.getOrDefault(language, new ArrayList<>());
}

public final Collection<ProjectFile> files() {
Set<ProjectFile> allFiles = new HashSet<>();
this.langToFilesMap.forEach((lang, files) -> allFiles.addAll(files));
return allFiles;
}

public String projectDir() {
if (this.projectDir != null && !this.projectDir.isEmpty()) {
return this.projectDir;
Expand Down
41 changes: 41 additions & 0 deletions src/test/java/com/hadii/test/ProjectFilesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,47 @@ public void testProjectFilesSize() {
assertEquals(2, pfs.size());
}

@Test
public void testGetAllFiles() {
ProjectFiles pfs = new ProjectFiles();
pfs.insertFile(new ProjectFile("/test.java", "{}"));
pfs.insertFile(new ProjectFile("/tester.go", "{}"));
assertEquals(2, pfs.files().size());
}

@Test
public void testGetAllGoFiles() {
ProjectFiles pfs = new ProjectFiles();
pfs.insertFile(new ProjectFile("/test.java", "{}"));
pfs.insertFile(new ProjectFile("/tester.go", "{}"));
assertEquals(1, pfs.files(Lang.GOLANG).size());
}

@Test
public void testGetAllFilesForNonExistentLang() {
ProjectFiles pfs = new ProjectFiles();
pfs.insertFile(new ProjectFile("/test.java", "{}"));
pfs.insertFile(new ProjectFile("/tester.go", "{}"));
assertEquals(0, pfs.files(Lang.JAVASCRIPT).size());
}

@Test
public void testGetAllJavaFiles() {
ProjectFiles pfs = new ProjectFiles();
pfs.insertFile(new ProjectFile("/test.java", "{}"));
pfs.insertFile(new ProjectFile("/tester.go", "{}"));
assertEquals(1, pfs.files(Lang.JAVA).size());
}

@Test
public void testGetAllJSFiles() {
ProjectFiles pfs = new ProjectFiles();
pfs.insertFile(new ProjectFile("/test.js", "{}"));
pfs.insertFile(new ProjectFile("/tester.go", "{}"));
assertEquals(1, pfs.files(Lang.JAVASCRIPT).size());
}


@Test
public void testEmptyProjectFilesSize() {
ProjectFiles pfs = new ProjectFiles();
Expand Down

0 comments on commit b8a99c7

Please sign in to comment.