diff --git a/java/src/main/java/tech/sourced/enry/Enry.java b/java/src/main/java/tech/sourced/enry/Enry.java index 193922c..388163e 100644 --- a/java/src/main/java/tech/sourced/enry/Enry.java +++ b/java/src/main/java/tech/sourced/enry/Enry.java @@ -247,4 +247,14 @@ public class Enry { 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))); + } } diff --git a/java/src/test/java/tech/sourced/enry/EnryTest.java b/java/src/test/java/tech/sourced/enry/EnryTest.java index 32d9e37..25ba5d2 100644 --- a/java/src/test/java/tech/sourced/enry/EnryTest.java +++ b/java/src/test/java/tech/sourced/enry/EnryTest.java @@ -177,6 +177,11 @@ public class EnryTest { 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); diff --git a/shared/enry.go b/shared/enry.go index b109804..1b1a538 100644 --- a/shared/enry.go +++ b/shared/enry.go @@ -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 { @@ -141,10 +142,15 @@ 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)) } } -func main() {} +func main() {} \ No newline at end of file