Skip to content

Commit

Permalink
Add string reader long tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Earthcomputer authored and Dinnerbone committed Sep 26, 2018
1 parent 8871428 commit b10b447
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/test/java/com/mojang/brigadier/StringReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,58 @@ public void readInt_withRemainingImmediate() throws Exception {
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");
Expand Down

0 comments on commit b10b447

Please sign in to comment.