public void testComplexUnions()
{
// one of each unnamed type and two of named types
String partial = "[\"int\", \"long\", \"float\", \"double\", \"boolean\", \"bytes\"," +
" \"string\", {\"type\":\"array\", \"items\": \"long\"}," +
" {\"type\":\"map\", \"values\":\"long\"}";
String namedTypes = ", {\"type\":\"record\",\"name\":\"Foo\",\"fields\":[]}," +
" {\"type\":\"fixed\",\"name\":\"Bar\",\"size\": 1}," +
" {\"type\":\"enum\",\"name\":\"Baz\",\"symbols\": [\"X\"]}";
String namedTypes2 = ", {\"type\":\"record\",\"name\":\"Foo2\",\"fields\":[]}," +
" {\"type\":\"fixed\",\"name\":\"Bar2\",\"size\": 1}," +
" {\"type\":\"enum\",\"name\":\"Baz2\",\"symbols\": [\"X\"]}";
check(partial + namedTypes + "]", false);
check(partial + namedTypes + namedTypes2 + "]", false);
//checkParseError(partial + namedTypes + namedTypes + "]");
//TODO: Check this
// fail with two branches of the same unnamed type
checkUnionError(new Schema[] { new Schema(Schema.INT), new Schema(Schema.INT) });
checkUnionError(new Schema[] { new Schema(Schema.LONG), new Schema(Schema.LONG) });
checkUnionError(new Schema[] { new Schema(Schema.FLOAT), new Schema(Schema.FLOAT) });
checkUnionError(new Schema[] { new Schema(Schema.DOUBLE), new Schema(Schema.DOUBLE) });
checkUnionError(new Schema[] { new Schema(Schema.BOOLEAN), new Schema(Schema.BOOLEAN) });
checkUnionError(new Schema[] { new Schema(Schema.BYTES), new Schema(Schema.BYTES) });
checkUnionError(new Schema[] { new Schema(Schema.STRING), new Schema(Schema.STRING) });
checkUnionError(new Schema[] { new ArraySchema(new Schema(Schema.INT)), new ArraySchema(new Schema(Schema.INT)) });
checkUnionError(new Schema[] {new MapSchema(new Schema(Schema.INT)), new MapSchema(new Schema(Schema.INT))});
List<String> symbols = new List<String>();
symbols.Add("NOTHING");
// succeed with two branches of the same named type, if different names
// buildUnion(new Schema[] {Schema.createRecord("Foo", null, "org.test", false),
//Schema.createRecord("Foo2", null, "org.test", false)});
// buildUnion(new Schema[] {Schema.createEnum("Bar", null, "org.test", symbols),
//Schema.createEnum("Bar2", null, "org.test", symbols)});
// buildUnion(new Schema[] {Schema.createFixed("Baz", null, "org.test", 2),
//Schema.createFixed("Baz2", null, "org.test", 1)});
// // fail with two branches of the same named type, but same names
// checkUnionError(new Schema[] {Schema.createRecord("Foo", null, "org.test", false),
//Schema.createRecord("Foo", null, "org.test", false)});
// checkUnionError(new Schema[] {Schema.createEnum("Bar", null, "org.test", symbols),
//Schema.createEnum("Bar", null, "org.test", symbols)});
// checkUnionError(new Schema[] {Schema.createFixed("Baz", null, "org.test", 2),
//Schema.createFixed("Baz", null, "org.test", 1)});
Schema union = buildUnion(new Schema[] { new Schema(Schema.INT)});
// fail if creating a union of a union
checkUnionError(new Schema[] { union });
}