Skip to content

Commit

Permalink
add test case for #59
Browse files Browse the repository at this point in the history
  • Loading branch information
dwrensha committed Dec 14, 2017
1 parent 906bab7 commit 5b0afb5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
23 changes: 23 additions & 0 deletions compiler/src/test/scala/org/capnproto/EncodingSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,29 @@ class EncodingSuite extends FunSuite {
root.getInt16Field() should equal (32767)
}

test("UpgradeStruct") {
val builder = new MessageBuilder()
val root = builder.initRoot(TestAnyPointer.factory)

{
val oldVersion = root.getAnyPointerField().initAs(TestOldVersion.factory)
oldVersion.setOld1(123)
oldVersion.setOld2("foo")
val sub = oldVersion.initOld3()
sub.setOld1(456)
sub.setOld2("bar")
}

{
val newVersion = root.getAnyPointerField().asReader().getAs(TestNewVersion.factory)
newVersion.getOld1() should equal (123)
newVersion.getOld2().toString() should equal ("foo")
newVersion.getNew2().toString() should equal ("baz")
newVersion.hasNew2() should equal (false)
newVersion.hasNew3() should equal (false)
}
}

test("UpgradeStructInBuilder") {
val builder = new MessageBuilder()
val root = builder.initRoot(TestAnyPointer.factory)
Expand Down
1 change: 1 addition & 0 deletions compiler/src/test/schema/test.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ struct TestNewVersion {
old3 @2 :TestNewVersion;
new1 @3 :Int64 = 987;
new2 @4 :Text = "baz";
new3 @5 :Data;
}

struct TestGenerics(Foo, Bar) {
Expand Down

0 comments on commit 5b0afb5

Please sign in to comment.