dub 0.2.2 → 0.6.2
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/.gitignore +8 -0
- data/History.txt +32 -0
- data/LICENSE +20 -0
- data/README.rdoc +48 -0
- data/Rakefile +58 -0
- data/dub.gemspec +197 -0
- data/lib/dub/argument.rb +275 -0
- data/lib/dub/entities_unescape.rb +16 -0
- data/lib/dub/function.rb +163 -0
- data/lib/dub/function_group.rb +72 -0
- data/lib/dub/generator.rb +15 -0
- data/lib/dub/group.rb +24 -0
- data/lib/dub/klass.rb +231 -0
- data/lib/dub/lua/class.cpp.erb +83 -0
- data/lib/dub/lua/class_gen.rb +97 -0
- data/lib/dub/lua/function.cpp.erb +18 -0
- data/lib/dub/lua/function_gen.rb +258 -0
- data/lib/dub/lua/group.cpp.erb +9 -0
- data/lib/dub/lua/lua_cpp_helper.h +141 -0
- data/lib/dub/lua/namespace.cpp.erb +40 -0
- data/lib/dub/lua/namespace_gen.rb +88 -0
- data/lib/dub/lua.rb +24 -0
- data/lib/dub/member_extraction.rb +92 -0
- data/lib/dub/namespace.rb +277 -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 +23 -20
- data/test/argument_test.rb +547 -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 +140 -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_matrix.xml +281 -0
- data/test/fixtures/app/xml/classdub_1_1_t_mat.xml +233 -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 +44 -0
- data/test/fixtures/app/xml/index.xsd +66 -0
- data/test/fixtures/app/xml/matrix_8h.xml +157 -0
- data/test/fixtures/app/xml/namespacedub.xml +41 -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 +24 -0
- data/test/function_test.rb +395 -0
- data/test/group_test.rb +155 -0
- data/test/helper.rb +34 -0
- data/test/klass_test.rb +387 -0
- data/test/lua_function_gen_test.rb +195 -0
- data/test/namespace_test.rb +220 -0
- data/test/parser_test.rb +36 -0
- metadata +211 -275
- 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
data/test/klass_test.rb
ADDED
@@ -0,0 +1,387 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'dub/lua'
|
3
|
+
|
4
|
+
class KlassTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context 'A Klass' do
|
7
|
+
setup do
|
8
|
+
# namespacecv_xml = Dub.parse(fixture('app/xml/namespacedub.xml'))
|
9
|
+
@class = namespacedub_xml[:dub][:Matrix]
|
10
|
+
end
|
11
|
+
|
12
|
+
should 'return a list of Functions with members' do
|
13
|
+
assert_kind_of Array, @class.members
|
14
|
+
assert_kind_of Dub::Function, @class.members.first
|
15
|
+
end
|
16
|
+
|
17
|
+
should 'return name with name' do
|
18
|
+
assert_equal 'Matrix', @class.name
|
19
|
+
end
|
20
|
+
|
21
|
+
should 'have namespace prefix' do
|
22
|
+
assert_equal 'dub', @class.prefix
|
23
|
+
end
|
24
|
+
|
25
|
+
should 'combine prefix and name in lib_name' do
|
26
|
+
assert_equal 'dub_Matrix', @class.lib_name
|
27
|
+
end
|
28
|
+
|
29
|
+
should 'combine prefix and name in id_name' do
|
30
|
+
assert_equal 'dub.Matrix', @class.id_name
|
31
|
+
end
|
32
|
+
|
33
|
+
should 'combine prefix and provided name in id_name' do
|
34
|
+
assert_equal 'dub.Foobar', @class.id_name('Foobar')
|
35
|
+
end
|
36
|
+
|
37
|
+
should 'use parent namespace in full_type' do
|
38
|
+
assert_equal 'dub::Matrix', @class.full_type
|
39
|
+
end
|
40
|
+
|
41
|
+
should 'return file and line on source' do
|
42
|
+
assert_match %r{app/include/matrix\.h:\d+}, @class.source
|
43
|
+
end
|
44
|
+
|
45
|
+
should 'return a list of class methods' do
|
46
|
+
assert_kind_of Array, @class.class_methods
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'with a bound member list' do
|
50
|
+
setup do
|
51
|
+
Dub::Lua.bind(@class)
|
52
|
+
@list = @class.members.map {|m| m.name}
|
53
|
+
end
|
54
|
+
|
55
|
+
should 'remove destructor from member list' do
|
56
|
+
assert !@list.include?("~Matrix")
|
57
|
+
end
|
58
|
+
|
59
|
+
should 'remove constructor from member list' do
|
60
|
+
assert !@list.include?("Matrix")
|
61
|
+
end
|
62
|
+
|
63
|
+
should 'ignore template methods in member list' do
|
64
|
+
assert !@list.include?("give_me_tea")
|
65
|
+
end
|
66
|
+
|
67
|
+
should 'ignore members with templated arguments' do
|
68
|
+
# at least for now
|
69
|
+
assert @class[:mul].has_complex_arguments?
|
70
|
+
assert !@list.include?("mul")
|
71
|
+
assert_no_match %r{Matrix_mul}, @class.to_s
|
72
|
+
end
|
73
|
+
|
74
|
+
should 'ignore operator methods in member list' do
|
75
|
+
assert !@list.include?("operator size_t")
|
76
|
+
end
|
77
|
+
|
78
|
+
should 'ignore members returning native pointers' do
|
79
|
+
assert !@list.include?("ptr")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
should 'return constructor with constructor' do
|
84
|
+
const = @class.constructor
|
85
|
+
assert_kind_of Dub::Function, const.first
|
86
|
+
end
|
87
|
+
|
88
|
+
should 'respond to destructor_name' do
|
89
|
+
assert_equal 'Matrix_destructor', @class.destructor_name
|
90
|
+
end
|
91
|
+
|
92
|
+
should 'respond to tostring_name' do
|
93
|
+
assert_equal 'Matrix__tostring', @class.tostring_name
|
94
|
+
end
|
95
|
+
|
96
|
+
should 'respond to constructor.method_name' do
|
97
|
+
assert_equal 'Matrix_Matrix', @class.constructor.method_name(0)
|
98
|
+
end
|
99
|
+
|
100
|
+
should 'find method with array index' do
|
101
|
+
assert_kind_of Dub::Function, @class[:rows]
|
102
|
+
end
|
103
|
+
|
104
|
+
should 'find static methods with array index' do
|
105
|
+
assert_kind_of Dub::Function, @class[:MakeMatrix]
|
106
|
+
end
|
107
|
+
|
108
|
+
should 'return header name on header' do
|
109
|
+
assert_equal 'matrix.h', @class.header
|
110
|
+
end
|
111
|
+
|
112
|
+
should 'return defined header if changed' do
|
113
|
+
klass = Dub.parse(fixture('app/xml/namespacedub.xml'))[:dub][:Matrix]
|
114
|
+
klass.header = 'opencv/cv.h'
|
115
|
+
assert_equal 'opencv/cv.h', klass.header
|
116
|
+
end
|
117
|
+
|
118
|
+
should 'know that it is not a template' do
|
119
|
+
assert !@class.template?
|
120
|
+
end
|
121
|
+
|
122
|
+
context 'bound to a generator' do
|
123
|
+
setup do
|
124
|
+
Dub::Lua.bind(@class)
|
125
|
+
end
|
126
|
+
|
127
|
+
should 'bind each member' do
|
128
|
+
assert_equal Dub::Lua.function_generator, @class.members.first.gen
|
129
|
+
end
|
130
|
+
|
131
|
+
should 'register constructor' do
|
132
|
+
assert_match %r{\{\s*\"Matrix\"\s*,\s*Matrix_Matrix\s*\}}, @class.to_s
|
133
|
+
end
|
134
|
+
|
135
|
+
should 'build constructor' do
|
136
|
+
result = @class.to_s
|
137
|
+
assert_match %r{static int Matrix_Matrix1\s*\(}, result
|
138
|
+
assert_match %r{static int Matrix_Matrix2\s*\(}, result
|
139
|
+
assert_match %r{static int Matrix_Matrix\s*\(}, result
|
140
|
+
end
|
141
|
+
|
142
|
+
should 'return new objects in constructors' do
|
143
|
+
@class = namespacecv_xml[:cv][:Mat]
|
144
|
+
Dub::Lua.bind(@class)
|
145
|
+
assert_match %r{lua_pushclass<Mat>.*"cv.Mat"}, @class.constructor.first.to_s
|
146
|
+
end
|
147
|
+
|
148
|
+
should 'include class header' do
|
149
|
+
assert_match %r{#include\s+"matrix.h"}, @class.to_s
|
150
|
+
end
|
151
|
+
|
152
|
+
should 'include helper header' do
|
153
|
+
assert_match %r{#include\s+"lua_cpp_helper.h"}, @class.to_s
|
154
|
+
end
|
155
|
+
|
156
|
+
should 'create Lua metatable with class name' do
|
157
|
+
assert_match %r{luaL_newmetatable\(L,\s*"dub.Matrix"\)}, @class.to_s
|
158
|
+
end
|
159
|
+
|
160
|
+
should 'not build template methods' do
|
161
|
+
assert_no_match %r{give_me_tea}, @class.to_s
|
162
|
+
end
|
163
|
+
|
164
|
+
should 'declare tostring' do
|
165
|
+
assert_match %r{__tostring}, @class.to_s
|
166
|
+
end
|
167
|
+
|
168
|
+
should 'use custom format if provided for tostring' do
|
169
|
+
@class.string_format = "%dx%d"
|
170
|
+
@class.string_args = "(*userdata)->rows, (*userdata)->cols"
|
171
|
+
assert_match %r{\(\*userdata\)->rows, \(\*userdata\)->cols}, @class.to_s
|
172
|
+
end
|
173
|
+
|
174
|
+
should 'use a default method for tostring if no custom string_format is provided' do
|
175
|
+
@class.string_format = nil
|
176
|
+
assert_match %r{<dub.Matrix: %p>}, @class.to_s
|
177
|
+
end
|
178
|
+
|
179
|
+
should 'implement tostring' do
|
180
|
+
assert_match %r{Matrix__tostring\(lua_State}, @class.to_s
|
181
|
+
end
|
182
|
+
|
183
|
+
context 'using a custom template' do
|
184
|
+
setup do
|
185
|
+
@class.gen.template_path = fixture('dummy_class.cpp.erb')
|
186
|
+
end
|
187
|
+
|
188
|
+
teardown do
|
189
|
+
@class.gen.template_path = nil
|
190
|
+
end
|
191
|
+
|
192
|
+
should 'use custom template to render function' do
|
193
|
+
assert_equal 'CLASS: Matrix', @class.to_s
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
context 'A template class' do
|
200
|
+
setup do
|
201
|
+
# namespacecv_xml = Dub.parse(fixture('app/xml/namespacedub.xml'))
|
202
|
+
@class = namespacedub_xml[:dub].template_class(:TMat)
|
203
|
+
end
|
204
|
+
|
205
|
+
should 'know that it is a template' do
|
206
|
+
assert @class.template?
|
207
|
+
end
|
208
|
+
|
209
|
+
should 'return template parameters' do
|
210
|
+
assert_equal ['T'], @class.template_params
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
context 'A class defined from a template' do
|
215
|
+
setup do
|
216
|
+
@class = namespacecv_xml[:cv][:Size]
|
217
|
+
end
|
218
|
+
|
219
|
+
should 'replace template parameter in method arguments' do
|
220
|
+
Dub::Lua.bind(@class)
|
221
|
+
assert_match %r{int *_width}, @class.to_s
|
222
|
+
end
|
223
|
+
|
224
|
+
should 'register in the template for these types' do
|
225
|
+
@tclass = namespacecv_xml[:cv].template_class(:Size_)
|
226
|
+
assert_equal @class, @tclass.instanciations[['int']]
|
227
|
+
end
|
228
|
+
|
229
|
+
context 'with a bound member list' do
|
230
|
+
setup do
|
231
|
+
@class = namespacedub_xml[:dub][:FMatrix]
|
232
|
+
Dub::Lua.bind(@class)
|
233
|
+
@list = @class.members.map {|m| m.name}
|
234
|
+
end
|
235
|
+
|
236
|
+
should 'ignore template methods in member list' do
|
237
|
+
assert !@list.include?("give_me_tea")
|
238
|
+
end
|
239
|
+
|
240
|
+
should 'ignore template methods in member registration' do
|
241
|
+
assert_no_match %r{give_me_tea}, @class.gen.method_registration(@class)
|
242
|
+
end
|
243
|
+
|
244
|
+
should 'ignore template methods in method istanciation' do
|
245
|
+
assert_no_match %r{give_me_tea}, @class.to_s
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
# strangely, the bug does not show up with "FMatrix"
|
251
|
+
context 'Another class defined from a template' do
|
252
|
+
setup do
|
253
|
+
@class = namespacecv_xml[:cv][:Scalar]
|
254
|
+
end
|
255
|
+
|
256
|
+
context 'with a bound member list' do
|
257
|
+
setup do
|
258
|
+
Dub::Lua.bind(@class)
|
259
|
+
@list = @class.members.map {|m| m.name}
|
260
|
+
end
|
261
|
+
|
262
|
+
should 'ignore template methods in member list' do
|
263
|
+
assert !@list.include?("convertTo")
|
264
|
+
end
|
265
|
+
|
266
|
+
should 'ignore template methods in member registration' do
|
267
|
+
assert_no_match %r{convertTo}, @class.gen.method_registration(@class)
|
268
|
+
end
|
269
|
+
|
270
|
+
should 'ignore template methods in method istanciation' do
|
271
|
+
assert_no_match %r{convertTo}, @class.to_s
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
context 'A class with alias names' do
|
277
|
+
setup do
|
278
|
+
# namespacecv_xml = Dub.parse(fixture('app/xml/namespacedub.xml'))
|
279
|
+
@class = namespacedub_xml[:dub][:FloatMat]
|
280
|
+
end
|
281
|
+
|
282
|
+
should 'return a list of these alias on alias_names' do
|
283
|
+
assert_equal ['FloatMat'], @class.alias_names
|
284
|
+
assert_equal 'FMatrix', @class.name
|
285
|
+
end
|
286
|
+
|
287
|
+
should 'find class from alias in namespace' do
|
288
|
+
assert_equal @class, namespacedub_xml[:dub][:FMatrix]
|
289
|
+
end
|
290
|
+
|
291
|
+
should 'use the shortest alias as main name' do
|
292
|
+
assert_equal 'Size', namespacecv_xml[:cv][:Size2i].name
|
293
|
+
end
|
294
|
+
|
295
|
+
should 'rename constructors to shortest name' do
|
296
|
+
assert_equal 'Size', namespacecv_xml[:cv][:Size].constructor.name
|
297
|
+
end
|
298
|
+
|
299
|
+
should 'parse arguments and evaluate types by resolving template params' do
|
300
|
+
size_class = namespacecv_xml[:cv][:Size]
|
301
|
+
Dub::Lua.bind(size_class)
|
302
|
+
assert_match %r{const Point \*pt}, size_class.constructor[5].to_s
|
303
|
+
end
|
304
|
+
|
305
|
+
context 'bound to a generator' do
|
306
|
+
setup do
|
307
|
+
Dub::Lua.bind(@class)
|
308
|
+
end
|
309
|
+
|
310
|
+
should 'register all alias_names' do
|
311
|
+
result = @class.to_s
|
312
|
+
assert_match %r{"FloatMat"\s*,\s*FMatrix_FMatrix}, result
|
313
|
+
assert_match %r{"FMatrix"\s*,\s*FMatrix_FMatrix}, result
|
314
|
+
assert_match %r{luaL_register\(L,\s*"dub".*FMatrix_namespace_methods}, result
|
315
|
+
end
|
316
|
+
|
317
|
+
should 'use the smallest name in method definition' do
|
318
|
+
assert_match %r{int FMatrix_FMatrix}, @class.to_s
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
context 'A class with overloaded methods' do
|
324
|
+
setup do
|
325
|
+
# namespacecv_xml = Dub.parse(fixture('app/xml/namespacedub.xml'))
|
326
|
+
@class = namespacecv_xml[:cv][:Mat]
|
327
|
+
Dub::Lua.bind(@class)
|
328
|
+
end
|
329
|
+
|
330
|
+
should 'declare chooser' do
|
331
|
+
result = @class.gen.method_registration(@class)
|
332
|
+
assert_match %r{"diag"\s*,\s*Mat_diag\}}, result
|
333
|
+
assert_no_match %r{diag1}, result
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
context 'A class with overloaded static methods' do
|
338
|
+
setup do
|
339
|
+
# namespacecv_xml = Dub.parse(fixture('app/xml/namespacedub.xml'))
|
340
|
+
@class = namespacecv_xml[:cv][:Mat]
|
341
|
+
Dub::Lua.bind(@class)
|
342
|
+
end
|
343
|
+
|
344
|
+
should 'declare chooser' do
|
345
|
+
result = @class.gen.namespace_methods_registration(@class)
|
346
|
+
assert_match %r{"Mat_zeros"\s*,\s*Mat_zeros\}}, result
|
347
|
+
assert_no_match %r{zeros1}, result
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
context 'A complex class' do
|
352
|
+
setup do
|
353
|
+
# namespacecv_xml = Dub.parse(fixture('app/xml/namespacedub.xml'))
|
354
|
+
@class = namespacecv_xml[:cv][:Mat]
|
355
|
+
end
|
356
|
+
|
357
|
+
context 'bound to a generator' do
|
358
|
+
setup do
|
359
|
+
Dub::Lua.bind(@class)
|
360
|
+
end
|
361
|
+
|
362
|
+
should 'list all members on members' do
|
363
|
+
assert_equal %w{addref adjustROI assignTo channels clone col colRange convertTo copyTo create cross depth diag dot elemSize elemSize1 empty eye isContinuous locateROI ones release reshape row rowRange setTo size step1 type zeros}, @class.members.map {|m| m.name}
|
364
|
+
end
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
context 'A class with enums' do
|
369
|
+
setup do
|
370
|
+
# namespacecv_xml = Dub.parse(fixture('app/xml/namespacedub.xml'))
|
371
|
+
@class = namespacecv_xml[:cv][:Mat]
|
372
|
+
end
|
373
|
+
|
374
|
+
should 'respond true to has_enums' do
|
375
|
+
assert @class.has_constants?
|
376
|
+
end
|
377
|
+
|
378
|
+
should 'produce namespaced declarations' do
|
379
|
+
assert_match %r{\{"AUTO_STEP"\s*,\s*cv::Mat::AUTO_STEP\}}, Dub::Lua.class_generator.constants_registration(@class)
|
380
|
+
end
|
381
|
+
|
382
|
+
should 'find a list of enums' do
|
383
|
+
assert_equal %w{MAGIC_VAL AUTO_STEP CONTINUOUS_FLAG}, @class.enums
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
387
|
+
end
|
@@ -0,0 +1,195 @@
|
|
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
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'A group of overloaded functions' do
|
81
|
+
setup do
|
82
|
+
# namespacecv_xml = Dub.parse(fixture('namespacecv.xml'))
|
83
|
+
@function_group = namespacecv_xml[:cv][:divide]
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'bound to a Lua generator' do
|
87
|
+
setup do
|
88
|
+
Dub::Lua.bind(@function_group)
|
89
|
+
end
|
90
|
+
|
91
|
+
should 'return string content on to_s' do
|
92
|
+
assert_kind_of String, @function_group.to_s
|
93
|
+
end
|
94
|
+
|
95
|
+
should 'generate a static function returning an int' do
|
96
|
+
assert_match %r{static int cv_divide}, @function_group.to_s
|
97
|
+
end
|
98
|
+
|
99
|
+
should 'generate a static function returning an int for each overloaded function' do
|
100
|
+
bindings = @function_group.to_s
|
101
|
+
assert_match %r{static int cv_divide1}, bindings
|
102
|
+
assert_match %r{static int cv_divide2}, bindings
|
103
|
+
assert_match %r{static int cv_divide3}, bindings
|
104
|
+
assert_match %r{static int cv_divide4}, bindings
|
105
|
+
end
|
106
|
+
|
107
|
+
# should 'declare chooser' do
|
108
|
+
# assert_match %r{"divide",\s*cv_divide\}}, @group.to_s
|
109
|
+
# end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'A function with a custom class return value' do
|
114
|
+
setup do
|
115
|
+
# namespacecv_xml = Dub.parse(fixture('namespacecv.xml'))
|
116
|
+
@function = namespacecv_xml[:cv][:getRotationMatrix2D]
|
117
|
+
end
|
118
|
+
|
119
|
+
context 'bound to a Lua generator' do
|
120
|
+
setup do
|
121
|
+
Dub::Lua.bind(@function)
|
122
|
+
end
|
123
|
+
|
124
|
+
should 'call template push method' do
|
125
|
+
assert_match %r{lua_pushclass<Mat>\(\s*L\s*,\s*retval__\s*,\s*"cv.Mat"\s*\)}, @function.to_s
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context 'A function with pointer parameters' do
|
131
|
+
setup do
|
132
|
+
# namespacecv_xml = Dub.parse(fixture('namespacecv.xml'))
|
133
|
+
@function = namespacecv_xml[:cv][:calcHist][0]
|
134
|
+
end
|
135
|
+
|
136
|
+
context 'bound to a Lua generator' do
|
137
|
+
setup do
|
138
|
+
Dub::Lua.bind(@function)
|
139
|
+
end
|
140
|
+
|
141
|
+
should 'use a DubArgPointer with the given type' do
|
142
|
+
assert_match %r{DubArgPointer<int>}, @function.to_s
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'A member function bound to a Lua generator' do
|
148
|
+
setup do
|
149
|
+
@member = namespacedub_xml[:dub][:Matrix][:rows]
|
150
|
+
Dub::Lua.bind(@member)
|
151
|
+
end
|
152
|
+
|
153
|
+
should 'start by getting self' do
|
154
|
+
assert_match %r{self__\s*=\s*\*\(\(Matrix\*\*\)luaL_checkudata}, @member.to_s
|
155
|
+
end
|
156
|
+
|
157
|
+
should 'prefix call with self' do
|
158
|
+
assert_match %r{self__->rows\(}, @member.to_s
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context 'A constructor bound to a Lua generator' do
|
163
|
+
setup do
|
164
|
+
@constructor = namespacedub_xml[:dub][:Matrix][:Matrix].first
|
165
|
+
Dub::Lua.bind(@constructor)
|
166
|
+
end
|
167
|
+
|
168
|
+
should 'use pushclass in constructor' do
|
169
|
+
result = @constructor.to_s
|
170
|
+
assert_match %r{lua_pushclass<Matrix>\s*\(L, retval__, \"dub.Matrix\"\s*\)}, result
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context 'A function without return value' do
|
175
|
+
setup do
|
176
|
+
@function = namespacecv_xml[:cv][:blur]
|
177
|
+
end
|
178
|
+
|
179
|
+
context 'bound to a Lua generator' do
|
180
|
+
setup do
|
181
|
+
Dub::Lua.bind(@function)
|
182
|
+
end
|
183
|
+
|
184
|
+
should 'return 0' do
|
185
|
+
assert_match %r{return\s+0}, @function.to_s
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
|
191
|
+
end
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
|