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

Add missing calls to fail() when exceptions are expected to be thrown #107

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions src/test/java/com/mojang/brigadier/StringReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ public void readQuotedString_withImmediateRemaining() throws Exception {
public void readQuotedString_noOpen() throws Exception {
try {
new StringReader("hello world\"").readQuotedString();
fail();
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerExpectedStartOfQuote()));
assertThat(ex.getCursor(), is(0));
Expand All @@ -250,6 +251,7 @@ public void readQuotedString_noOpen() throws Exception {
public void readQuotedString_noClose() throws Exception {
try {
new StringReader("\"hello world").readQuotedString();
fail();
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerExpectedEndOfQuote()));
assertThat(ex.getCursor(), is(12));
Expand All @@ -260,6 +262,7 @@ public void readQuotedString_noClose() throws Exception {
public void readQuotedString_invalidEscape() throws Exception {
try {
new StringReader("\"hello\\nworld\"").readQuotedString();
fail();
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerInvalidEscape()));
assertThat(ex.getCursor(), is(7));
Expand All @@ -270,6 +273,7 @@ public void readQuotedString_invalidEscape() throws Exception {
public void readQuotedString_invalidQuoteEscape() throws Exception {
try {
new StringReader("'hello\\\"\'world").readQuotedString();
fail();
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerInvalidEscape()));
assertThat(ex.getCursor(), is(7));
Expand Down Expand Up @@ -320,6 +324,7 @@ public void readInt_negative() throws Exception {
public void readInt_invalid() throws Exception {
try {
new StringReader("12.34").readInt();
fail();
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerInvalidInt()));
assertThat(ex.getCursor(), is(0));
Expand All @@ -330,6 +335,7 @@ public void readInt_invalid() throws Exception {
public void readInt_none() throws Exception {
try {
new StringReader("").readInt();
fail();
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerExpectedInt()));
assertThat(ex.getCursor(), is(0));
Expand Down Expand Up @@ -372,6 +378,7 @@ public void readLong_negative() throws Exception {
public void readLong_invalid() throws Exception {
try {
new StringReader("12.34").readLong();
fail();
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerInvalidLong()));
assertThat(ex.getCursor(), is(0));
Expand All @@ -382,6 +389,7 @@ public void readLong_invalid() throws Exception {
public void readLong_none() throws Exception {
try {
new StringReader("").readLong();
fail();
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerExpectedLong()));
assertThat(ex.getCursor(), is(0));
Expand Down Expand Up @@ -432,6 +440,7 @@ public void readDouble_negative() throws Exception {
public void readDouble_invalid() throws Exception {
try {
new StringReader("12.34.56").readDouble();
fail();
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerInvalidDouble()));
assertThat(ex.getCursor(), is(0));
Expand All @@ -442,6 +451,7 @@ public void readDouble_invalid() throws Exception {
public void readDouble_none() throws Exception {
try {
new StringReader("").readDouble();
fail();
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerExpectedDouble()));
assertThat(ex.getCursor(), is(0));
Expand Down Expand Up @@ -492,6 +502,7 @@ public void readFloat_negative() throws Exception {
public void readFloat_invalid() throws Exception {
try {
new StringReader("12.34.56").readFloat();
fail();
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerInvalidFloat()));
assertThat(ex.getCursor(), is(0));
Expand All @@ -502,6 +513,7 @@ public void readFloat_invalid() throws Exception {
public void readFloat_none() throws Exception {
try {
new StringReader("").readFloat();
fail();
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandSyntaxException.BUILT_IN_EXCEPTIONS.readerExpectedFloat()));
assertThat(ex.getCursor(), is(0));
Expand Down