mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-05-23 08:30:07 -03:00
fix getLanguage when arguments are null
This commit is contained in:
parent
0fe0a97f67
commit
1d7b975743
@ -15,12 +15,19 @@ class GoUtils {
|
||||
bytes = str.getBytes("utf-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
bytes = str.getBytes();
|
||||
} catch (NullPointerException e) {
|
||||
bytes = null;
|
||||
}
|
||||
|
||||
int length = 0;
|
||||
Pointer ptr = null;
|
||||
if (bytes != null) {
|
||||
length = bytes.length;
|
||||
ptr = ptrFromBytes(bytes);
|
||||
}
|
||||
|
||||
GoString.ByValue val = new GoString.ByValue();
|
||||
val.n = bytes.length;
|
||||
Pointer ptr = new Memory(bytes.length);
|
||||
ptr.write(0, bytes, 0, bytes.length);
|
||||
val.n = length;
|
||||
val.p = ptr;
|
||||
return val;
|
||||
}
|
||||
@ -49,7 +56,14 @@ class GoUtils {
|
||||
}
|
||||
|
||||
static GoSlice.ByValue toGoByteSlice(byte[] bytes) {
|
||||
return sliceFromPtr(bytes.length, ptrFromBytes(bytes));
|
||||
int length = 0;
|
||||
Pointer ptr = null;
|
||||
if (bytes != null) {
|
||||
length = bytes.length;
|
||||
ptr = ptrFromBytes(bytes);
|
||||
}
|
||||
|
||||
return sliceFromPtr(length, ptr);
|
||||
}
|
||||
|
||||
static GoSlice.ByValue sliceFromPtr(int len, Pointer ptr) {
|
||||
|
@ -18,6 +18,17 @@ public class EnryTest {
|
||||
assertEquals("PHP", Enry.getLanguage("foobar.php", code.getBytes()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLanguageWithNullContent() {
|
||||
assertEquals("Python", Enry.getLanguage("foo.py", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLanguageWithNullFilename() {
|
||||
byte[] content = "#!/usr/bin/env python".getBytes();
|
||||
assertEquals("Python", Enry.getLanguage(null, content));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLanguageByContent() {
|
||||
String code = "<?php $foo = bar();";
|
||||
|
Loading…
x
Reference in New Issue
Block a user