dub 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/History.txt +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +53 -0
- data/Rakefile +58 -0
- data/dub.gemspec +194 -0
- data/lib/dub/argument.rb +261 -0
- data/lib/dub/entities_unescape.rb +16 -0
- data/lib/dub/function.rb +111 -0
- data/lib/dub/function_group.rb +74 -0
- data/lib/dub/generator.rb +15 -0
- data/lib/dub/group.rb +10 -0
- data/lib/dub/klass.rb +231 -0
- data/lib/dub/lua/class.cpp.erb +75 -0
- data/lib/dub/lua/class_gen.rb +78 -0
- data/lib/dub/lua/function.cpp.erb +4 -0
- data/lib/dub/lua/function_gen.rb +223 -0
- data/lib/dub/lua/group.cpp.erb +10 -0
- data/lib/dub/lua/lua_cpp_helper.h +141 -0
- data/lib/dub/lua/namespace.cpp.erb +35 -0
- data/lib/dub/lua/namespace_gen.rb +86 -0
- data/lib/dub/lua.rb +24 -0
- data/lib/dub/member_extraction.rb +88 -0
- data/lib/dub/namespace.rb +276 -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 +26 -0
- data/test/argument_test.rb +423 -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 +123 -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 +239 -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 +42 -0
- data/test/fixtures/app/xml/index.xsd +66 -0
- data/test/fixtures/app/xml/matrix_8h.xml +149 -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_size__.xml +270 -0
- data/test/fixtures/group___magic_type.xml +406 -0
- data/test/fixtures/namespacecv.xml +12659 -0
- data/test/function_group_test.rb +15 -0
- data/test/function_test.rb +252 -0
- data/test/group_test.rb +155 -0
- data/test/helper.rb +34 -0
- data/test/klass_test.rb +297 -0
- data/test/lua_function_gen_test.rb +179 -0
- data/test/namespace_test.rb +220 -0
- data/test/parser_test.rb +36 -0
- metadata +216 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class FunctionGroupTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context 'A FunctionGroup' do
|
6
|
+
setup do
|
7
|
+
# namespacecv_xml = Dub.parse(fixture('namespacecv.xml'))
|
8
|
+
@group = namespacecv_xml[:cv][:divide]
|
9
|
+
end
|
10
|
+
|
11
|
+
should 'keep its members sorted by overloaded_index' do
|
12
|
+
assert_equal [1, 2, 3, 4], @group.map {|f| f.overloaded_index}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,252 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'dub/lua'
|
3
|
+
|
4
|
+
class FunctionTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
context 'A Function' do
|
7
|
+
setup do
|
8
|
+
# namespacecv_xml = Dub.parse(fixture('namespacecv.xml'))
|
9
|
+
@function = namespacecv_xml[:cv][:resize]
|
10
|
+
end
|
11
|
+
|
12
|
+
should 'return a list of Arguments with arguments' do
|
13
|
+
assert_kind_of Array, @function.arguments
|
14
|
+
assert_kind_of Dub::Argument, @function.arguments.first
|
15
|
+
end
|
16
|
+
|
17
|
+
should 'return name with name' do
|
18
|
+
assert_equal 'resize', @function.name
|
19
|
+
end
|
20
|
+
|
21
|
+
should 'have namespace prefix' do
|
22
|
+
assert_equal 'cv', @function.prefix
|
23
|
+
end
|
24
|
+
|
25
|
+
should 'display original_signature' do
|
26
|
+
assert_equal 'CV_EXPORTS void cv::resize(const Mat &src, Mat &dst, Size dsize, double fx=0, double fy=0, int interpolation=INTER_LINEAR)', @function.original_signature
|
27
|
+
end
|
28
|
+
|
29
|
+
should 'return file and line on source' do
|
30
|
+
assert_equal 'include/opencv/cv.hpp:343', @function.source
|
31
|
+
end
|
32
|
+
|
33
|
+
should 'know if it has default arguments' do
|
34
|
+
assert @function.has_default_arguments?
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'without default arguments' do
|
38
|
+
setup do
|
39
|
+
@function = namespacecv_xml[:cv][:getRotationMatrix2D]
|
40
|
+
end
|
41
|
+
|
42
|
+
should 'know if it has default arguments' do
|
43
|
+
assert !@function.has_default_arguments?
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'without a return value' do
|
48
|
+
should 'know the type of a returned value' do
|
49
|
+
assert_equal nil, @function.return_value
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'with a return value' do
|
54
|
+
setup do
|
55
|
+
@function = namespacecv_xml[:cv][:getRotationMatrix2D]
|
56
|
+
end
|
57
|
+
|
58
|
+
should 'return an Argument on return_value' do
|
59
|
+
assert_kind_of Dub::Argument, @function.return_value
|
60
|
+
end
|
61
|
+
|
62
|
+
should 'know the type of a returned value' do
|
63
|
+
assert_equal 'Mat', @function.return_value.type
|
64
|
+
end
|
65
|
+
|
66
|
+
should 'not use a pointer for create_type' do
|
67
|
+
assert_equal 'Mat ', @function.return_value.create_type
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'with a pointer to native type return value' do
|
72
|
+
setup do
|
73
|
+
@function = namespacecv_xml[:cv][:Mat][:ptr].first
|
74
|
+
end
|
75
|
+
|
76
|
+
should 'know the type of the returned value' do
|
77
|
+
assert_equal 'uchar *', @function.return_value.create_type
|
78
|
+
end
|
79
|
+
|
80
|
+
should 'know that the type is a native pointer' do
|
81
|
+
assert @function.return_value.is_pointer?
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'with a reference return value' do
|
86
|
+
setup do
|
87
|
+
@function = namespacecv_xml[:cv][:Mat][:adjustROI]
|
88
|
+
end
|
89
|
+
|
90
|
+
should 'strip ref in the create type' do
|
91
|
+
assert_equal 'Mat ', @function.return_value.create_type
|
92
|
+
end
|
93
|
+
|
94
|
+
should 'know that the type is a not native pointer' do
|
95
|
+
assert !@function.return_value.is_pointer?
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'with a void pointer return value' do
|
100
|
+
setup do
|
101
|
+
@function = namespacecv_xml[:cv][:fastMalloc]
|
102
|
+
#Dub::Lua.bind(@function)
|
103
|
+
end
|
104
|
+
|
105
|
+
should 'strip ref in the create type' do
|
106
|
+
assert_equal 'void *', @function.return_value.create_type
|
107
|
+
end
|
108
|
+
|
109
|
+
should 'be ignored by generator' do
|
110
|
+
assert Dub::Lua.namespace_generator.ignore_member?(@function)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context 'with a class return value' do
|
115
|
+
setup do
|
116
|
+
@function = namespacecv_xml[:cv][:Mat][:row]
|
117
|
+
end
|
118
|
+
|
119
|
+
should 'return new objects in constructors' do
|
120
|
+
Dub::Lua.bind(@function)
|
121
|
+
assert_match %r{lua_pushclass<Mat>.*"cv.Mat"}, @function.to_s
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context 'A vararg method' do
|
127
|
+
setup do
|
128
|
+
@function = namespacecv_xml[:cv][:format]
|
129
|
+
end
|
130
|
+
|
131
|
+
should 'know it is a vararg' do
|
132
|
+
assert @function.vararg?
|
133
|
+
end
|
134
|
+
|
135
|
+
should 'be ignored by generator' do
|
136
|
+
assert Dub::Lua.namespace_generator.ignore_member?(@function)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context 'A constructor with void pointer argument' do
|
141
|
+
setup do
|
142
|
+
@function = namespacecv_xml[:cv][:Mat].constructor[6]
|
143
|
+
end
|
144
|
+
|
145
|
+
should 'be ignored by generator' do
|
146
|
+
assert Dub::Lua.class_generator.ignore_member?(@function)
|
147
|
+
end
|
148
|
+
|
149
|
+
should 'not have array arguments' do
|
150
|
+
assert !namespacecv_xml[:cv][:Mat].constructor[2].has_array_arguments?
|
151
|
+
end
|
152
|
+
|
153
|
+
should 'not be listed in group members if bound' do
|
154
|
+
klass = namespacecv_xml[:cv][:Mat]
|
155
|
+
Dub::Lua.bind(klass)
|
156
|
+
assert !klass.constructor.members.include?(@function)
|
157
|
+
end
|
158
|
+
|
159
|
+
should 'be removed from group list on to_s' do
|
160
|
+
klass = namespacecv_xml[:cv][:Mat]
|
161
|
+
Dub::Lua.bind(klass)
|
162
|
+
assert_no_match %r{void\s*\*_data,\s*size_t}, klass.constructor.to_s
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
context 'A function with void pointer argument' do
|
167
|
+
setup do
|
168
|
+
@function = namespacecv_xml[:cv][:fastFree]
|
169
|
+
end
|
170
|
+
|
171
|
+
should 'be ignored by generator' do
|
172
|
+
assert Dub::Lua.namespace_generator.ignore_member?(@function)
|
173
|
+
end
|
174
|
+
|
175
|
+
should 'be removed from members list' do
|
176
|
+
Dub::Lua.bind(namespacecv_xml[:cv])
|
177
|
+
assert !namespacecv_xml[:cv].members.include?(@function)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
context 'A method without arguments' do
|
182
|
+
setup do
|
183
|
+
@function = namespacecv_xml[:cv][:getCPUTickCount]
|
184
|
+
end
|
185
|
+
|
186
|
+
should 'parse return value' do
|
187
|
+
assert_equal 'int64', @function.return_value.type
|
188
|
+
end
|
189
|
+
|
190
|
+
should 'produce a one liner to call function' do
|
191
|
+
Dub::Lua.bind(@function)
|
192
|
+
assert_match %r{int64\s*retval__\s*=\s*getCPUTickCount\(\);}, @function.to_s
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
context 'A method' do
|
197
|
+
setup do
|
198
|
+
# namespacecv_xml = Dub.parse(fixture('app/xml/namespacedub.xml'))
|
199
|
+
@method = namespacedub_xml[:dub][:Matrix][:size]
|
200
|
+
end
|
201
|
+
|
202
|
+
should 'know that it belongs to a class' do
|
203
|
+
assert @method.member_method?
|
204
|
+
end
|
205
|
+
|
206
|
+
should 'know if it is a constructor' do
|
207
|
+
assert !@method.constructor?
|
208
|
+
end
|
209
|
+
|
210
|
+
should 'return klass on klass' do
|
211
|
+
assert_kind_of Dub::Klass, @method.klass
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
context 'A constructor' do
|
216
|
+
setup do
|
217
|
+
# namespacecv_xml = Dub.parse(fixture('app/xml/namespacedub.xml'))
|
218
|
+
@method = namespacedub_xml[:dub][:Matrix][:Matrix].first
|
219
|
+
end
|
220
|
+
|
221
|
+
should 'know that it belongs to a class' do
|
222
|
+
assert @method.member_method?
|
223
|
+
end
|
224
|
+
|
225
|
+
should 'know if it is a constructor' do
|
226
|
+
assert @method.constructor?
|
227
|
+
end
|
228
|
+
|
229
|
+
should 'return class name on return_value create_type' do
|
230
|
+
assert_equal 'Matrix', @method.return_value.type
|
231
|
+
end
|
232
|
+
|
233
|
+
should 'return class name pointer on return_value create_type' do
|
234
|
+
assert_equal 'Matrix *', @method.return_value.create_type
|
235
|
+
end
|
236
|
+
|
237
|
+
context 'from a typedef bound to a generator' do
|
238
|
+
setup do
|
239
|
+
@method = namespacecv_xml[:cv][:Size].constructor.first
|
240
|
+
Dub::Lua.bind(@method)
|
241
|
+
end
|
242
|
+
|
243
|
+
should 'know that it is a constructor' do
|
244
|
+
assert @method.constructor?
|
245
|
+
end
|
246
|
+
|
247
|
+
should 'push new userdata on new' do
|
248
|
+
assert_match %r{lua_pushclass<Size>.*"cv.Size".*return 1}m, @method.generator.return_value(@method)
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
data/test/group_test.rb
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'dub/lua'
|
3
|
+
|
4
|
+
class GroupTest < 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
|
+
context 'when bound' do
|
44
|
+
setup do
|
45
|
+
@generator = Dub::Lua.namespace_generator
|
46
|
+
end
|
47
|
+
|
48
|
+
should 'contain generator' do
|
49
|
+
res = Dub::Lua.bind(@namespace)
|
50
|
+
assert_equal res, @namespace
|
51
|
+
assert_equal @generator, @namespace.gen
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'with overloaded functions' do
|
57
|
+
setup do
|
58
|
+
@function = namespacecv_xml[:cv][:divide]
|
59
|
+
end
|
60
|
+
|
61
|
+
should 'find a Dub::FunctionGroup' do
|
62
|
+
assert_kind_of Dub::FunctionGroup, @function
|
63
|
+
end
|
64
|
+
|
65
|
+
should 'find a group of functions' do
|
66
|
+
assert_kind_of Dub::Function, @function[0]
|
67
|
+
assert_kind_of Dub::Function, @function[1]
|
68
|
+
end
|
69
|
+
|
70
|
+
should 'group functions by name' do
|
71
|
+
assert_equal 'divide', @function[0].name
|
72
|
+
assert_equal 'divide', @function[1].name
|
73
|
+
end
|
74
|
+
|
75
|
+
should 'assign an overloaded_index to grouped functions' do
|
76
|
+
assert_equal 1, @function[0].overloaded_index
|
77
|
+
assert_equal 2, @function[1].overloaded_index
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'A namespace with class definitions' do
|
83
|
+
setup do
|
84
|
+
@namespace = namespacedub_xml[:dub]
|
85
|
+
end
|
86
|
+
|
87
|
+
should 'find classes by array index' do
|
88
|
+
assert_kind_of Dub::Klass, @namespace[:Matrix]
|
89
|
+
end
|
90
|
+
|
91
|
+
should 'find classes with klass' do
|
92
|
+
assert_kind_of Dub::Klass, @namespace.klass('Matrix')
|
93
|
+
end
|
94
|
+
|
95
|
+
should 'return a list of classes with classes' do
|
96
|
+
assert_kind_of Array, @namespace.classes
|
97
|
+
assert_kind_of Dub::Klass, @namespace.classes.first
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'A namespace with template class definitions' do
|
102
|
+
setup do
|
103
|
+
@namespace = namespacedub_xml[:dub]
|
104
|
+
end
|
105
|
+
|
106
|
+
should 'ignore template classes in class list' do
|
107
|
+
assert !@namespace.classes.map{|m| m.name}.include?("TMat")
|
108
|
+
end
|
109
|
+
|
110
|
+
should 'return template class with template_class' do
|
111
|
+
assert_kind_of Dub::Klass, @namespace.template_class('TMat')
|
112
|
+
end
|
113
|
+
|
114
|
+
should 'build a full classes for template typedefs' do
|
115
|
+
assert_kind_of Dub::Klass, @namespace.klass(:FloatMat)
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'bound to a generator' do
|
119
|
+
setup do
|
120
|
+
Dub::Lua.bind(@namespace)
|
121
|
+
end
|
122
|
+
|
123
|
+
should 'generate a valid class' do
|
124
|
+
# TODO: rerun all tests for lua class generation
|
125
|
+
assert_match %r{luaL_register\(L,\s*"dub".*FMatrix}, @namespace[:FloatMat].to_s
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context 'A namespace with enums' do
|
131
|
+
setup do
|
132
|
+
@namespace = namespacecv_xml[:cv]
|
133
|
+
end
|
134
|
+
|
135
|
+
should 'respond true to has_enums' do
|
136
|
+
assert @namespace.has_constants?
|
137
|
+
end
|
138
|
+
|
139
|
+
should 'produce namespaced declarations' do
|
140
|
+
assert_match %r{\{"INTER_LINEAR"\s*,\s*cv::INTER_LINEAR\}}, Dub::Lua.namespace_generator.constants_registration(@namespace)
|
141
|
+
end
|
142
|
+
|
143
|
+
context 'bound to a generator' do
|
144
|
+
setup do
|
145
|
+
Dub::Lua.bind(@namespace)
|
146
|
+
end
|
147
|
+
|
148
|
+
should 'produce enums registration' do
|
149
|
+
result = @namespace.to_s
|
150
|
+
assert_match %r{\{"INTER_LINEAR"\s*,\s*cv::INTER_LINEAR\}}, result
|
151
|
+
assert_match %r{register_constants\(L,\s*"cv",\s*cv_namespace_constants\)}, result
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
7
|
+
require 'dub'
|
8
|
+
|
9
|
+
class Test::Unit::TestCase
|
10
|
+
|
11
|
+
def self.fixture(path)
|
12
|
+
File.join(File.dirname(__FILE__), 'fixtures', path)
|
13
|
+
end
|
14
|
+
|
15
|
+
@@namespacecv_xml = nil
|
16
|
+
|
17
|
+
Dub.logger.level = Logger::FATAL
|
18
|
+
|
19
|
+
def fixture(path)
|
20
|
+
self.class.fixture(path)
|
21
|
+
end
|
22
|
+
|
23
|
+
def namespacecv_xml
|
24
|
+
@@namespacecv_xml ||= Dub.parse(fixture('namespacecv.xml'))
|
25
|
+
end
|
26
|
+
|
27
|
+
def namespacedub_xml
|
28
|
+
@@namespacedub_xml ||= Dub.parse(fixture('app/xml/namespacedub.xml'))
|
29
|
+
end
|
30
|
+
|
31
|
+
def groupmagic_xml
|
32
|
+
@@groupmagic_xml ||= Dub.parse(fixture('group___magic_type.xml'))
|
33
|
+
end
|
34
|
+
end
|