Skip to content

Commit

Permalink
Negative number issue (2.13 branch - tests only) (#781)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning authored Jun 25, 2022
1 parent 7f64092 commit 80d4776
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public void testIntParsing() throws Exception
public void testIntParsingWithStrings() throws Exception
{
assertEquals(3, NumberInput.parseInt("3"));
assertEquals(3, NumberInput.parseInt("+3"));
assertEquals(0, NumberInput.parseInt("0"));
assertEquals(-3, NumberInput.parseInt("-3"));
assertEquals(27, NumberInput.parseInt("27"));
Expand All @@ -189,6 +190,24 @@ public void testIntParsingWithStrings() throws Exception
assertEquals(Integer.MAX_VALUE, NumberInput.parseInt(""+Integer.MAX_VALUE));
}

public void testLongParsingWithStrings() throws Exception
{
assertEquals(3, NumberInput.parseLong("3"));
assertEquals(3, NumberInput.parseLong("+3"));
assertEquals(0, NumberInput.parseLong("0"));
assertEquals(-3, NumberInput.parseLong("-3"));
assertEquals(27, NumberInput.parseLong("27"));
assertEquals(-31, NumberInput.parseLong("-31"));
assertEquals(271, NumberInput.parseLong("271"));
assertEquals(-131, NumberInput.parseLong("-131"));
assertEquals(2709, NumberInput.parseLong("2709"));
assertEquals(-9999, NumberInput.parseLong("-9999"));
assertEquals(Long.MIN_VALUE, NumberInput.parseLong(""+Long.MIN_VALUE));
assertEquals(Integer.MIN_VALUE-1, NumberInput.parseLong(""+(Integer.MIN_VALUE-1)));
assertEquals(Long.MAX_VALUE, NumberInput.parseLong(""+Long.MAX_VALUE));
assertEquals(Integer.MAX_VALUE+1, NumberInput.parseLong(""+(Integer.MAX_VALUE+1)));
}

/*
/**********************************************************************
/* Tests, Long
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.fasterxml.jackson.failing;

import com.fasterxml.jackson.core.BaseTest;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.core.json.JsonReadFeature;

public class FailingNonStandardNumberParsingTest
extends BaseTest
{
private final JsonFactory JSON_F = JsonFactory.builder()
.enable(JsonReadFeature.ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS)
.build();

protected JsonFactory jsonFactory() {
return JSON_F;
}

public void testLeadingDotInNegativeDecimalAllowedAsync() throws Exception {
_testLeadingDotInNegativeDecimalAllowed(jsonFactory(), MODE_DATA_INPUT);
}

public void testLeadingDotInNegativeDecimalAllowedBytes() throws Exception {
_testLeadingDotInNegativeDecimalAllowed(jsonFactory(), MODE_INPUT_STREAM);
_testLeadingDotInNegativeDecimalAllowed(jsonFactory(), MODE_INPUT_STREAM_THROTTLED);
}

public void testLeadingDotInNegativeDecimalAllowedReader() throws Exception {
_testLeadingDotInNegativeDecimalAllowed(jsonFactory(), MODE_READER);
}

private void _testLeadingDotInNegativeDecimalAllowed(JsonFactory f, int mode) throws Exception
{
JsonParser p = createParser(f, mode, " -.125 ");
try {
assertEquals(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
assertEquals(-0.125, p.getValueAsDouble());
assertEquals("-0.125", p.getDecimalValue().toString());
assertEquals("-.125", p.getText());
} finally {
p.close();
}
}
}

0 comments on commit 80d4776

Please sign in to comment.