Merge branch 'master' into kotest-fixes
This commit is contained in:
@@ -120,10 +120,10 @@ public final class ASTNumericLiteral extends AbstractLiteral {
|
||||
* for the literal {@code 0} (which can really be any base).
|
||||
*/
|
||||
public int getBase() {
|
||||
return getBase(getLiteralText());
|
||||
return getBase(getLiteralText(), isIntegral());
|
||||
}
|
||||
|
||||
static int getBase(Chars image) {
|
||||
static int getBase(Chars image, boolean isIntegral) {
|
||||
if (image.length() > 1 && image.charAt(0) == '0') {
|
||||
switch (image.charAt(1)) {
|
||||
case 'x':
|
||||
@@ -132,10 +132,8 @@ public final class ASTNumericLiteral extends AbstractLiteral {
|
||||
case 'b':
|
||||
case 'B':
|
||||
return 2;
|
||||
case '.':
|
||||
return 10;
|
||||
default:
|
||||
return 8;
|
||||
return isIntegral ? 8 : 10;
|
||||
}
|
||||
}
|
||||
return 10;
|
||||
@@ -172,7 +170,7 @@ public final class ASTNumericLiteral extends AbstractLiteral {
|
||||
* <p>Invalid literals or overflows result in {@code 0L}.
|
||||
*/
|
||||
static long parseIntegralValue(Chars image) {
|
||||
final int base = getBase(image);
|
||||
final int base = getBase(image, true);
|
||||
if (base == 8) {
|
||||
image = image.subSequence(1); // 0
|
||||
} else if (base != 10) {
|
||||
|
||||
@@ -387,6 +387,23 @@ $delim
|
||||
it::getBase shouldBe 10
|
||||
}
|
||||
}
|
||||
|
||||
"0." should parseAs {
|
||||
number(DOUBLE) {
|
||||
it::getBase shouldBe 10
|
||||
}
|
||||
}
|
||||
val doubleOrFloatInBase10: NodeSpec<*> = {
|
||||
number {
|
||||
it::getBase shouldBe 10
|
||||
}
|
||||
}
|
||||
"05e10" should parseAs(doubleOrFloatInBase10)
|
||||
"05e10f" should parseAs(doubleOrFloatInBase10)
|
||||
"00f" should parseAs(doubleOrFloatInBase10)
|
||||
"00d" should parseAs(doubleOrFloatInBase10)
|
||||
"00D" should parseAs(doubleOrFloatInBase10)
|
||||
"050.0" should parseAs(doubleOrFloatInBase10)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -401,6 +418,7 @@ $delim
|
||||
it::getValueAsDouble shouldBe 30.0
|
||||
it::getValueAsFloat shouldBe 30f
|
||||
it::getValueAsInt shouldBe 30
|
||||
it::getBase shouldBe 16
|
||||
}
|
||||
}
|
||||
|
||||
@@ -412,6 +430,7 @@ $delim
|
||||
it::getValueAsDouble shouldBe 7.5
|
||||
it::getValueAsFloat shouldBe 7.5f
|
||||
it::getValueAsInt shouldBe 7
|
||||
it::getBase shouldBe 16
|
||||
}
|
||||
}
|
||||
|
||||
@@ -431,6 +450,7 @@ $delim
|
||||
it::getValueAsFloat shouldBe 15f
|
||||
it::getValueAsInt shouldBe 15
|
||||
it::getValueAsLong shouldBe 15L
|
||||
it::getBase shouldBe 16
|
||||
}
|
||||
}
|
||||
|
||||
@@ -477,6 +497,7 @@ $delim
|
||||
it::getValueAsFloat shouldBe 3f
|
||||
it::getValueAsInt shouldBe 3
|
||||
it::getValueAsLong shouldBe 3L
|
||||
it::getBase shouldBe 2
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
@@ -244,6 +244,16 @@ public class Foo {
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>ok, float literal in hexadecimal and exponent</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
float f = 0x1.0000_ffff_eeeep+2f;
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>ok, Lengthy numeric literal with variable name as serialVersionUID</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
|
||||
+42
@@ -54,6 +54,48 @@ public class Foo {
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>OK, double value</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
double d = 012.0;
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>OK, double suffix</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
double d1 = 012d;
|
||||
double d2 = 012D;
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>OK, float suffix</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
float f = 012f;
|
||||
float f = 012F;
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>OK, double value with exponent</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
double d = 012e0;
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>bad, 012L</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
|
||||
Reference in New Issue
Block a user