|
19 | 19 | import static org.mockito.Mockito.times;
|
20 | 20 | import static org.mockito.Mockito.verifyZeroInteractions;
|
21 | 21 |
|
| 22 | +import org.junit.Assert; |
22 | 23 | import org.junit.Before;
|
23 | 24 | import org.junit.Rule;
|
24 | 25 | import org.junit.Test;
|
@@ -196,4 +197,47 @@ public void testShouldNotParseTrailingGarbage() {
|
196 | 197 | jsonDecoder.process("{\"lit\":\"value\"}XXX");
|
197 | 198 | }
|
198 | 199 |
|
| 200 | + @Test |
| 201 | + public void testShouldNotParseComments() { |
| 202 | + exception.expect(MetafactureException.class); |
| 203 | + exception.expectMessage("Unexpected character ('/' (code 47))"); |
| 204 | + |
| 205 | + Assert.assertFalse(jsonDecoder.getAllowComments()); |
| 206 | + |
| 207 | + jsonDecoder.process("//{\"lit\":\"value\"}"); |
| 208 | + } |
| 209 | + |
| 210 | + @Test |
| 211 | + public void testShouldParseCommentsIfEnabled() { |
| 212 | + jsonDecoder.setAllowComments(true); |
| 213 | + Assert.assertTrue(jsonDecoder.getAllowComments()); |
| 214 | + |
| 215 | + jsonDecoder.process("//{\"lit\":\"value\"}"); |
| 216 | + |
| 217 | + verifyZeroInteractions(receiver); |
| 218 | + } |
| 219 | + |
| 220 | + @Test |
| 221 | + public void testShouldNotParseInlineComments() { |
| 222 | + exception.expect(MetafactureException.class); |
| 223 | + exception.expectMessage("Unexpected character ('/' (code 47))"); |
| 224 | + |
| 225 | + Assert.assertFalse(jsonDecoder.getAllowComments()); |
| 226 | + |
| 227 | + jsonDecoder.process("{\"lit\":/*comment*/\"value\"}"); |
| 228 | + } |
| 229 | + |
| 230 | + @Test |
| 231 | + public void testShouldParseInlineCommentsIfEnabled() { |
| 232 | + jsonDecoder.setAllowComments(true); |
| 233 | + Assert.assertTrue(jsonDecoder.getAllowComments()); |
| 234 | + |
| 235 | + jsonDecoder.process("{\"lit\":/*comment*/\"value\"}"); |
| 236 | + |
| 237 | + final InOrder ordered = inOrder(receiver); |
| 238 | + ordered.verify(receiver).startRecord("1"); |
| 239 | + ordered.verify(receiver).literal("lit", "value"); |
| 240 | + ordered.verify(receiver).endRecord(); |
| 241 | + } |
| 242 | + |
199 | 243 | }
|
0 commit comments