diff options
author | Wouter van Oortmerssen <aardappel@gmail.com> | 2020-08-18 14:00:02 -0700 |
---|---|---|
committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2020-08-18 14:00:02 -0700 |
commit | 77f966f89fcf76fa67485adf941ac6e90d28029c (patch) | |
tree | 4f168bc6acfafa09c71e428b966b33021bbaa28e /tests/lobstertest.lobster | |
parent | e86d5b8e97c09d4eac46dbbb8541f180d05f1da2 (diff) | |
download | flatbuffers-77f966f89fcf76fa67485adf941ac6e90d28029c.tar.gz flatbuffers-77f966f89fcf76fa67485adf941ac6e90d28029c.tar.bz2 flatbuffers-77f966f89fcf76fa67485adf941ac6e90d28029c.zip |
[Lobster] optional scalars support
Diffstat (limited to 'tests/lobstertest.lobster')
-rw-r--r-- | tests/lobstertest.lobster | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/tests/lobstertest.lobster b/tests/lobstertest.lobster index 7ea9b388..ac42c2e8 100644 --- a/tests/lobstertest.lobster +++ b/tests/lobstertest.lobster @@ -14,6 +14,7 @@ import from "../lobster/" import monster_test_generated +import optional_scalars_generated def check_read_buffer(buf): // CheckReadBuffer checks that the given buffer is evaluated correctly as the example Monster. @@ -108,6 +109,28 @@ def make_monster_from_generated_code(): return b.SizedCopy() +def test_optional_scalars(): + def build(add_fields): + let b = flatbuffers_builder {} + let ss = optional_scalars_ScalarStuffBuilder { b }.start() + if add_fields: + ss.add_just_i8(1) + ss.add_maybe_i8(1) + ss.add_default_i8(1) + 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 + + 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 + + // Verify that the canonical flatbuffer file (produced by the C++ implementation) // is readable by the generated Lobster code. let fb2 = read_file("monsterdata_test.mon") @@ -134,4 +157,7 @@ assert not err2 // Check the resulting binary again (full roundtrip test): check_read_buffer(fb3) -print "Lobster test succesful!"
\ No newline at end of file +// Additional tests. +test_optional_scalars() + +print "Lobster test succesful!" |