Skip to content

Commit

Permalink
Add a failing test for #216 (and #207)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 9, 2015
1 parent cfeaed0 commit 7ca3d1c
Showing 1 changed file with 44 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.fasterxml.jackson.core.sym;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.HashSet;

Expand All @@ -12,28 +13,39 @@ public class SymbolsViaParserTest
extends com.fasterxml.jackson.core.BaseTest
{
// for [jackson-core#213]
public void test17CharSymbols() throws Exception
{
public void test17CharSymbols() throws Exception {
_test17Chars(false);
}

// for [jackson-core#213]
public void test17ByteSymbols() throws Exception
{
public void test17ByteSymbols() throws Exception {
_test17Chars(true);
}

// for [jackson-core#216]
public void testSymbolTableExpansionChars() throws Exception {
_testSymbolTableExpansion(false);
}

// for [jackson-core#216]
public void testSymbolTableExpansionBytes() throws Exception {
_testSymbolTableExpansion(true);
}

/*
/**********************************************************
/* Secondary test methods
/**********************************************************
*/

private void _test17Chars(boolean useBytes) throws IOException
{
String doc = _createDoc();
String doc = _createDoc17();
JsonFactory f = new JsonFactory();

JsonParser p;
if (useBytes) {
p = f.createParser(doc.getBytes("UTF-8"));
} else {
p = f.createParser(doc);
}
JsonParser p = useBytes
? f.createParser(doc.getBytes("UTF-8"))
: f.createParser(doc);
HashSet<String> syms = new HashSet<String>();
assertToken(JsonToken.START_OBJECT, p.nextToken());
for (int i = 0; i < 50; ++i) {
Expand All @@ -46,7 +58,7 @@ private void _test17Chars(boolean useBytes) throws IOException
p.close();
}

private String _createDoc() {
private String _createDoc17() {
StringBuilder sb = new StringBuilder(1000);
sb.append("{\n");
for (int i = 1; i <= 50; ++i) {
Expand All @@ -60,4 +72,24 @@ private String _createDoc() {
sb.append("\n}");
return sb.toString();
}

public void _testSymbolTableExpansion(boolean useBytes) throws Exception
{
JsonFactory jsonFactory = new JsonFactory();
// Important: must create separate documents to gradually build up symbol table
for (int i = 0; i < 200; i++) {
String field = Integer.toString(i);
final String doc = "{ \"" + field + "\" : \"test\" }";
JsonParser parser = useBytes
? jsonFactory.createParser(doc.getBytes("UTF-8"))
: jsonFactory.createParser(doc);
assertToken(JsonToken.START_OBJECT, parser.nextToken());
assertToken(JsonToken.FIELD_NAME, parser.nextToken());
assertEquals(field, parser.getCurrentName());
assertToken(JsonToken.VALUE_STRING, parser.nextToken());
assertToken(JsonToken.END_OBJECT, parser.nextToken());
assertNull(parser.nextToken());
parser.close();
}
}
}

0 comments on commit 7ca3d1c

Please sign in to comment.