add Unions test

This commit is contained in:
David Renshaw 2016-12-16 14:50:43 -05:00
parent cb0fdba7b8
commit 2c43bd712f
2 changed files with 21 additions and 0 deletions

View file

@ -230,6 +230,17 @@ class EncodingSuite extends FunSuite {
TestUtil.checkSettedDefaultMessage(defaults.asReader())
}
test("Unions") {
val builder = new MessageBuilder()
val root = builder.initRoot(TestUnion.factory)
val u0 = root.initUnion0()
u0.initU0f1sp(10)
assert(u0.which() == TestUnion.Union0.Which.U0F1SP)
u0.initPrimitiveList(10)
assert(u0.which() == TestUnion.Union0.Which.PRIMITIVE_LIST)
}
test("Groups") {
val builder = new MessageBuilder()
val root = builder.initRoot(TestGroups.factory)

View file

@ -180,6 +180,8 @@ struct TestUnion {
u0f1s32 @15: Int32;
u0f1s64 @16: Int64;
u0f1sp @17: Text;
primitiveList @56: List(UInt32);
}
# Pack one bit in order to make pathological situation for union1.
@ -393,6 +395,14 @@ struct GenericMap(K, V)
c @3 :List(List(List(Entry)));
}
# TODO. this is currently broken
#struct TestGenericUnion(T) {
# union0: union {
# nothing @0 :Void;
# something @1 :T;
# }
#}
struct TestEmptyStruct {}
struct TestConstants {