Expose GetLanguageType (#2)

This commit is contained in:
Utsav Chokshi 2022-03-02 10:32:57 +05:30 committed by GitHub
parent 821f01cdde
commit 4e3a49c565
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 1 deletions

@ -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)));
}
}

@ -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);

@ -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() {}