summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2016-04-21 16:26:52 -0700
committerJoshua Haberman <jhaberman@gmail.com>2016-04-21 16:26:52 -0700
commitac2689cec721eb94b49dfbfed310e2e0e3bdfa2b (patch)
tree1f6b0b65b2a8b49d281b23ed4a1ef066525e4556 /tests
parente6fa3f9d869765544b8e424e8573fe8d9af35534 (diff)
Put oneofs in the same table as fields. (#60)
* Put oneofs in the same table as fields. Oneofs and fields are not allowed to have names that conflict, so we might as well put them all in the same table. This also allows an efficient operation that looks for both fields and oneofs in a single lookup. Added support for OneofDef to Lua to allow testing of this. * Addressed PR comments.
Diffstat (limited to 'tests')
-rw-r--r--tests/bindings/lua/test_upb.lua24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/bindings/lua/test_upb.lua b/tests/bindings/lua/test_upb.lua
index f32a690..7c14b58 100644
--- a/tests/bindings/lua/test_upb.lua
+++ b/tests/bindings/lua/test_upb.lua
@@ -16,6 +16,18 @@ function iter_to_array(iter)
return arr
end
+function test_msgdef()
+ local f2 = upb.FieldDef{name = "field2", number = 1, type = upb.TYPE_INT32}
+ local o = upb.OneofDef{name = "field1", fields = {f2}}
+ local f = upb.FieldDef{name = "field3", number = 2, type = upb.TYPE_INT32}
+
+ local m = upb.MessageDef{fields = {o, f}}
+
+ assert_equal(f, m:lookup_name("field3"))
+ assert_equal(o, m:lookup_name("field1"))
+ assert_equal(f2, m:lookup_name("field2"))
+end
+
function test_fielddef()
local f = upb.FieldDef()
assert_false(f:is_frozen())
@@ -314,6 +326,18 @@ function test_msgdef_errors()
}
end)
+ assert_error(function()
+ -- Duplicate field name.
+ upb.MessageDef{
+ fields = {
+ upb.OneofDef{name = "field1", fields = {
+ upb.FieldDef{name = "field2", number = 1, type = upb.TYPE_INT32},
+ }},
+ upb.FieldDef{name = "field2", number = 2, type = upb.TYPE_INT32}
+ }
+ }
+ end)
+
-- attempt to set a name with embedded NULLs.
assert_error_match("names cannot have embedded NULLs", function()
md:set_full_name("abc\0def")
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback