dub 0.2.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of dub might be problematic. Click here for more details.
- data/History.txt +92 -0
- data/LICENSE +20 -0
- data/README.rdoc +115 -0
- data/Rakefile +59 -0
- data/dub.gemspec +197 -0
- data/lib/dub/argument.rb +286 -0
- data/lib/dub/entities_unescape.rb +9 -0
- data/lib/dub/function.rb +177 -0
- data/lib/dub/function_group.rb +72 -0
- data/lib/dub/generator.rb +15 -0
- data/lib/dub/group.rb +20 -0
- data/lib/dub/klass.rb +338 -0
- data/lib/dub/lua/class.cpp.erb +114 -0
- data/lib/dub/lua/class_gen.rb +96 -0
- data/lib/dub/lua/function.cpp.erb +15 -0
- data/lib/dub/lua/function_gen.rb +329 -0
- data/lib/dub/lua/group.cpp.erb +9 -0
- data/lib/dub/lua/lua_cpp_helper.cpp +259 -0
- data/lib/dub/lua/lua_cpp_helper.h +219 -0
- data/lib/dub/lua/lua_object.cpp +158 -0
- data/lib/dub/lua/lua_object.h +69 -0
- data/lib/dub/lua/namespace.cpp.erb +42 -0
- data/lib/dub/lua/namespace_gen.rb +69 -0
- data/lib/dub/lua.rb +24 -0
- data/lib/dub/member_extraction.rb +128 -0
- data/lib/dub/namespace.rb +295 -0
- data/lib/dub/opts_parser.rb +30 -0
- data/lib/dub/parser.rb +46 -0
- data/lib/dub/templates/lua_template.erb +21 -0
- data/lib/dub/version.rb +3 -0
- data/lib/dub.rb +24 -20
- data/test/argument_test.rb +581 -0
- data/test/fixtures/app/CMakeLists.txt +54 -0
- data/test/fixtures/app/Doxyfile +1600 -0
- data/test/fixtures/app/bindings/all_lua.cpp +299 -0
- data/test/fixtures/app/include/matrix.h +283 -0
- data/test/fixtures/app/make_lua_bindings.rb +13 -0
- data/test/fixtures/app/vendor/lua/CMakeLists.txt +25 -0
- data/test/fixtures/app/vendor/lua/COPYRIGHT +34 -0
- data/test/fixtures/app/vendor/lua/HISTORY +183 -0
- data/test/fixtures/app/vendor/lua/INSTALL +99 -0
- data/test/fixtures/app/vendor/lua/Makefile +183 -0
- data/test/fixtures/app/vendor/lua/README +37 -0
- data/test/fixtures/app/vendor/lua/lapi.c +1080 -0
- data/test/fixtures/app/vendor/lua/lapi.h +16 -0
- data/test/fixtures/app/vendor/lua/lauxlib.c +653 -0
- data/test/fixtures/app/vendor/lua/lauxlib.h +174 -0
- data/test/fixtures/app/vendor/lua/lbaselib.c +643 -0
- data/test/fixtures/app/vendor/lua/lcode.c +839 -0
- data/test/fixtures/app/vendor/lua/lcode.h +76 -0
- data/test/fixtures/app/vendor/lua/ldblib.c +397 -0
- data/test/fixtures/app/vendor/lua/ldebug.c +622 -0
- data/test/fixtures/app/vendor/lua/ldebug.h +33 -0
- data/test/fixtures/app/vendor/lua/ldo.c +516 -0
- data/test/fixtures/app/vendor/lua/ldo.h +57 -0
- data/test/fixtures/app/vendor/lua/ldump.c +164 -0
- data/test/fixtures/app/vendor/lua/lfunc.c +174 -0
- data/test/fixtures/app/vendor/lua/lfunc.h +34 -0
- data/test/fixtures/app/vendor/lua/lgc.c +711 -0
- data/test/fixtures/app/vendor/lua/lgc.h +110 -0
- data/test/fixtures/app/vendor/lua/liblua.a +0 -0
- data/test/fixtures/app/vendor/lua/linit.c +38 -0
- data/test/fixtures/app/vendor/lua/liolib.c +532 -0
- data/test/fixtures/app/vendor/lua/llex.c +461 -0
- data/test/fixtures/app/vendor/lua/llex.h +81 -0
- data/test/fixtures/app/vendor/lua/llimits.h +128 -0
- data/test/fixtures/app/vendor/lua/lmathlib.c +263 -0
- data/test/fixtures/app/vendor/lua/lmem.c +86 -0
- data/test/fixtures/app/vendor/lua/lmem.h +49 -0
- data/test/fixtures/app/vendor/lua/loadlib.c +664 -0
- data/test/fixtures/app/vendor/lua/lobject.c +214 -0
- data/test/fixtures/app/vendor/lua/lobject.h +381 -0
- data/test/fixtures/app/vendor/lua/lopcodes.c +102 -0
- data/test/fixtures/app/vendor/lua/lopcodes.h +268 -0
- data/test/fixtures/app/vendor/lua/loslib.c +244 -0
- data/test/fixtures/app/vendor/lua/lparser.c +1337 -0
- data/test/fixtures/app/vendor/lua/lparser.h +82 -0
- data/test/fixtures/app/vendor/lua/lstate.c +214 -0
- data/test/fixtures/app/vendor/lua/lstate.h +168 -0
- data/test/fixtures/app/vendor/lua/lstring.c +111 -0
- data/test/fixtures/app/vendor/lua/lstring.h +31 -0
- data/test/fixtures/app/vendor/lua/lstrlib.c +868 -0
- data/test/fixtures/app/vendor/lua/ltable.c +588 -0
- data/test/fixtures/app/vendor/lua/ltable.h +40 -0
- data/test/fixtures/app/vendor/lua/ltablib.c +278 -0
- data/test/fixtures/app/vendor/lua/ltm.c +75 -0
- data/test/fixtures/app/vendor/lua/ltm.h +54 -0
- data/test/fixtures/app/vendor/lua/lua.c +695 -0
- data/test/fixtures/app/vendor/lua/lua.h +385 -0
- data/test/fixtures/app/vendor/lua/lua_dub_helper.h +77 -0
- data/test/fixtures/app/vendor/lua/luac +0 -0
- data/test/fixtures/app/vendor/lua/luac.c +200 -0
- data/test/fixtures/app/vendor/lua/luaconf.h +762 -0
- data/test/fixtures/app/vendor/lua/lualib.h +53 -0
- data/test/fixtures/app/vendor/lua/lundump.c +223 -0
- data/test/fixtures/app/vendor/lua/lundump.h +36 -0
- data/test/fixtures/app/vendor/lua/lvm.c +765 -0
- data/test/fixtures/app/vendor/lua/lvm.h +36 -0
- data/test/fixtures/app/vendor/lua/lzio.c +82 -0
- data/test/fixtures/app/vendor/lua/lzio.h +67 -0
- data/test/fixtures/app/vendor/lua/matrix.h +102 -0
- data/test/fixtures/app/vendor/lua/print.c +227 -0
- data/test/fixtures/app/vendor/lua/test/README +26 -0
- data/test/fixtures/app/vendor/lua/test/bisect.lua +27 -0
- data/test/fixtures/app/vendor/lua/test/cf.lua +16 -0
- data/test/fixtures/app/vendor/lua/test/echo.lua +5 -0
- data/test/fixtures/app/vendor/lua/test/env.lua +7 -0
- data/test/fixtures/app/vendor/lua/test/factorial.lua +32 -0
- data/test/fixtures/app/vendor/lua/test/fib.lua +40 -0
- data/test/fixtures/app/vendor/lua/test/fibfor.lua +13 -0
- data/test/fixtures/app/vendor/lua/test/globals.lua +13 -0
- data/test/fixtures/app/vendor/lua/test/hello.lua +3 -0
- data/test/fixtures/app/vendor/lua/test/life.lua +111 -0
- data/test/fixtures/app/vendor/lua/test/luac.lua +7 -0
- data/test/fixtures/app/vendor/lua/test/printf.lua +7 -0
- data/test/fixtures/app/vendor/lua/test/readonly.lua +12 -0
- data/test/fixtures/app/vendor/lua/test/sieve.lua +29 -0
- data/test/fixtures/app/vendor/lua/test/sort.lua +66 -0
- data/test/fixtures/app/vendor/lua/test/table.lua +12 -0
- data/test/fixtures/app/vendor/lua/test/trace-calls.lua +32 -0
- data/test/fixtures/app/vendor/lua/test/trace-globals.lua +38 -0
- data/test/fixtures/app/vendor/lua/test/xd.lua +14 -0
- data/test/fixtures/app/xml/classdub_1_1_base.xml +85 -0
- data/test/fixtures/app/xml/classdub_1_1_custom_destructor.xml +67 -0
- data/test/fixtures/app/xml/classdub_1_1_deletable_out_of_lua.xml +43 -0
- data/test/fixtures/app/xml/classdub_1_1_matrix.xml +482 -0
- data/test/fixtures/app/xml/classdub_1_1_no_destructor.xml +49 -0
- data/test/fixtures/app/xml/classdub_1_1_priv_sub_base.xml +89 -0
- data/test/fixtures/app/xml/classdub_1_1_private_constr.xml +68 -0
- data/test/fixtures/app/xml/classdub_1_1_static_constr.xml +69 -0
- data/test/fixtures/app/xml/classdub_1_1_sub_base.xml +89 -0
- data/test/fixtures/app/xml/classdub_1_1_t_mat.xml +252 -0
- data/test/fixtures/app/xml/combine.xslt +15 -0
- data/test/fixtures/app/xml/compound.xsd +814 -0
- data/test/fixtures/app/xml/dir_53661a2bdeb1d55e60581a7e15deb763.xml +12 -0
- data/test/fixtures/app/xml/index.xml +91 -0
- data/test/fixtures/app/xml/index.xsd +66 -0
- data/test/fixtures/app/xml/matrix_8h.xml +310 -0
- data/test/fixtures/app/xml/namespacedub.xml +48 -0
- data/test/fixtures/classcv_1_1_mat.xml +1996 -0
- data/test/fixtures/classcv_1_1_point__.xml +341 -0
- data/test/fixtures/classcv_1_1_scalar__.xml +269 -0
- data/test/fixtures/classcv_1_1_size__.xml +270 -0
- data/test/fixtures/dummy_class.cpp.erb +1 -0
- data/test/fixtures/dummy_function.cpp.erb +1 -0
- data/test/fixtures/group___magic_type.xml +406 -0
- data/test/fixtures/namespacecv.xml +12659 -0
- data/test/function_group_test.rb +43 -0
- data/test/function_test.rb +405 -0
- data/test/group_test.rb +241 -0
- data/test/helper.rb +34 -0
- data/test/klass_test.rb +551 -0
- data/test/lua_function_gen_test.rb +242 -0
- data/test/namespace_test.rb +220 -0
- data/test/parser_test.rb +36 -0
- metadata +229 -272
- checksums.yaml +0 -7
- data/lib/open_api_sdk/analytics.rb +0 -99
- data/lib/open_api_sdk/domains.rb +0 -353
- data/lib/open_api_sdk/dub.rb +0 -88
- data/lib/open_api_sdk/links.rb +0 -766
- data/lib/open_api_sdk/metatags.rb +0 -54
- data/lib/open_api_sdk/models/operations/bulkcreatelinks_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/bulkupdatelinks_requestbody.rb +0 -27
- data/lib/open_api_sdk/models/operations/bulkupdatelinks_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/color.rb +0 -24
- data/lib/open_api_sdk/models/operations/createdomain_requestbody.rb +0 -33
- data/lib/open_api_sdk/models/operations/createdomain_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/createlink_requestbody.rb +0 -95
- data/lib/open_api_sdk/models/operations/createlink_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/createtag_requestbody.rb +0 -32
- data/lib/open_api_sdk/models/operations/createtag_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/data.rb +0 -83
- data/lib/open_api_sdk/models/operations/deletedomain_request.rb +0 -24
- data/lib/open_api_sdk/models/operations/deletedomain_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/deletedomain_responsebody.rb +0 -24
- data/lib/open_api_sdk/models/operations/deletelink_request.rb +0 -24
- data/lib/open_api_sdk/models/operations/deletelink_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/deletelink_responsebody.rb +0 -24
- data/lib/open_api_sdk/models/operations/event.rb +0 -21
- data/lib/open_api_sdk/models/operations/getlinkinfo_request.rb +0 -33
- data/lib/open_api_sdk/models/operations/getlinkinfo_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/getlinks_request.rb +0 -51
- data/lib/open_api_sdk/models/operations/getlinks_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/getlinkscount_request.rb +0 -48
- data/lib/open_api_sdk/models/operations/getlinkscount_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/getmetatags_request.rb +0 -24
- data/lib/open_api_sdk/models/operations/getmetatags_response.rb +0 -33
- data/lib/open_api_sdk/models/operations/getmetatags_responsebody.rb +0 -30
- data/lib/open_api_sdk/models/operations/getqrcode_request.rb +0 -39
- data/lib/open_api_sdk/models/operations/getqrcode_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/gettags_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/getworkspace_request.rb +0 -24
- data/lib/open_api_sdk/models/operations/getworkspace_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/groupby.rb +0 -28
- data/lib/open_api_sdk/models/operations/interval.rb +0 -25
- data/lib/open_api_sdk/models/operations/level.rb +0 -21
- data/lib/open_api_sdk/models/operations/listdomains_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/paymentprocessor.rb +0 -20
- data/lib/open_api_sdk/models/operations/requestbody.rb +0 -95
- data/lib/open_api_sdk/models/operations/retrieveanalytics_request.rb +0 -81
- data/lib/open_api_sdk/models/operations/retrieveanalytics_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/sort.rb +0 -20
- data/lib/open_api_sdk/models/operations/trackcustomer_requestbody.rb +0 -33
- data/lib/open_api_sdk/models/operations/trackcustomer_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/trackcustomer_responsebody.rb +0 -33
- data/lib/open_api_sdk/models/operations/tracklead_requestbody.rb +0 -42
- data/lib/open_api_sdk/models/operations/tracklead_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/tracklead_responsebody.rb +0 -42
- data/lib/open_api_sdk/models/operations/tracksale_requestbody.rb +0 -42
- data/lib/open_api_sdk/models/operations/tracksale_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/tracksale_responsebody.rb +0 -42
- data/lib/open_api_sdk/models/operations/updatedomain_request.rb +0 -27
- data/lib/open_api_sdk/models/operations/updatedomain_requestbody.rb +0 -33
- data/lib/open_api_sdk/models/operations/updatedomain_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/updatelink_request.rb +0 -27
- data/lib/open_api_sdk/models/operations/updatelink_requestbody.rb +0 -95
- data/lib/open_api_sdk/models/operations/updatelink_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/updatetag_color.rb +0 -24
- data/lib/open_api_sdk/models/operations/updatetag_request.rb +0 -27
- data/lib/open_api_sdk/models/operations/updatetag_requestbody.rb +0 -32
- data/lib/open_api_sdk/models/operations/updatetag_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/updateworkspace_request.rb +0 -27
- data/lib/open_api_sdk/models/operations/updateworkspace_requestbody.rb +0 -27
- data/lib/open_api_sdk/models/operations/updateworkspace_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/upsertlink_requestbody.rb +0 -95
- data/lib/open_api_sdk/models/operations/upsertlink_response.rb +0 -60
- data/lib/open_api_sdk/models/operations.rb +0 -74
- data/lib/open_api_sdk/models/shared/badrequest.rb +0 -24
- data/lib/open_api_sdk/models/shared/code.rb +0 -18
- data/lib/open_api_sdk/models/shared/color.rb +0 -24
- data/lib/open_api_sdk/models/shared/conflict.rb +0 -24
- data/lib/open_api_sdk/models/shared/conflict_code.rb +0 -18
- data/lib/open_api_sdk/models/shared/conflict_error.rb +0 -30
- data/lib/open_api_sdk/models/shared/countrycode.rb +0 -267
- data/lib/open_api_sdk/models/shared/domains.rb +0 -27
- data/lib/open_api_sdk/models/shared/domainschema.rb +0 -48
- data/lib/open_api_sdk/models/shared/error.rb +0 -30
- data/lib/open_api_sdk/models/shared/forbidden.rb +0 -24
- data/lib/open_api_sdk/models/shared/forbidden_code.rb +0 -18
- data/lib/open_api_sdk/models/shared/forbidden_error.rb +0 -30
- data/lib/open_api_sdk/models/shared/geo.rb +0 -771
- data/lib/open_api_sdk/models/shared/internalservererror.rb +0 -24
- data/lib/open_api_sdk/models/shared/internalservererror_code.rb +0 -18
- data/lib/open_api_sdk/models/shared/internalservererror_error.rb +0 -30
- data/lib/open_api_sdk/models/shared/inviteexpired.rb +0 -24
- data/lib/open_api_sdk/models/shared/inviteexpired_code.rb +0 -18
- data/lib/open_api_sdk/models/shared/inviteexpired_error.rb +0 -30
- data/lib/open_api_sdk/models/shared/linkgeotargeting.rb +0 -771
- data/lib/open_api_sdk/models/shared/linkschema.rb +0 -142
- data/lib/open_api_sdk/models/shared/notfound.rb +0 -24
- data/lib/open_api_sdk/models/shared/notfound_code.rb +0 -18
- data/lib/open_api_sdk/models/shared/notfound_error.rb +0 -30
- data/lib/open_api_sdk/models/shared/plan.rb +0 -24
- data/lib/open_api_sdk/models/shared/ratelimitexceeded.rb +0 -24
- data/lib/open_api_sdk/models/shared/ratelimitexceeded_code.rb +0 -18
- data/lib/open_api_sdk/models/shared/ratelimitexceeded_error.rb +0 -30
- data/lib/open_api_sdk/models/shared/role.rb +0 -19
- data/lib/open_api_sdk/models/shared/security.rb +0 -24
- data/lib/open_api_sdk/models/shared/tagschema.rb +0 -30
- data/lib/open_api_sdk/models/shared/unauthorized.rb +0 -24
- data/lib/open_api_sdk/models/shared/unauthorized_code.rb +0 -18
- data/lib/open_api_sdk/models/shared/unauthorized_error.rb +0 -30
- data/lib/open_api_sdk/models/shared/unprocessableentity.rb +0 -24
- data/lib/open_api_sdk/models/shared/unprocessableentity_code.rb +0 -18
- data/lib/open_api_sdk/models/shared/unprocessableentity_error.rb +0 -30
- data/lib/open_api_sdk/models/shared/users.rb +0 -24
- data/lib/open_api_sdk/models/shared/workspaceschema.rb +0 -81
- data/lib/open_api_sdk/models/shared.rb +0 -49
- data/lib/open_api_sdk/qr_codes.rb +0 -97
- data/lib/open_api_sdk/sdkconfiguration.rb +0 -52
- data/lib/open_api_sdk/tags.rb +0 -272
- data/lib/open_api_sdk/track.rb +0 -276
- data/lib/open_api_sdk/utils/metadata_fields.rb +0 -150
- data/lib/open_api_sdk/utils/t.rb +0 -59
- data/lib/open_api_sdk/utils/utils.rb +0 -772
- data/lib/open_api_sdk/workspaces.rb +0 -192
@@ -0,0 +1,242 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'dub/lua'
|
3
|
+
|
4
|
+
class LuaFunctionGenTest < Test::Unit::TestCase
|
5
|
+
context 'A Lua generator' do
|
6
|
+
setup do
|
7
|
+
@generator = Dub::Lua
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'with a function' do
|
11
|
+
setup do
|
12
|
+
# namespacecv_xml = Dub.parse(fixture('namespacecv.xml'))
|
13
|
+
@function = namespacecv_xml[:cv][:resize]
|
14
|
+
end
|
15
|
+
|
16
|
+
should 'return Function on bind' do
|
17
|
+
assert_kind_of Dub::Function, @generator.bind(@function)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'A Function' do
|
23
|
+
setup do
|
24
|
+
@function = namespacecv_xml[:cv][:resize]
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'bound to a Lua generator' do
|
28
|
+
setup do
|
29
|
+
Dub::Lua.bind(@function)
|
30
|
+
@generator = Dub::Lua.function_generator
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
should 'return string on to_s' do
|
35
|
+
assert_kind_of String, @function.to_s
|
36
|
+
end
|
37
|
+
|
38
|
+
should 'generate a static function returning an int' do
|
39
|
+
assert_match %r{static int cv_resize}, @function.to_s
|
40
|
+
end
|
41
|
+
|
42
|
+
should 'insert code to check for an arguments on get_arg' do
|
43
|
+
assert_match /Mat.*\*\s*src\s*=\s*\*\(\(const\s+Mat\s+\*\*\)\s*luaL_checkudata\s*\(L,\s*1,\s*\"cv\.Mat\"\s*\)\)\s*;/,
|
44
|
+
@generator.get_arg(@function.arguments.first, 1) # 1 = first argument in Lua stack
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'with default values' do
|
48
|
+
should 'verify stack size' do
|
49
|
+
assert_match /top__\s*<\s*6/, @generator.function(@function)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'in a class with a class as parameter' do
|
54
|
+
setup do
|
55
|
+
@function = namespacecv_xml[:cv][:Mat][:locateROI]
|
56
|
+
end
|
57
|
+
|
58
|
+
should 'use parameter class identifier' do
|
59
|
+
assert_match /Size\s*\*\*\)luaL_checkudata\s*\(L,\s*1,\s*\"cv\.Size\"\s*\)\)\s*;/,
|
60
|
+
@generator.get_arg(@function.arguments.first, 1) # 1 = first argument in Lua stack
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'using a custom template' do
|
65
|
+
setup do
|
66
|
+
@generator.template_path = fixture('dummy_function.cpp.erb')
|
67
|
+
end
|
68
|
+
|
69
|
+
teardown do
|
70
|
+
@generator.template_path = nil
|
71
|
+
end
|
72
|
+
|
73
|
+
should 'use custom template to render function' do
|
74
|
+
assert_equal 'DUMMY: resize', @generator.function(@function)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'using a custom type' do
|
79
|
+
setup do
|
80
|
+
@generator.custom_type(/lua_State /) do |type_def, arg, stack_pos|
|
81
|
+
if type_def =~ /lua_State\s*\*\s*L/
|
82
|
+
""
|
83
|
+
else
|
84
|
+
"#{type_def} = L;"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
should 'use custom block to get arg type' do
|
90
|
+
method = @generator.function(namespacedub_xml[:dub][:Matrix][:lua_thing])
|
91
|
+
assert_match %r{int a = luaL_checkint\(L, 2\)}, method
|
92
|
+
assert_no_match %r{L\s*=}, method
|
93
|
+
assert_match %r{int b = luaL_checkint\(L, 4\)}, method
|
94
|
+
assert_match %r{lua_thing\(a, L, b\)}, method
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'using LuaStackSize return value' do
|
99
|
+
should 'return call result as stack size' do
|
100
|
+
method = @generator.function(namespacedub_xml[:dub][:Matrix][:work_with_lua])
|
101
|
+
assert_match %r{return retval__}, method
|
102
|
+
assert_no_match %r{lua_pushclass}, method
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'using const char * return value' do
|
107
|
+
should 'pushstring' do
|
108
|
+
method = @generator.function(namespacedub_xml[:dub][:Matrix][:name])
|
109
|
+
assert_match %r{lua_pushstring\(L, retval__\);}, method
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'using bool return value' do
|
114
|
+
should 'pushbool' do
|
115
|
+
method = @generator.function(namespacedub_xml[:dub][:Matrix][:true])
|
116
|
+
assert_match %r{lua_pushboolean\(L, retval__\);}, method
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context 'A group of overloaded functions' do
|
123
|
+
setup do
|
124
|
+
# namespacecv_xml = Dub.parse(fixture('namespacecv.xml'))
|
125
|
+
@function_group = namespacecv_xml[:cv][:divide]
|
126
|
+
end
|
127
|
+
|
128
|
+
context 'bound to a Lua generator' do
|
129
|
+
setup do
|
130
|
+
Dub::Lua.bind(@function_group)
|
131
|
+
end
|
132
|
+
|
133
|
+
should 'return string content on to_s' do
|
134
|
+
assert_kind_of String, @function_group.to_s
|
135
|
+
end
|
136
|
+
|
137
|
+
should 'generate a static function returning an int' do
|
138
|
+
assert_match %r{static int cv_divide}, @function_group.to_s
|
139
|
+
end
|
140
|
+
|
141
|
+
should 'generate a static function returning an int for each overloaded function' do
|
142
|
+
bindings = @function_group.to_s
|
143
|
+
assert_match %r{static int cv_divide1}, bindings
|
144
|
+
assert_match %r{static int cv_divide2}, bindings
|
145
|
+
assert_match %r{static int cv_divide3}, bindings
|
146
|
+
assert_match %r{static int cv_divide4}, bindings
|
147
|
+
end
|
148
|
+
|
149
|
+
# should 'declare chooser' do
|
150
|
+
# assert_match %r{"divide",\s*cv_divide\}}, @group.to_s
|
151
|
+
# end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'A function with a custom class return value' do
|
156
|
+
setup do
|
157
|
+
# namespacecv_xml = Dub.parse(fixture('namespacecv.xml'))
|
158
|
+
@function = namespacecv_xml[:cv][:getRotationMatrix2D]
|
159
|
+
end
|
160
|
+
|
161
|
+
context 'bound to a Lua generator' do
|
162
|
+
setup do
|
163
|
+
Dub::Lua.bind(@function)
|
164
|
+
end
|
165
|
+
|
166
|
+
should 'call template push method' do
|
167
|
+
assert_match %r{lua_pushclass<Mat>\(\s*L\s*,\s*retval__\s*,\s*"cv.Mat"\s*\)}, @function.to_s
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
context 'A function with pointer parameters' do
|
173
|
+
setup do
|
174
|
+
# namespacecv_xml = Dub.parse(fixture('namespacecv.xml'))
|
175
|
+
@function = namespacecv_xml[:cv][:calcHist][0]
|
176
|
+
end
|
177
|
+
|
178
|
+
context 'bound to a Lua generator' do
|
179
|
+
setup do
|
180
|
+
Dub::Lua.bind(@function)
|
181
|
+
end
|
182
|
+
|
183
|
+
should 'use a DubArgPointer with the given type' do
|
184
|
+
assert_match %r{DubArgPointer<int>}, @function.to_s
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
context 'A member function bound to a Lua generator' do
|
190
|
+
subject do
|
191
|
+
member = namespacedub_xml[:dub][:Matrix][:rows]
|
192
|
+
Dub::Lua.bind(member)
|
193
|
+
member.to_s
|
194
|
+
end
|
195
|
+
|
196
|
+
should 'start by getting self' do
|
197
|
+
assert_match %r{self__\s*=\s*\*\(\(Matrix\*\*\)luaL_checkudata}, subject
|
198
|
+
end
|
199
|
+
|
200
|
+
should 'assert that self is not nil' do
|
201
|
+
assert_match %r{self__\s*=\s*\*\(\(Matrix\*\*\)luaL_checkudata}, subject
|
202
|
+
end
|
203
|
+
|
204
|
+
should 'prefix call with self' do
|
205
|
+
assert_match %r{self__->rows\(}, subject
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
context 'A constructor bound to a Lua generator' do
|
210
|
+
setup do
|
211
|
+
@constructor = namespacedub_xml[:dub][:Matrix][:Matrix].first
|
212
|
+
Dub::Lua.bind(@constructor)
|
213
|
+
end
|
214
|
+
|
215
|
+
should 'use pushclass in constructor' do
|
216
|
+
result = @constructor.to_s
|
217
|
+
assert_match %r{lua_pushclass<Matrix>\s*\(L, retval__, \"dub.Matrix\"\s*\)}, result
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
context 'A function without return value' do
|
222
|
+
setup do
|
223
|
+
@function = namespacecv_xml[:cv][:blur]
|
224
|
+
end
|
225
|
+
|
226
|
+
context 'bound to a Lua generator' do
|
227
|
+
setup do
|
228
|
+
Dub::Lua.bind(@function)
|
229
|
+
end
|
230
|
+
|
231
|
+
should 'return 0' do
|
232
|
+
assert_match %r{return\s+0}, @function.to_s
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
|
238
|
+
end
|
239
|
+
|
240
|
+
|
241
|
+
|
242
|
+
|
@@ -0,0 +1,220 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'dub/lua'
|
3
|
+
|
4
|
+
class NamespaceTest < Test::Unit::TestCase
|
5
|
+
context 'A Namespace' do
|
6
|
+
setup do
|
7
|
+
# namespacecv_xml = Dub.parse(fixture('namespacecv.xml'))
|
8
|
+
@namespace = namespacecv_xml[:cv]
|
9
|
+
end
|
10
|
+
|
11
|
+
should 'find a function with functions method' do
|
12
|
+
assert_kind_of Dub::Function, @namespace.function(:resize)
|
13
|
+
end
|
14
|
+
|
15
|
+
should 'find a function with array index' do
|
16
|
+
assert_kind_of Dub::Function, @namespace[:resize]
|
17
|
+
end
|
18
|
+
|
19
|
+
should 'respond to name' do
|
20
|
+
assert_equal 'cv', @namespace.name
|
21
|
+
end
|
22
|
+
|
23
|
+
should 'respond to lib_name' do
|
24
|
+
# nested namespace could be cv_more
|
25
|
+
assert_equal 'cv', @namespace.lib_name
|
26
|
+
end
|
27
|
+
|
28
|
+
should 'respond to id_name' do
|
29
|
+
# nested namespace could be cv.more
|
30
|
+
assert_equal 'cv', @namespace.id_name
|
31
|
+
end
|
32
|
+
|
33
|
+
should 'return header name on header' do
|
34
|
+
assert_equal 'cv.hpp', @namespace.header
|
35
|
+
end
|
36
|
+
|
37
|
+
should 'return defined header if changed' do
|
38
|
+
namespace = Dub.parse(fixture('namespacecv.xml'))[:cv]
|
39
|
+
namespace.header = 'opencv/cv.h'
|
40
|
+
assert_equal 'opencv/cv.h', namespace.header
|
41
|
+
end
|
42
|
+
|
43
|
+
should 'remove members on minus equal operator when bound' do
|
44
|
+
namespace = Dub.parse(fixture('app/xml/namespacedub.xml'))[:dub]
|
45
|
+
namespace.ignore 'FMatrix'
|
46
|
+
assert_equal %w{Matrix}, namespace.classes.map{|k| k.name}
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'when bound' do
|
50
|
+
setup do
|
51
|
+
@generator = Dub::Lua.namespace_generator
|
52
|
+
end
|
53
|
+
|
54
|
+
should 'contain generator' do
|
55
|
+
res = Dub::Lua.bind(@namespace)
|
56
|
+
assert_equal res, @namespace
|
57
|
+
assert_equal @generator, @namespace.gen
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'with overloaded functions' do
|
63
|
+
setup do
|
64
|
+
@function = namespacecv_xml[:cv][:divide]
|
65
|
+
end
|
66
|
+
|
67
|
+
should 'find a Dub::FunctionGroup' do
|
68
|
+
assert_kind_of Dub::FunctionGroup, @function
|
69
|
+
end
|
70
|
+
|
71
|
+
should 'find a group of functions' do
|
72
|
+
assert_kind_of Dub::Function, @function[0]
|
73
|
+
assert_kind_of Dub::Function, @function[1]
|
74
|
+
end
|
75
|
+
|
76
|
+
should 'group functions by name' do
|
77
|
+
assert_equal 'divide', @function[0].name
|
78
|
+
assert_equal 'divide', @function[1].name
|
79
|
+
end
|
80
|
+
|
81
|
+
should 'assign an overloaded_index to grouped functions' do
|
82
|
+
assert_equal 1, @function[0].overloaded_index
|
83
|
+
assert_equal 2, @function[1].overloaded_index
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'A namespace with class definitions' do
|
89
|
+
setup do
|
90
|
+
@namespace = namespacedub_xml[:dub]
|
91
|
+
end
|
92
|
+
|
93
|
+
should 'find classes by array index' do
|
94
|
+
assert_kind_of Dub::Klass, @namespace[:Matrix]
|
95
|
+
end
|
96
|
+
|
97
|
+
should 'find classes with klass' do
|
98
|
+
assert_kind_of Dub::Klass, @namespace.klass('Matrix')
|
99
|
+
end
|
100
|
+
|
101
|
+
should 'return a list of classes with classes' do
|
102
|
+
assert_kind_of Array, @namespace.classes
|
103
|
+
assert_kind_of Dub::Klass, @namespace.classes.first
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'A namespace with template class definitions' do
|
108
|
+
setup do
|
109
|
+
@namespace = namespacedub_xml[:dub]
|
110
|
+
end
|
111
|
+
|
112
|
+
should 'ignore template classes in class list' do
|
113
|
+
assert !@namespace.classes.map{|m| m.name}.include?("TMat")
|
114
|
+
end
|
115
|
+
|
116
|
+
should 'return template class with template_class' do
|
117
|
+
assert_kind_of Dub::Klass, @namespace.template_class('TMat')
|
118
|
+
end
|
119
|
+
|
120
|
+
should 'build a full classes for template typedefs' do
|
121
|
+
assert_kind_of Dub::Klass, @namespace.klass(:FloatMat)
|
122
|
+
end
|
123
|
+
|
124
|
+
context 'bound to a generator' do
|
125
|
+
setup do
|
126
|
+
Dub::Lua.bind(@namespace)
|
127
|
+
end
|
128
|
+
|
129
|
+
should 'generate a valid class' do
|
130
|
+
# TODO: rerun all tests for lua class generation
|
131
|
+
assert_match %r{luaL_register\(L,\s*"dub".*FMatrix}, @namespace[:FloatMat].to_s
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context 'A namespace with enums' do
|
137
|
+
setup do
|
138
|
+
@namespace = namespacecv_xml[:cv]
|
139
|
+
end
|
140
|
+
|
141
|
+
should 'respond true to has_enums' do
|
142
|
+
assert @namespace.has_constants?
|
143
|
+
end
|
144
|
+
|
145
|
+
should 'produce namespaced declarations' do
|
146
|
+
assert_match %r{\{"INTER_LINEAR"\s*,\s*cv::INTER_LINEAR\}}, Dub::Lua.namespace_generator.constants_registration(@namespace)
|
147
|
+
end
|
148
|
+
|
149
|
+
context 'bound to a generator' do
|
150
|
+
setup do
|
151
|
+
Dub::Lua.bind(@namespace)
|
152
|
+
end
|
153
|
+
|
154
|
+
should 'produce enums registration' do
|
155
|
+
result = @namespace.to_s
|
156
|
+
assert_match %r{\{"INTER_LINEAR"\s*,\s*cv::INTER_LINEAR\}}, result
|
157
|
+
assert_match %r{register_constants\(L,\s*"cv",\s*cv_namespace_constants\)}, result
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
context 'On merge with a group' do
|
162
|
+
setup do
|
163
|
+
@namespace = Dub.parse(fixture('namespacecv.xml'))[:cv]
|
164
|
+
group = Dub.parse(fixture('group___magic_type.xml'))[:MagicType]
|
165
|
+
@namespace.merge!(group)
|
166
|
+
Dub::Lua.bind(@namespace)
|
167
|
+
end
|
168
|
+
|
169
|
+
should 'produce enums and defines registration' do
|
170
|
+
result = @namespace.to_s
|
171
|
+
assert_match %r{\{"INTER_LINEAR"\s*,\s*cv::INTER_LINEAR\}}, result
|
172
|
+
assert_match %r{register_constants\(L,\s*"cv",\s*cv_namespace_constants\)}, result
|
173
|
+
assert_match %r{\{"CV_32FC1"\s*,\s*CV_32FC1\}}, result
|
174
|
+
assert_match %r{register_constants\(L,\s*"cv",\s*cv_namespace_constants\)}, result
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context 'A Group with defines' do
|
180
|
+
setup do
|
181
|
+
# groupmagic_xml = Dub.parse(fixture('group___magic_type.xml'))
|
182
|
+
@group = groupmagic_xml[:MagicType]
|
183
|
+
end
|
184
|
+
|
185
|
+
should 'parse defines' do
|
186
|
+
assert @group.defines.include?("CV_32FC1")
|
187
|
+
end
|
188
|
+
|
189
|
+
should 'ignore defines with parameters' do
|
190
|
+
assert !@group.defines.include?("CV_8UC")
|
191
|
+
end
|
192
|
+
|
193
|
+
context 'bound to a generator' do
|
194
|
+
setup do
|
195
|
+
Dub::Lua.bind(@group)
|
196
|
+
@group.name = 'cv'
|
197
|
+
end
|
198
|
+
|
199
|
+
should 'produce defines registration' do
|
200
|
+
result = @group.to_s
|
201
|
+
assert_match %r{\{"CV_32FC1"\s*,\s*CV_32FC1\}}, result
|
202
|
+
assert_match %r{register_constants\(L,\s*"cv",\s*cv_namespace_constants\)}, result
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
context 'A namespace bound to a generator' do
|
208
|
+
setup do
|
209
|
+
@namespace = namespacecv_xml[:cv]
|
210
|
+
Dub::Lua.bind(@namespace)
|
211
|
+
end
|
212
|
+
|
213
|
+
should 'produce methods registration' do
|
214
|
+
result = @namespace.to_s
|
215
|
+
assert_match %r{\{"resize"\s*,\s*cv_resize\},}, result
|
216
|
+
assert_match %r{luaL_register\(L,\s*"cv".*cv_functions}, result
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
end
|
data/test/parser_test.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class ParserTest < Test::Unit::TestCase
|
4
|
+
# cache parsing to speed things up
|
5
|
+
@@namespace = Dub.parse(fixture('namespacecv.xml'))
|
6
|
+
@@group = Dub.parse(fixture('group___magic_type.xml'))
|
7
|
+
|
8
|
+
context 'Parsing a namespace' do
|
9
|
+
setup do
|
10
|
+
@parser = @@namespace
|
11
|
+
end
|
12
|
+
|
13
|
+
should 'find cv namespace with namespace method' do
|
14
|
+
assert_kind_of Dub::Namespace, @parser.namespace(:cv)
|
15
|
+
end
|
16
|
+
|
17
|
+
should 'find namespace with array index' do
|
18
|
+
assert_kind_of Dub::Namespace, @parser[:cv]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'Parsing a group' do
|
23
|
+
setup do
|
24
|
+
@parser = @@group
|
25
|
+
end
|
26
|
+
|
27
|
+
should 'find MagicType group with group method' do
|
28
|
+
assert_kind_of Dub::Namespace, @parser.group(:MagicType)
|
29
|
+
end
|
30
|
+
|
31
|
+
should 'find group with array index' do
|
32
|
+
assert_kind_of Dub::Namespace, @parser[:MagicType]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|