Skip to content

Commit

Permalink
Add missing calls to fail() when exceptions are expected to be thrown
Browse files Browse the repository at this point in the history
Fixes Mojang#106.  Without this, the test could pass if no exception is thrown, in addition to the wanted result of a matching exception being thrown.
  • Loading branch information
Pokechu22 committed Nov 11, 2021
1 parent cf754c4 commit 54963c9
Showing 1 changed file with 12 additions and 0 deletions.
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

0 comments on commit 54963c9

Please sign in to comment.