support enum constants
This commit is contained in:
parent
db04e2da5e
commit
ad161e1569
3 changed files with 7 additions and 4 deletions
|
@ -331,7 +331,7 @@ private:
|
||||||
EnumSchema schema = schemaLoader.get(type.getEnum().getTypeId()).asEnum();
|
EnumSchema schema = schemaLoader.get(type.getEnum().getTypeId()).asEnum();
|
||||||
if (value.getEnum() < schema.getEnumerants().size()) {
|
if (value.getEnum() < schema.getEnumerants().size()) {
|
||||||
return kj::strTree(
|
return kj::strTree(
|
||||||
javaFullName(schema), "::",
|
javaFullName(schema), ".",
|
||||||
toUpperCase(schema.getEnumerants()[value.getEnum()].getProto().getName()));
|
toUpperCase(schema.getEnumerants()[value.getEnum()].getProto().getName()));
|
||||||
} else {
|
} else {
|
||||||
return kj::strTree("static_cast<", javaFullName(schema), ">(", value.getEnum(), ")");
|
return kj::strTree("static_cast<", javaFullName(schema), ">(", value.getEnum(), ")");
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
package org.capnproto;
|
package org.capnproto;
|
||||||
|
|
||||||
import org.capnproto.test.Test._;
|
import org.capnproto.test.Test._;
|
||||||
|
|
||||||
import org.scalatest.FunSuite
|
import org.scalatest.FunSuite
|
||||||
|
import org.scalatest.Matchers._;
|
||||||
|
|
||||||
class EncodingSuite extends FunSuite {
|
class EncodingSuite extends FunSuite {
|
||||||
|
|
||||||
|
@ -83,7 +82,10 @@ class EncodingSuite extends FunSuite {
|
||||||
assert(-6101065172474983726L == TestConstants.UINT64_CONST);
|
assert(-6101065172474983726L == TestConstants.UINT64_CONST);
|
||||||
|
|
||||||
assert(1234.5f == TestConstants.FLOAT32_CONST);
|
assert(1234.5f == TestConstants.FLOAT32_CONST);
|
||||||
assert(-123e45 == TestConstants.FLOAT64_CONST);
|
(-123e45) should equal (TestConstants.FLOAT64_CONST);
|
||||||
|
|
||||||
|
(TestConstants.ENUM_CONST) should equal (TestEnum.CORGE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test("GlobalConstants") {
|
test("GlobalConstants") {
|
||||||
|
|
|
@ -197,6 +197,7 @@ struct TestConstants {
|
||||||
const float32Const :Float32 = 1234.5;
|
const float32Const :Float32 = 1234.5;
|
||||||
const float64Const :Float64 = -123e45;
|
const float64Const :Float64 = -123e45;
|
||||||
# ...
|
# ...
|
||||||
|
const enumConst :TestEnum = corge;
|
||||||
}
|
}
|
||||||
|
|
||||||
const globalInt :UInt32 = 12345;
|
const globalInt :UInt32 = 12345;
|
Loading…
Reference in a new issue