Merge f050cd4afe
into f20bede62a
This commit is contained in:
commit
c11c9f53a6
6 changed files with 94 additions and 8 deletions
src
|
@ -85,7 +85,11 @@ public class StringReader implements ImmutableStringReader {
|
|||
}
|
||||
|
||||
public static boolean isAllowedNumber(final char c) {
|
||||
return c >= '0' && c <= '9' || c == '.' || c == '-';
|
||||
return isAllowedInteger(c) || c == '.' || c == 'e' || c == 'E';
|
||||
}
|
||||
|
||||
public static boolean isAllowedInteger(final char c) {
|
||||
return c >= '0' && c <= '9' || c == '+' || c == '-';
|
||||
}
|
||||
|
||||
public static boolean isQuotedStringStart(char c) {
|
||||
|
@ -100,7 +104,7 @@ public class StringReader implements ImmutableStringReader {
|
|||
|
||||
public int readInt() throws CommandSyntaxException {
|
||||
final int start = cursor;
|
||||
while (canRead() && isAllowedNumber(peek())) {
|
||||
while (canRead() && isAllowedInteger(peek())) {
|
||||
skip();
|
||||
}
|
||||
final String number = string.substring(start, cursor);
|
||||
|
@ -117,7 +121,7 @@ public class StringReader implements ImmutableStringReader {
|
|||
|
||||
public long readLong() throws CommandSyntaxException {
|
||||
final int start = cursor;
|
||||
while (canRead() && isAllowedNumber(peek())) {
|
||||
while (canRead() && isAllowedInteger(peek())) {
|
||||
skip();
|
||||
}
|
||||
final String number = string.substring(start, cursor);
|
||||
|
|
|
@ -11,7 +11,8 @@ import java.util.Arrays;
|
|||
import java.util.Collection;
|
||||
|
||||
public class DoubleArgumentType implements ArgumentType<Double> {
|
||||
private static final Collection<String> EXAMPLES = Arrays.asList("0", "1.2", ".5", "-1", "-.5", "-1234.56");
|
||||
private static final Collection<String> EXAMPLES = Arrays.asList("0", "1.2", ".5", "-1", "+1", "-.5", "-1234.56",
|
||||
"1e123", "1E123", "1.2e3", "1.2e-3", "-123.456e-7");
|
||||
|
||||
private final double minimum;
|
||||
private final double maximum;
|
||||
|
|
|
@ -11,7 +11,8 @@ import java.util.Arrays;
|
|||
import java.util.Collection;
|
||||
|
||||
public class FloatArgumentType implements ArgumentType<Float> {
|
||||
private static final Collection<String> EXAMPLES = Arrays.asList("0", "1.2", ".5", "-1", "-.5", "-1234.56");
|
||||
private static final Collection<String> EXAMPLES = Arrays.asList("0", "1.2", ".5", "-1", "+1", "-.5", "-1234.56",
|
||||
"1e123", "1E123", "1.2e3", "1.2e-3", "-123.456e-7");
|
||||
|
||||
private final float minimum;
|
||||
private final float maximum;
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.util.Arrays;
|
|||
import java.util.Collection;
|
||||
|
||||
public class IntegerArgumentType implements ArgumentType<Integer> {
|
||||
private static final Collection<String> EXAMPLES = Arrays.asList("0", "123", "-123");
|
||||
private static final Collection<String> EXAMPLES = Arrays.asList("0", "123", "-123", "+123");
|
||||
|
||||
private final int minimum;
|
||||
private final int maximum;
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.util.Arrays;
|
|||
import java.util.Collection;
|
||||
|
||||
public class LongArgumentType implements ArgumentType<Long> {
|
||||
private static final Collection<String> EXAMPLES = Arrays.asList("0", "123", "-123");
|
||||
private static final Collection<String> EXAMPLES = Arrays.asList("0", "123", "-123", "+123");
|
||||
|
||||
private final long minimum;
|
||||
private final long maximum;
|
||||
|
|
|
@ -315,6 +315,14 @@ public class StringReaderTest {
|
|||
assertThat(reader.getRead(), equalTo("-1234567890"));
|
||||
assertThat(reader.getRemaining(), equalTo(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readInt_explicitPositive() throws Exception {
|
||||
final StringReader reader = new StringReader("+1234567890");
|
||||
assertThat(reader.readInt(), is(+1234567890));
|
||||
assertThat(reader.getRead(), equalTo("+1234567890"));
|
||||
assertThat(reader.getRemaining(), equalTo(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readInt_invalid() throws Exception {
|
||||
|
@ -367,6 +375,14 @@ public class StringReaderTest {
|
|||
assertThat(reader.getRead(), equalTo("-1234567890"));
|
||||
assertThat(reader.getRemaining(), equalTo(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readLong_explicitPositive() throws Exception {
|
||||
final StringReader reader = new StringReader("+1234567890");
|
||||
assertThat(reader.readLong(), is(+1234567890L));
|
||||
assertThat(reader.getRead(), equalTo("+1234567890"));
|
||||
assertThat(reader.getRemaining(), equalTo(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readLong_invalid() throws Exception {
|
||||
|
@ -427,6 +443,38 @@ public class StringReaderTest {
|
|||
assertThat(reader.getRead(), equalTo("-123"));
|
||||
assertThat(reader.getRemaining(), equalTo(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readDouble_explicitPositive() throws Exception {
|
||||
final StringReader reader = new StringReader("+123");
|
||||
assertThat(reader.readDouble(), is(+123.0));
|
||||
assertThat(reader.getRead(), equalTo("+123"));
|
||||
assertThat(reader.getRemaining(), equalTo(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readDouble_exponent() throws Exception {
|
||||
final StringReader reader = new StringReader("123e4");
|
||||
assertThat(reader.readDouble(), is(123e4));
|
||||
assertThat(reader.getRead(), equalTo("123e4"));
|
||||
assertThat(reader.getRemaining(), equalTo(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readDouble_negativeExponent() throws Exception {
|
||||
final StringReader reader = new StringReader("123e-4");
|
||||
assertThat(reader.readDouble(), is(123e-4));
|
||||
assertThat(reader.getRead(), equalTo("123e-4"));
|
||||
assertThat(reader.getRemaining(), equalTo(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readDouble_explicitPositiveExponent() throws Exception {
|
||||
final StringReader reader = new StringReader("123e+4");
|
||||
assertThat(reader.readDouble(), is(123e+4));
|
||||
assertThat(reader.getRead(), equalTo("123e+4"));
|
||||
assertThat(reader.getRemaining(), equalTo(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readDouble_invalid() throws Exception {
|
||||
|
@ -487,6 +535,38 @@ public class StringReaderTest {
|
|||
assertThat(reader.getRead(), equalTo("-123"));
|
||||
assertThat(reader.getRemaining(), equalTo(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readFloat_explicitPositive() throws Exception {
|
||||
final StringReader reader = new StringReader("+123");
|
||||
assertThat(reader.readFloat(), is(+123.0f));
|
||||
assertThat(reader.getRead(), equalTo("+123"));
|
||||
assertThat(reader.getRemaining(), equalTo(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readFloat_exponent() throws Exception {
|
||||
final StringReader reader = new StringReader("123e4");
|
||||
assertThat(reader.readFloat(), is(123e4f));
|
||||
assertThat(reader.getRead(), equalTo("123e4"));
|
||||
assertThat(reader.getRemaining(), equalTo(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readFloat_negativeExponent() throws Exception {
|
||||
final StringReader reader = new StringReader("123e-4");
|
||||
assertThat(reader.readFloat(), is(123e-4f));
|
||||
assertThat(reader.getRead(), equalTo("123e-4"));
|
||||
assertThat(reader.getRemaining(), equalTo(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readFloat_explicitPositiveExponent() throws Exception {
|
||||
final StringReader reader = new StringReader("123e+4");
|
||||
assertThat(reader.readFloat(), is(123e+4f));
|
||||
assertThat(reader.getRead(), equalTo("123e+4"));
|
||||
assertThat(reader.getRemaining(), equalTo(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readFloat_invalid() throws Exception {
|
||||
|
@ -585,4 +665,4 @@ public class StringReaderTest {
|
|||
assertThat(ex.getCursor(), is(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue