Skip to content

Commit

Permalink
fix negatives and add octal test
Browse files Browse the repository at this point in the history
  • Loading branch information
rjernst committed Jul 24, 2018
1 parent c406980 commit 54c30ca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ enum Type {
public Object convert(Object value) {
try {
String strValue = value.toString();
if (strValue.startsWith("0x")) {
if (strValue.startsWith("0x") || strValue.startsWith("-0x")) {
return Integer.decode(strValue);
}
return Integer.parseInt(strValue);
Expand All @@ -57,7 +57,7 @@ public Object convert(Object value) {
public Object convert(Object value) {
try {
String strValue = value.toString();
if (strValue.startsWith("0x")) {
if (strValue.startsWith("0x") || strValue.startsWith("-0x")) {
return Long.decode(strValue);
}
return Long.parseLong(strValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ public void testConvertIntHex() throws Exception {
assertThat(ingestDocument.getFieldValue(fieldName, Integer.class), equalTo(randomInt));
}

public void testConvertIntLeadingZero() throws Exception {
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, "010");
Processor processor = new ConvertProcessor(randomAlphaOfLength(10), fieldName, fieldName, Type.INTEGER, false);
processor.execute(ingestDocument);
assertThat(ingestDocument.getFieldValue(fieldName, Integer.class), equalTo(10));
}

public void testConvertIntHexError() {
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
String value = "0x" + randomAlphaOfLengthBetween(1, 10);
Expand Down Expand Up @@ -121,6 +129,14 @@ public void testConvertLongHex() throws Exception {
assertThat(ingestDocument.getFieldValue(fieldName, Long.class), equalTo(randomLong));
}

public void testConvertLongLeadingZero() throws Exception {
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, "010");
Processor processor = new ConvertProcessor(randomAlphaOfLength(10), fieldName, fieldName, Type.LONG, false);
processor.execute(ingestDocument);
assertThat(ingestDocument.getFieldValue(fieldName, Long.class), equalTo(10));
}

public void testConvertLongHexError() {
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
String value = "0x" + randomAlphaOfLengthBetween(1, 10);
Expand Down

0 comments on commit 54c30ca

Please sign in to comment.