BugFix: Optional enum when it is null (#6835)

* Test to make sure optional enum is written properly

* Handle optional enum codegen: when cast optional enum add `?`

* Run `tests/generate_code.sh` to generate code from schema

* Fix type casting in case of CreateXXXTypeVector

* Reason why vector's type is not optional
This commit is contained in:
Artavazd Balaian
2021-09-11 00:55:46 +08:00
committed by GitHub
parent 8fb8c2ce1d
commit 47d35f1053
3 changed files with 22 additions and 7 deletions

View File

@@ -1139,5 +1139,18 @@ namespace FlatBuffers.Test
Assert.AreEqual(keywordsInTable.Is, KeywordTest.ABC.@stackalloc);
Assert.AreEqual(keywordsInTable.Private, KeywordTest.@public.NONE);
}
[FlatBuffersTestMethod]
public void AddOptionalEnum_WhenPassNull_ShouldWorkProperly() {
var fbb = new FlatBufferBuilder(1);
ScalarStuff.StartScalarStuff(fbb);
ScalarStuff.AddMaybeEnum(fbb, null);
var offset = ScalarStuff.EndScalarStuff(fbb);
ScalarStuff.FinishScalarStuffBuffer(fbb, offset);
ScalarStuff scalarStuff = ScalarStuff.GetRootAsScalarStuff(fbb.DataBuffer);
Assert.AreEqual(null, scalarStuff.MaybeEnum);
}
}
}