Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negative number issue (2.13 branch - tests only) #781

Merged
merged 3 commits into from
Jun 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
}