mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-03 21:34:12 +00:00
Updated Lobster test for optional bools/enums
The codegen for this was already correct, just added more tests
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
|
||||
import from "../lobster/"
|
||||
import monster_test_generated
|
||||
import optional_scalars_generated
|
||||
import optional_scalars2_generated
|
||||
|
||||
def check_read_buffer(buf):
|
||||
// CheckReadBuffer checks that the given buffer is evaluated correctly as the example Monster.
|
||||
@@ -117,18 +117,53 @@ def test_optional_scalars():
|
||||
ss.add_just_i8(1)
|
||||
ss.add_maybe_i8(1)
|
||||
ss.add_default_i8(1)
|
||||
ss.add_just_f64(1.0)
|
||||
ss.add_maybe_f64(1.0)
|
||||
ss.add_default_f64(1.0)
|
||||
ss.add_just_bool(true)
|
||||
ss.add_maybe_bool(true)
|
||||
ss.add_default_bool(true)
|
||||
ss.add_just_enum(optional_scalars_OptionalByte_Two)
|
||||
ss.add_maybe_enum(optional_scalars_OptionalByte_Two)
|
||||
ss.add_default_enum(optional_scalars_OptionalByte_Two)
|
||||
b.Finish(ss.end())
|
||||
return optional_scalars_GetRootAsScalarStuff(b.SizedCopy())
|
||||
|
||||
var root = build(true)
|
||||
|
||||
assert root.just_i8() == 1 and root.default_i8() == 1
|
||||
var maybe_val, maybe_present = root.maybe_i8()
|
||||
assert maybe_val == 1 and maybe_present == true
|
||||
var maybe_val_i8, maybe_present_i8 = root.maybe_i8()
|
||||
assert maybe_val_i8 == 1 and maybe_present_i8 == true
|
||||
|
||||
assert root.just_f64() == 1.0 and root.default_f64() == 1.0
|
||||
var maybe_val_f64, maybe_present_f64 = root.maybe_f64()
|
||||
assert maybe_val_f64 == 1.0 and maybe_present_f64 == true
|
||||
|
||||
assert root.just_bool() == true and root.default_bool() == true
|
||||
var maybe_val_bool, maybe_present_bool = root.maybe_bool()
|
||||
assert maybe_val_bool == true and maybe_present_bool == true
|
||||
|
||||
assert root.just_enum() == optional_scalars_OptionalByte_Two and root.default_enum() == optional_scalars_OptionalByte_Two
|
||||
var maybe_val_enum, maybe_present_enum = root.maybe_enum()
|
||||
assert maybe_val_enum == optional_scalars_OptionalByte_Two and maybe_present_enum == true
|
||||
|
||||
root = build(false)
|
||||
|
||||
assert root.just_i8() == 0 and root.default_i8() == 42
|
||||
maybe_val, maybe_present = root.maybe_i8()
|
||||
assert maybe_val == 0 and maybe_present == false
|
||||
maybe_val_i8, maybe_present_i8 = root.maybe_i8()
|
||||
assert maybe_val_i8 == 0 and maybe_present_i8 == false
|
||||
|
||||
assert root.just_f64() == 0.0 and root.default_f64() == 42.0
|
||||
maybe_val_f64, maybe_present_f64 = root.maybe_f64()
|
||||
assert maybe_val_f64 == 0.0 and maybe_present_f64 == false
|
||||
|
||||
assert root.just_bool() == false and root.default_bool() == true
|
||||
maybe_val_bool, maybe_present_bool = root.maybe_bool()
|
||||
assert maybe_val_bool == false and maybe_present_bool == false
|
||||
|
||||
assert root.just_enum() == optional_scalars_OptionalByte_None and root.default_enum() == optional_scalars_OptionalByte_One
|
||||
maybe_val_enum, maybe_present_enum = root.maybe_enum()
|
||||
assert maybe_val_enum == optional_scalars_OptionalByte_None and maybe_present_enum == false
|
||||
|
||||
|
||||
// Verify that the canonical flatbuffer file (produced by the C++ implementation)
|
||||
|
||||
Reference in New Issue
Block a user