Add string reader long tests
This commit is contained in:
parent
88714288a7
commit
b10b4479e2
1 changed files with 52 additions and 0 deletions
|
@ -294,6 +294,58 @@ public class StringReaderTest {
|
|||
assertThat(reader.getRemaining(), equalTo("foo bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readLong() 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_negative() 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 {
|
||||
try {
|
||||
new StringReader("12.34").readLong();
|
||||
} catch (final CommandSyntaxException ex) {
|
||||
assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerInvalidLong()));
|
||||
assertThat(ex.getCursor(), is(0));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readLong_none() throws Exception {
|
||||
try {
|
||||
new StringReader("").readLong();
|
||||
} catch (final CommandSyntaxException ex) {
|
||||
assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerExpectedLong()));
|
||||
assertThat(ex.getCursor(), is(0));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readLong_withRemaining() throws Exception {
|
||||
final StringReader reader = new StringReader("1234567890 foo bar");
|
||||
assertThat(reader.readLong(), is(1234567890L));
|
||||
assertThat(reader.getRead(), equalTo("1234567890"));
|
||||
assertThat(reader.getRemaining(), equalTo(" foo bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readLong_withRemainingImmediate() throws Exception {
|
||||
final StringReader reader = new StringReader("1234567890foo bar");
|
||||
assertThat(reader.readLong(), is(1234567890L));
|
||||
assertThat(reader.getRead(), equalTo("1234567890"));
|
||||
assertThat(reader.getRemaining(), equalTo("foo bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readDouble() throws Exception {
|
||||
final StringReader reader = new StringReader("123");
|
||||
|
|
Loading…
Reference in a new issue