Merge pull request #80 from trilogy-group/master

Expose IsTest and GetLangaugeType methods  & Fix test cases for Java Bindings
This commit is contained in:
Alex 2022-03-24 12:16:29 +01:00 committed by GitHub
commit f1e62adcd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 1 deletions

View File

@ -237,4 +237,24 @@ public class Enry {
public static synchronized String getColor(String language) {
return toJavaString(nativeLib.GetColor(toGoString(language)));
}
/**
* Reports whether the given path is a test path or not.
*
* @param path of the file or directory
* @return whether it's test or not
*/
public static synchronized boolean isTest(String path) {
return toJavaBool(nativeLib.IsTest(toGoString(path)));
}
/**
* Returns type for given language.
*
* @param language of the file
* @return type (data, programming, markup, prose)
*/
public static synchronized String getLanguageType(String language) {
return toJavaString(nativeLib.GetLanguageType(toGoString(language)));
}
}

View File

@ -120,7 +120,7 @@ public class EnryTest {
"extern int foo(void *bar);";
String[] result = Enry.getLanguages("foo.h", code.getBytes());
String[] expected = {"C", "C++", "Objective-C"};
String[] expected = {"C"};
assertArrayEquals(expected, result);
}
@ -169,6 +169,19 @@ public class EnryTest {
);
}
@Test
public void isTest() {
assertTrue(Enry.isTest("test_foo.py"));
assertTrue(Enry.isTest("test/java/tech/sourced/enry/EnryTest.java"));
assertFalse(Enry.isTest("foo.py"));
assertFalse(Enry.isTest("src/java/foo.java"));
}
@Test
public void getLanguageType() {
assertEquals("data", Enry.getLanguageType("CSV"));
}
void assertGuess(String language, boolean safe, Guess guess) {
assertEquals(language, guess.language);
assertEquals(safe, guess.safe);

View File

@ -5,6 +5,7 @@ package main
import "C"
import "github.com/go-enry/go-enry/v2"
import "github.com/go-enry/go-enry/v2/data"
//export GetLanguage
func GetLanguage(filename string, content []byte) string {
@ -136,6 +137,16 @@ func GetColor(language string) string {
return enry.GetColor(language)
}
//export IsTest
func IsTest(path string) bool {
return enry.IsTest(path)
}
//export GetLanguageType
func GetLanguageType(language string) string {
return data.Type(enry.GetLanguageType(language)).String()
}
func strSliceCopy(result *[]*C.char, slice []string) {
for _, str := range slice {
*result = append(*result, C.CString(str))