mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-22 20:08:51 +00:00
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:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user