diff options
author | Joshua Haberman <jhaberman@gmail.com> | 2018-08-21 14:18:53 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-21 14:18:53 -0700 |
commit | e3eae33fb5840dbec3c2bc9109fa164f6066baa8 (patch) | |
tree | 34690021d5688e2b9cd75982a0d1de2451f042d2 /tests/bindings/lua/test_upb.pb.lua | |
parent | b0a6602fc8fddf71ac959d43b4cd82707e6235b9 (diff) | |
parent | 636b25be8d2744bc5fe41b44d36580460aa7b611 (diff) |
Merge pull request #114 from haberman/arenaonly
Enforced that upb_msg lives in an Arena only, and other simplifying.
Diffstat (limited to 'tests/bindings/lua/test_upb.pb.lua')
-rw-r--r-- | tests/bindings/lua/test_upb.pb.lua | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/tests/bindings/lua/test_upb.pb.lua b/tests/bindings/lua/test_upb.pb.lua index 106dc55..752a736 100644 --- a/tests/bindings/lua/test_upb.pb.lua +++ b/tests/bindings/lua/test_upb.pb.lua @@ -27,25 +27,13 @@ local symtab = upb.SymbolTable{ local factory = upb.MessageFactory(symtab); local TestMessage = factory:get_message_class("TestMessage") -function test_decodermethod() - local decoder = pb.MakeStringToMessageDecoder(TestMessage) - - assert_error( - function() - -- Needs at least one argument to construct. - pb.MakeStringToMessageDecoder() - end) -end - function test_parse_primitive() local binary_pb = "\008\128\128\128\128\002\016\128\128\128\128\004\024\128\128" .. "\128\128\128\128\128\002\032\128\128\128\128\128\128\128\001\041\000" .. "\000\000\000\000\000\248\063\053\000\000\096\064\056\001" - local decoder = pb.MakeStringToMessageDecoder(TestMessage) - local encoder = pb.MakeMessageToStringEncoder(TestMessage) - collectgarbage() -- ensure encoder/decoder GC-anchor what they need. - local msg = decoder(binary_pb) + local msg = TestMessage() + pb.decode(msg, binary_pb) assert_equal(536870912, msg.i32) assert_equal(1073741824, msg.u32) assert_equal(1125899906842624, msg.i64) @@ -54,8 +42,9 @@ function test_parse_primitive() assert_equal(3.5, msg.flt) assert_equal(true, msg.bool) - local encoded = encoder(msg) - local msg2 = decoder(encoded) + local encoded = pb.encode(msg) + local msg2 = TestMessage() + pb.decode(msg2, encoded) assert_equal(536870912, msg.i32) assert_equal(1073741824, msg.u32) assert_equal(1125899906842624, msg.i64) @@ -77,8 +66,8 @@ function test_parse_string() local TestMessage = factory:get_message_class("TestMessage") local binary_pb = "\010\005Hello" - local decoder = pb.MakeStringToMessageDecoder(TestMessage) - msg = decoder(binary_pb) + msg = TestMessage() + pb.decode(msg, binary_pb) assert_equal("Hello", msg.str) end |