Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into oersi
Browse files Browse the repository at this point in the history
  • Loading branch information
fsteeg committed Dec 3, 2020
2 parents ae1fb79 + fdd7035 commit 32dde6e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ public JsonDecoder() {
resetRecordCount();
}

public void setAllowComments(final boolean allowComments) {
jsonFactory.configure(JsonParser.Feature.ALLOW_COMMENTS, allowComments);
}

public boolean getAllowComments() {
return jsonFactory.isEnabled(JsonParser.Feature.ALLOW_COMMENTS);
}

public void setArrayMarker(final String arrayMarker) {
this.arrayMarker = arrayMarker;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verifyZeroInteractions;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -196,4 +197,47 @@ public void testShouldNotParseTrailingGarbage() {
jsonDecoder.process("{\"lit\":\"value\"}XXX");
}

@Test
public void testShouldNotParseComments() {
exception.expect(MetafactureException.class);
exception.expectMessage("Unexpected character ('/' (code 47))");

Assert.assertFalse(jsonDecoder.getAllowComments());

jsonDecoder.process("//{\"lit\":\"value\"}");
}

@Test
public void testShouldParseCommentsIfEnabled() {
jsonDecoder.setAllowComments(true);
Assert.assertTrue(jsonDecoder.getAllowComments());

jsonDecoder.process("//{\"lit\":\"value\"}");

verifyZeroInteractions(receiver);
}

@Test
public void testShouldNotParseInlineComments() {
exception.expect(MetafactureException.class);
exception.expectMessage("Unexpected character ('/' (code 47))");

Assert.assertFalse(jsonDecoder.getAllowComments());

jsonDecoder.process("{\"lit\":/*comment*/\"value\"}");
}

@Test
public void testShouldParseInlineCommentsIfEnabled() {
jsonDecoder.setAllowComments(true);
Assert.assertTrue(jsonDecoder.getAllowComments());

jsonDecoder.process("{\"lit\":/*comment*/\"value\"}");

final InOrder ordered = inOrder(receiver);
ordered.verify(receiver).startRecord("1");
ordered.verify(receiver).literal("lit", "value");
ordered.verify(receiver).endRecord();
}

}

0 comments on commit 32dde6e

Please sign in to comment.