-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added simple tests for multi language
- Loading branch information
1 parent
0dd5f8e
commit d62a358
Showing
5 changed files
with
106 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
languages/multi-language/src/test/java/de/java/multilang/MultilangTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package de.java.multilang; | ||
|
||
import static de.jplag.SharedTokenType.FILE_END; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.TreeSet; | ||
|
||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import de.jplag.ParsingException; | ||
import de.jplag.Token; | ||
import de.jplag.TokenType; | ||
import de.jplag.cpp.CPPTokenType; | ||
import de.jplag.java.JavaTokenType; | ||
import de.jplag.multilang.MultiLanguage; | ||
import de.jplag.multilang.MultiLanguageOptions; | ||
|
||
public class MultilangTest { | ||
private static File testDataDirectory; | ||
private static File javaCode; | ||
private static File cppCode; | ||
|
||
private static List<TokenType> expectedTokens = List.of(CPPTokenType.FUNCTION_BEGIN, CPPTokenType.RETURN, CPPTokenType.FUNCTION_END, FILE_END, | ||
JavaTokenType.J_CLASS_BEGIN, JavaTokenType.J_CLASS_END, FILE_END); | ||
|
||
@BeforeAll | ||
static void setUp() throws IOException { | ||
testDataDirectory = Files.createTempDirectory("multiLanguageTestData").toFile(); | ||
cppCode = new File(testDataDirectory, "CppCode.cpp"); | ||
javaCode = new File(testDataDirectory, "JavaCode.java"); | ||
|
||
MultilangTest.class.getResourceAsStream("/de/jplag/multilang/testDataSet/CppCode.cpp").transferTo(new FileOutputStream(cppCode)); | ||
MultilangTest.class.getResourceAsStream("/de/jplag/multilang/testDataSet/JavaCode.java").transferTo(new FileOutputStream(javaCode)); | ||
} | ||
|
||
@Test | ||
void testMultiLanguageParsing() throws ParsingException { | ||
MultiLanguage languageModule = new MultiLanguage(); | ||
((MultiLanguageOptions) languageModule.getOptions()).languageNames.setValue("java,cpp"); | ||
|
||
Set<File> sources = new TreeSet<>(List.of(javaCode, cppCode)); // Using TreeSet to ensure order of entries | ||
List<Token> tokens = languageModule.parse(sources, false); | ||
|
||
Assertions.assertEquals(expectedTokens, tokens.stream().map(Token::getType).toList()); | ||
} | ||
|
||
@Test | ||
void testNoLanguagesConfigured() { | ||
MultiLanguage languageModule = new MultiLanguage(); | ||
Assertions.assertThrowsExactly(IllegalArgumentException.class, () -> { | ||
languageModule.parse(Set.of(javaCode, cppCode), false); | ||
}); | ||
} | ||
|
||
@Test | ||
void testInvalidLanguage() { | ||
MultiLanguage languageModule = new MultiLanguage(); | ||
((MultiLanguageOptions) languageModule.getOptions()).languageNames.setValue("thisIsNotALanguage"); | ||
|
||
Assertions.assertThrowsExactly(IllegalArgumentException.class, () -> { | ||
languageModule.parse(Set.of(javaCode, cppCode), false); | ||
}); | ||
} | ||
|
||
@AfterAll | ||
static void cleanUp() { | ||
javaCode.delete(); | ||
cppCode.delete(); | ||
testDataDirectory.delete(); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
languages/multi-language/src/test/resources/de/jplag/multilang/testDataSet/CppCode.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
int main() { | ||
return 0; | ||
} |
3 changes: 3 additions & 0 deletions
3
languages/multi-language/src/test/resources/de/jplag/multilang/testDataSet/JavaCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
public class JavaCode { | ||
|
||
} |