mirror of
https://github.com/ralsina/tartrazine.git
synced 2024-11-10 13:32:24 +00: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");
|
bytes = str.getBytes("utf-8");
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
bytes = str.getBytes();
|
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();
|
GoString.ByValue val = new GoString.ByValue();
|
||||||
val.n = bytes.length;
|
val.n = length;
|
||||||
Pointer ptr = new Memory(bytes.length);
|
|
||||||
ptr.write(0, bytes, 0, bytes.length);
|
|
||||||
val.p = ptr;
|
val.p = ptr;
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
@ -49,7 +56,14 @@ class GoUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static GoSlice.ByValue toGoByteSlice(byte[] bytes) {
|
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) {
|
static GoSlice.ByValue sliceFromPtr(int len, Pointer ptr) {
|
||||||
|
@ -18,6 +18,17 @@ public class EnryTest {
|
|||||||
assertEquals("PHP", Enry.getLanguage("foobar.php", code.getBytes()));
|
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
|
@Test
|
||||||
public void getLanguageByContent() {
|
public void getLanguageByContent() {
|
||||||
String code = "<?php $foo = bar();";
|
String code = "<?php $foo = bar();";
|
||||||
|
Loading…
Reference in New Issue
Block a user