ruby-qt6-rspec 2.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1994bf06f3196d9bdbc6a67e9ed4a597e65525f720062aa8477e02096b27a7b1
4
+ data.tar.gz: fa42c2e9468f2a7f264fc71488a70cd697292c8c408c2616361066fe4d7cb240
5
+ SHA512:
6
+ metadata.gz: 9a2f0de7b34a3090f9fb90c7b904726847f92c9a4f186033a7f236278a619f11a40a7a40f5d53596830ed9bde4803fdc1a42d55d910dfeb5ca03dd21d9866928
7
+ data.tar.gz: 82263286305544bdcb90ca21d1e45611ec43f3f0db6ba1e9339b36aab498bb3b14e73f3d2c418b2c2d87f88910cbdf9c5c739e68aac21dafa162d626000c8859
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,10 @@
1
+ require: standard
2
+
3
+ inherit_gem:
4
+ standard: config/base.yml
5
+
6
+ AllCops:
7
+ SuggestExtensions: false
8
+ Exclude:
9
+ - "bin/**/*"
10
+ - "tmp/**/*"
data/LICENSE ADDED
@@ -0,0 +1,185 @@
1
+ This software is licensed under the LGPLv3, included below.
2
+
3
+ As a special exception to the GNU Lesser General Public License version 3
4
+ ("LGPL3"), the copyright holders of this Library give you permission to
5
+ convey to a third party a Combined Work that links statically or dynamically
6
+ to this Library without providing any Minimal Corresponding Source or
7
+ Minimal Application Code as set out in 4d or providing the installation
8
+ information set out in section 4e, provided that you comply with the other
9
+ provisions of LGPL3 and provided that you meet, for the Application the
10
+ terms and conditions of the license(s) which apply to the Application.
11
+
12
+ Except as stated in this special exception, the provisions of LGPL3 will
13
+ continue to comply in full to this Library. If you modify this Library, you
14
+ may apply this exception to your version of this Library, but you are not
15
+ obliged to do so. If you do not wish to do so, delete this exception
16
+ statement from your version. This exception does not (and cannot) modify any
17
+ license terms which apply to the Application, with which you must still
18
+ comply.
19
+
20
+
21
+ GNU LESSER GENERAL PUBLIC LICENSE
22
+ Version 3, 29 June 2007
23
+
24
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
25
+ Everyone is permitted to copy and distribute verbatim copies
26
+ of this license document, but changing it is not allowed.
27
+
28
+
29
+ This version of the GNU Lesser General Public License incorporates
30
+ the terms and conditions of version 3 of the GNU General Public
31
+ License, supplemented by the additional permissions listed below.
32
+
33
+ 0. Additional Definitions.
34
+
35
+ As used herein, "this License" refers to version 3 of the GNU Lesser
36
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
37
+ General Public License.
38
+
39
+ "The Library" refers to a covered work governed by this License,
40
+ other than an Application or a Combined Work as defined below.
41
+
42
+ An "Application" is any work that makes use of an interface provided
43
+ by the Library, but which is not otherwise based on the Library.
44
+ Defining a subclass of a class defined by the Library is deemed a mode
45
+ of using an interface provided by the Library.
46
+
47
+ A "Combined Work" is a work produced by combining or linking an
48
+ Application with the Library. The particular version of the Library
49
+ with which the Combined Work was made is also called the "Linked
50
+ Version".
51
+
52
+ The "Minimal Corresponding Source" for a Combined Work means the
53
+ Corresponding Source for the Combined Work, excluding any source code
54
+ for portions of the Combined Work that, considered in isolation, are
55
+ based on the Application, and not on the Linked Version.
56
+
57
+ The "Corresponding Application Code" for a Combined Work means the
58
+ object code and/or source code for the Application, including any data
59
+ and utility programs needed for reproducing the Combined Work from the
60
+ Application, but excluding the System Libraries of the Combined Work.
61
+
62
+ 1. Exception to Section 3 of the GNU GPL.
63
+
64
+ You may convey a covered work under sections 3 and 4 of this License
65
+ without being bound by section 3 of the GNU GPL.
66
+
67
+ 2. Conveying Modified Versions.
68
+
69
+ If you modify a copy of the Library, and, in your modifications, a
70
+ facility refers to a function or data to be supplied by an Application
71
+ that uses the facility (other than as an argument passed when the
72
+ facility is invoked), then you may convey a copy of the modified
73
+ version:
74
+
75
+ a) under this License, provided that you make a good faith effort to
76
+ ensure that, in the event an Application does not supply the
77
+ function or data, the facility still operates, and performs
78
+ whatever part of its purpose remains meaningful, or
79
+
80
+ b) under the GNU GPL, with none of the additional permissions of
81
+ this License applicable to that copy.
82
+
83
+ 3. Object Code Incorporating Material from Library Header Files.
84
+
85
+ The object code form of an Application may incorporate material from
86
+ a header file that is part of the Library. You may convey such object
87
+ code under terms of your choice, provided that, if the incorporated
88
+ material is not limited to numerical parameters, data structure
89
+ layouts and accessors, or small macros, inline functions and templates
90
+ (ten or fewer lines in length), you do both of the following:
91
+
92
+ a) Give prominent notice with each copy of the object code that the
93
+ Library is used in it and that the Library and its use are
94
+ covered by this License.
95
+
96
+ b) Accompany the object code with a copy of the GNU GPL and this license
97
+ document.
98
+
99
+ 4. Combined Works.
100
+
101
+ You may convey a Combined Work under terms of your choice that,
102
+ taken together, effectively do not restrict modification of the
103
+ portions of the Library contained in the Combined Work and reverse
104
+ engineering for debugging such modifications, if you also do each of
105
+ the following:
106
+
107
+ a) Give prominent notice with each copy of the Combined Work that
108
+ the Library is used in it and that the Library and its use are
109
+ covered by this License.
110
+
111
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
112
+ document.
113
+
114
+ c) For a Combined Work that displays copyright notices during
115
+ execution, include the copyright notice for the Library among
116
+ these notices, as well as a reference directing the user to the
117
+ copies of the GNU GPL and this license document.
118
+
119
+ d) Do one of the following:
120
+
121
+ 0) Convey the Minimal Corresponding Source under the terms of this
122
+ License, and the Corresponding Application Code in a form
123
+ suitable for, and under terms that permit, the user to
124
+ recombine or relink the Application with a modified version of
125
+ the Linked Version to produce a modified Combined Work, in the
126
+ manner specified by section 6 of the GNU GPL for conveying
127
+ Corresponding Source.
128
+
129
+ 1) Use a suitable shared library mechanism for linking with the
130
+ Library. A suitable mechanism is one that (a) uses at run time
131
+ a copy of the Library already present on the user's computer
132
+ system, and (b) will operate properly with a modified version
133
+ of the Library that is interface-compatible with the Linked
134
+ Version.
135
+
136
+ e) Provide Installation Information, but only if you would otherwise
137
+ be required to provide such information under section 6 of the
138
+ GNU GPL, and only to the extent that such information is
139
+ necessary to install and execute a modified version of the
140
+ Combined Work produced by recombining or relinking the
141
+ Application with a modified version of the Linked Version. (If
142
+ you use option 4d0, the Installation Information must accompany
143
+ the Minimal Corresponding Source and Corresponding Application
144
+ Code. If you use option 4d1, you must provide the Installation
145
+ Information in the manner specified by section 6 of the GNU GPL
146
+ for conveying Corresponding Source.)
147
+
148
+ 5. Combined Libraries.
149
+
150
+ You may place library facilities that are a work based on the
151
+ Library side by side in a single library together with other library
152
+ facilities that are not Applications and are not covered by this
153
+ License, and convey such a combined library under terms of your
154
+ choice, if you do both of the following:
155
+
156
+ a) Accompany the combined library with a copy of the same work based
157
+ on the Library, uncombined with any other library facilities,
158
+ conveyed under the terms of this License.
159
+
160
+ b) Give prominent notice with the combined library that part of it
161
+ is a work based on the Library, and explaining where to find the
162
+ accompanying uncombined form of the same work.
163
+
164
+ 6. Revised Versions of the GNU Lesser General Public License.
165
+
166
+ The Free Software Foundation may publish revised and/or new versions
167
+ of the GNU Lesser General Public License from time to time. Such new
168
+ versions will be similar in spirit to the present version, but may
169
+ differ in detail to address new problems or concerns.
170
+
171
+ Each version is given a distinguishing version number. If the
172
+ Library as you received it specifies that a certain numbered version
173
+ of the GNU Lesser General Public License "or any later version"
174
+ applies to it, you have the option of following the terms and
175
+ conditions either of that published version or of any later version
176
+ published by the Free Software Foundation. If the Library as you
177
+ received it does not specify a version number of the GNU Lesser
178
+ General Public License, you may choose any version of the GNU Lesser
179
+ General Public License ever published by the Free Software Foundation.
180
+
181
+ If the Library as you received it specifies that a proxy can decide
182
+ whether future versions of the GNU Lesser General Public License shall
183
+ apply, that proxy's public statement of acceptance of any version is
184
+ permanent authorization for you to choose that version for the
185
+ Library.
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # RubyQt6-RSpec
2
+
3
+ RSpec for RubyQt6.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ GEMSPEC = Gem::Specification.load("rspec.gemspec")
5
+
6
+ require "rubocop/rake_task"
7
+ RuboCop::RakeTask.new
8
+
9
+ require "rspec/core/rake_task"
10
+ RSpec::Core::RakeTask.new(:spec)
11
+
12
+ task default: %i[spec]
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyQt6
4
+ module RSpec
5
+ class BandoFileParser
6
+ class MissingLine < StandardError
7
+ def initialize(expected, got)
8
+ super("Missing line: expected '#{expected}', but got '#{got}'")
9
+ end
10
+ end
11
+
12
+ def initialize(cppfile, qmod)
13
+ @qmod = qmod
14
+ @bandoes = []
15
+ @lines, @lineno = File.read(cppfile).lines, 0
16
+ end
17
+
18
+ def parse
19
+ parse_bando_variants_declaration
20
+ parse_bando_definitions
21
+ raise MissingLine.new("}", line) unless line == "}"
22
+ @bandoes
23
+ end
24
+
25
+ def parse_bando_variants_declaration
26
+ while line == "" || line.start_with?("#include") || line.start_with?("using ") || line.start_with?("RICE4RUBYQT6_USE_NAMESPACE")
27
+ matched = line.match(/^using Bando_(\w+) = Bando(\w+)<(\w+), (.*)>/)
28
+ if matched.nil?
29
+ take_next_line
30
+ next
31
+ end
32
+
33
+ if matched[1] != matched[3]
34
+ expected = "using Bando_#{matched[1]} = Bando#{matched[2]}<#{matched[1]}, ..."
35
+ raise MissingLine.new(expected, line)
36
+ else
37
+ take_next_line
38
+ end
39
+
40
+ @bandoes << Struct.new(:name, :template, :constructor_args).new(matched[1], matched[2], matched[4])
41
+ end
42
+
43
+ @bandoes.each do |bando|
44
+ expected = "Class rb_mBando_c#{bando.name};"
45
+ if line == expected
46
+ take_next_line
47
+ else
48
+ raise MissingLine.new(expected, line)
49
+ end
50
+ end
51
+
52
+ while line == "" || line.start_with?("void Init_bando_q") || line == "{"
53
+ take_next_line
54
+ end
55
+ end
56
+
57
+ def parse_bando_definitions
58
+ @bandoes.each do |bando|
59
+ parse_bando_definition(bando)
60
+ end
61
+ end
62
+
63
+ def parse_bando_definition(bando)
64
+ name = bando.name
65
+
66
+ expected = "rb_mBando_c#{name} ="
67
+ if line == expected
68
+ take_next_line
69
+ else
70
+ raise MissingLine.new(expected, line)
71
+ end
72
+
73
+ expected = "define_bando_#{bando.template.downcase}_under<Bando_#{name}, #{name}>(rb_mQt6Bando, \"#{name}\")"
74
+ if line == expected
75
+ take_next_line
76
+ else
77
+ raise MissingLine.new(expected, line)
78
+ end
79
+
80
+ expected = ".define_constructor(Constructor<Bando_#{name}, #{bando.constructor_args}>()"
81
+ if line.start_with?(expected)
82
+ take_next_line
83
+ else
84
+ raise MissingLine.new(expected, line)
85
+ end
86
+
87
+ while line == "" || line == "}"
88
+ return if line == "}"
89
+ take_next_line
90
+ end
91
+ end
92
+
93
+ def take_next_line
94
+ @lineno += 1
95
+ end
96
+
97
+ def line
98
+ @lines[@lineno].strip
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,264 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyQt6
4
+ module RSpec
5
+ class QlassFileParser
6
+ NESTED_QLASSES = [
7
+ "QMetaObjectConnection", # QtCore::QMetaObject::Connection
8
+ "QPainterPathElement", # QtGui::QPainterPath::Element
9
+ "QTextLayoutFormatRange", # QtGui::QTextLayout::FormatRange
10
+ "QFormLayoutTakeRowResult", # QtWidgets::QFormLayout::TakeRowResult
11
+ "QTextEditExtraSelection", # QtWidgets::QTextEdit::ExtraSelection
12
+ "QQmlContextPropertyPair", # QtQml::QQmlContext::PropertyPair
13
+ "QWebEngineCookieStoreFilterRequest" # QtWebEngineCore::QWebEngineCookieStore::FilterRequest
14
+ ]
15
+
16
+ class MissingLine < StandardError
17
+ def initialize(expected, got)
18
+ super("Missing line: expected '#{expected}', but got '#{got}'")
19
+ end
20
+ end
21
+
22
+ def initialize(cppfile, qmod)
23
+ @qmod = qmod
24
+ @qlasses = []
25
+ @lines, @lineno = File.read(cppfile).lines, 0
26
+ end
27
+
28
+ def parse
29
+ parse_qlass_variants_declaration
30
+ parse_qlass_definitions
31
+ raise MissingLine.new("}", line) unless line == "}"
32
+ @qlasses
33
+ end
34
+
35
+ def parse_qlass_variants_declaration
36
+ while line == "" || line.start_with?("#include") || line == "RICE4RUBYQT6_USE_NAMESPACE"
37
+ take_next_line
38
+ end
39
+
40
+ while (matched = line.match(/^Class rb_c(\w+)/))
41
+ @qlasses << Struct.new(:name, :methods, :enums, :flags).new(matched[1], [], [], [])
42
+ take_next_line
43
+ end
44
+
45
+ if @qlasses.length.zero?
46
+ raise MissingLine.new("Class rb_c...", line)
47
+ end
48
+
49
+ until line.start_with?("void Init_q")
50
+ take_next_line
51
+ end
52
+
53
+ while line == "" || line.start_with?("void Init_q") || line == "{"
54
+ take_next_line
55
+ end
56
+ end
57
+
58
+ def parse_qlass_definitions
59
+ @qlasses.each do |qlass|
60
+ if NESTED_QLASSES.include?(qlass.name)
61
+ take_next_line until line == "" || line == "}"
62
+ next
63
+ end
64
+ parse_qlass_definition(qlass)
65
+ end
66
+ end
67
+
68
+ def parse_qlass_definition(qlass)
69
+ qmod_name = @qmod.name
70
+ name = qlass.name
71
+
72
+ expected = "rb_c#{name} ="
73
+ if line == expected
74
+ take_next_line
75
+ else
76
+ raise MissingLine.new(expected, line)
77
+ end
78
+
79
+ expected = "// RubyQt6::#{qmod_name}::#{name}"
80
+ if line == expected
81
+ take_next_line
82
+ else
83
+ raise MissingLine.new(expected, line)
84
+ end
85
+
86
+ if line.start_with?(/define_class_under<#{name}.*rb_mQt6#{qmod_name}, "#{name}"/)
87
+ take_next_line
88
+ else
89
+ raise MissingLine.new("define_class_under<#{name}...", line)
90
+ end
91
+
92
+ loop do
93
+ case line
94
+ when /\/\/ RubyQt6-Defined Functions/
95
+ qlass.methods.concat parse_qlass_definition_methods(qlass, :rubyqt6_defined_functions)
96
+ when /\/\/ Constructor/
97
+ qlass.methods.concat parse_qlass_definition_methods(qlass, :constructor)
98
+ when /\/\/ Inherits/
99
+ qlass.methods.concat parse_qlass_definition_methods(qlass, :inherits)
100
+ when /\/\/ Public Functions/
101
+ qlass.methods.concat parse_qlass_definition_methods(qlass, :public_functions)
102
+ when /\/\/ Public Slots/
103
+ qlass.methods.concat parse_qlass_definition_methods(qlass, :public_slots)
104
+ when /\/\/ Signals/
105
+ qlass.methods.concat parse_qlass_definition_methods(qlass, :signals)
106
+ when /\/\/ Static Public Members/
107
+ qlass.methods.concat parse_qlass_definition_methods(qlass, :static_public_members)
108
+ when /.define_attr/
109
+ take_next_line
110
+ next
111
+ when "", "}"
112
+ break
113
+ else
114
+ raise MissingLine.new("// Constructor", line)
115
+ end
116
+ end
117
+
118
+ while line == "" || line == "}"
119
+ return if line == "}"
120
+ take_next_line
121
+ end
122
+
123
+ while (matched = line.match(/^Data_Type<(.*)rb_c#{name}(.*) =/))
124
+ break if matched[1].start_with?("QFlags")
125
+ enum = Struct.new(:name).new(matched[2])
126
+ qlass.enums << enum
127
+ parse_qlass_definition_enum(qlass, enum)
128
+ end
129
+
130
+ while line == "" || line == "}"
131
+ return if line == "}"
132
+ take_next_line
133
+ end
134
+
135
+ while (matched = line.match(/^Data_Type<QFlags.*rb_c#{name}(.*) =/))
136
+ flag = Struct.new(:name, :enum_name).new(matched[1], "")
137
+ qlass.flags << flag
138
+ parse_qlass_definition_flag(qlass, flag)
139
+ end
140
+ end
141
+
142
+ def parse_qlass_definition_methods(qlass, type)
143
+ [].tap do |methods|
144
+ loop do
145
+ take_next_line
146
+ break if line.start_with?(/\/\/ (RubyQt6|Constructor|Inherits|Public|Signals|Static)/) || line == "" || line == "}"
147
+
148
+ if type == :signals
149
+ raise MissingLine.new("// .define_...", line) unless line.start_with?("// .define_")
150
+ methods << parse_qlass_definition_method(line[3..], qlass, type)
151
+ next
152
+ end
153
+
154
+ if line.start_with?("// .define_")
155
+ next
156
+ elsif line.start_with?(".define_")
157
+ methods << parse_qlass_definition_method(line, qlass, type)
158
+ else
159
+ raise MissingLine.new(".define_...", line)
160
+ end
161
+ end
162
+ end
163
+ end
164
+
165
+ def parse_qlass_definition_method(line, qlass, type)
166
+ rawline = line
167
+ line = line.sub(".define_constructor", "")
168
+ line = line.sub(".define_singleton_function", "")
169
+ line = line.sub(".define_method", "")
170
+ case line
171
+ when /Constructor<#{qlass.name}.*>/
172
+ rbname = "initialize"
173
+ when /(<.*>)?\("([\w?]+)", \[\]\(/
174
+ rbname = $2
175
+ when /(<.*>)?\("([\w?]+)", [A-Z]/
176
+ rbname = $2
177
+ when /(<.*>)?\("([\w?]+)", &#{qlass.name}::([a-zA-Z0-9_]+)/
178
+ rbname = $2
179
+ cppname = $3
180
+ when /(<.*>)?\("(\W+)", \[\]/
181
+ rbname = $2
182
+ when /(<.*>)?\("(\W+)", [A-Z]/
183
+ rbname = $2
184
+ when /(<.*>)?\("(\W+)", &#{qlass.name}::operator/
185
+ rbname = $2
186
+ else
187
+ raise "Invalid method line: #{line}"
188
+ end
189
+ Struct.new(:type, :rbname, :cppname, :rawline).new(type, rbname, cppname, rawline)
190
+ end
191
+
192
+ def parse_qlass_definition_enum(qlass, enum)
193
+ qmod_name = @qmod.name
194
+ name = qlass.name
195
+ enum_name = enum.name
196
+
197
+ expected = "Data_Type<#{name}::#{enum_name}> rb_c#{name}#{enum_name} ="
198
+ if line == expected
199
+ take_next_line
200
+ else
201
+ raise MissingLine.new(expected, line)
202
+ end
203
+
204
+ expected = "// RubyQt6::#{qmod_name}::#{name}::#{enum_name}"
205
+ if line == expected
206
+ take_next_line
207
+ else
208
+ raise MissingLine.new(expected, line)
209
+ end
210
+
211
+ expected = "define_qenum_under<#{name}::#{enum_name}>(rb_c#{name}, \"#{enum_name}\");"
212
+ if line == expected
213
+ take_next_line
214
+ else
215
+ raise MissingLine.new(expected, line)
216
+ end
217
+
218
+ while line == "" || line.start_with?("define_qenum_value_under")
219
+ take_next_line
220
+ end
221
+ end
222
+
223
+ def parse_qlass_definition_flag(qlass, flag)
224
+ qmod_name = @qmod.name
225
+ name = qlass.name
226
+ flag_name = flag.name
227
+
228
+ expected = /Data_Type<QFlags<#{name}::(.*)>> rb_c#{name}#{flag_name} =/
229
+ if (matched = line.match(expected))
230
+ flag.enum_name = matched[1]
231
+ take_next_line
232
+ else
233
+ raise MissingLine.new(expected, line)
234
+ end
235
+
236
+ expected = "// RubyQt6::#{qmod_name}::#{name}::#{flag_name}"
237
+ if line == expected
238
+ take_next_line
239
+ else
240
+ raise MissingLine.new(expected, line)
241
+ end
242
+
243
+ expected = "define_qflags_under<#{name}::#{flag.enum_name}>(rb_c#{name}, \"#{flag_name}\");"
244
+ if line == expected
245
+ take_next_line
246
+ else
247
+ raise MissingLine.new(expected, line)
248
+ end
249
+
250
+ while line == ""
251
+ take_next_line
252
+ end
253
+ end
254
+
255
+ def take_next_line
256
+ @lineno += 1
257
+ end
258
+
259
+ def line
260
+ @lines[@lineno].strip
261
+ end
262
+ end
263
+ end
264
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyQt6
4
+ module RSpec
5
+ RSPEC_RUBYGEM_VERSION = "2.0.0"
6
+ end
7
+ end
data/lib/qt6/rspec.rb ADDED
@@ -0,0 +1,288 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "rspec/bando_file_parser"
4
+ require_relative "rspec/qlass_file_parser"
5
+ require_relative "rspec/version"
6
+
7
+ module RubyQt6
8
+ module RSpec
9
+ VERIFY_QLASS_VIRTUAL_METHODS = [
10
+ "event", "event_filter", # QObject
11
+ "meta_object", # QObject
12
+ "connect_notify", "disconnect_notify", # QObject
13
+ "paint_engine", # QPaintDevice
14
+ "metric", # QPaintDevice
15
+ "has_height_for_width", "height_for_width", # QWidget
16
+ "input_method_query", # QWidget
17
+ "minimum_size_hint", "size_hint", # QWidget
18
+ "init_painter", # QWidget
19
+ "maximum_size", "minimum_size", # QLayoutItem
20
+ "clone", "swap" #
21
+ ]
22
+
23
+ NO_VERIFY_QLASS_DOCS = [
24
+ "QMetaMethodBuilder",
25
+ "QMetaObjectBuilder"
26
+ ]
27
+ NO_VERIFY_QLASS_INITIALIZE = QlassFileParser::NESTED_QLASSES + [
28
+ "QVariant"
29
+ ]
30
+ NO_VERIFY_QLASS_VIRTUAL_METHODS = {
31
+ "QCoreApplication" => ["post_event", "send_event"],
32
+ "QLayoutItem" => ["has_height_for_width", "height_for_width", "maximum_size", "minimum_size", "size_hint"],
33
+ "QLayout" => ["maximum_size", "minimum_size"],
34
+ "QWidget" => ["maximum_size", "minimum_size", "minimum_size_hint", "size_hint"],
35
+ "QWindow" => ["maximum_size", "minimum_size"]
36
+ }
37
+ NO_VERIFY_QLASS_LEADING_UNDERSCORE_METHODS = {
38
+ "QObject" => ["_connect", "_disconnect"],
39
+ "QApplication" => ["_all_widgets", "_top_level_widgets"]
40
+ }
41
+ NO_VERIFY_QLASS_OPERATOR_METHODS = {
42
+ "QByteArray" => ["[]"],
43
+ "QString" => ["[]", "[]="],
44
+ "QPoint" => ["*", "+", "-", "/", "+@", "-@"],
45
+ "QPointF" => ["*", "+", "-", "/", "+@", "-@"],
46
+ "QRect" => ["+", "-"],
47
+ "QRectF" => ["+", "-"],
48
+ "QSize" => ["*", "+", "-", "/"],
49
+ "QSizeF" => ["*", "+", "-", "/"],
50
+ "QTextBlock" => ["==", "!=", "<"],
51
+ "QTextStream" => ["<<"]
52
+ }
53
+ NO_VERIFY_QLASS_QOBJECT_INITIALIZE = [
54
+ "QCoreApplication",
55
+ "QGuiApplication",
56
+ "QApplication",
57
+ "QSettings",
58
+ "QAction",
59
+ "QDoubleValidator",
60
+ "QIntValidator",
61
+ "QRegularExpressionValidator",
62
+ "QGraphicsTextItem",
63
+ "QLabel",
64
+ "QPushButton",
65
+ "QRadioButton",
66
+ "QLineEdit",
67
+ "QTextEdit",
68
+ "QToolBar",
69
+ "QSystemTrayIcon",
70
+ "QWebEnginePage",
71
+ "QWebEngineView"
72
+ ]
73
+
74
+ ACRONYM = [
75
+ "UInt",
76
+ "ULongLong",
77
+ "ULong",
78
+ "UShort",
79
+ "LongLong",
80
+ "MSecs",
81
+ "QBitmap",
82
+ "QMetaObject",
83
+ "QObject"
84
+ ]
85
+
86
+ def self.inflector_underscore(str)
87
+ str = str.dup
88
+ ACRONYM.each { |acronym| str.gsub!(acronym, "_" + acronym.downcase) }
89
+ str.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
90
+ str.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
91
+ str.downcase!
92
+ str
93
+ end
94
+
95
+ def self.verify_bando_cppfile(cppfile, qmod)
96
+ parser = BandoFileParser.new(cppfile, qmod)
97
+ bandoes = parser.parse
98
+
99
+ rs = {}
100
+ bandoes.each do |bando|
101
+ r = Struct.new(:bando).new(bando)
102
+ rs[bando.name] = r
103
+
104
+ rbfile = "lib/qt6/bando/#{bando.name.downcase}.rb"
105
+ rbfile_contents = File.read(rbfile) if File.exist?(rbfile)
106
+
107
+ raise rbfile unless rbfile_contents.include?("class #{bando.name} < RubyQt6::#{qmod.name}::#{bando.name}")
108
+ raise rbfile unless rbfile_contents.match?(/Bando.define_bando_q\w+ Bando::#{bando.name}/)
109
+ end
110
+ rs
111
+ end
112
+
113
+ def self.verify_qlass_cppfile(cppfile, qmod)
114
+ parser = QlassFileParser.new(cppfile, qmod)
115
+ qlasses = parser.parse
116
+
117
+ rs = {}
118
+ qlasses.each do |qlass|
119
+ r = Struct.new(:qlass, :verified_initialize, :verified_methods_count, :verified_enums_count, :verified_flags_count).new(qlass, 0, 0, 0, 0)
120
+ rs[qlass.name] = r
121
+
122
+ rbfile = "lib/qt6/#{qmod.name.downcase}/#{qlass.name.downcase}.rb"
123
+ rbfile_contents = File.read(rbfile) if File.exist?(rbfile)
124
+
125
+ verify_qlass_cppfile_qlass_docs(qlass, cppfile, rbfile, rbfile_contents, r)
126
+ verify_qlass_cppfile_qlass_initialize(qlass, cppfile, rbfile, rbfile_contents, r)
127
+ verify_qlass_cppfile_qlass_methods(qlass, cppfile, rbfile, rbfile_contents, r)
128
+ verify_qlass_cppfile_qlass_enums(qlass, cppfile, rbfile, rbfile_contents, r)
129
+ verify_qlass_cppfile_qlass_flags(qlass, cppfile, rbfile, rbfile_contents, r)
130
+
131
+ qobject = true if rbfile_contents&.include?("q_object")
132
+ verify_qlass_cppfile_qlass_qobject_initialize(qlass, cppfile, rbfile, rbfile_contents, r) if qobject
133
+ verify_qlass_cppfile_qlass_qobject_methods(qlass, cppfile, rbfile, rbfile_contents, r) if qobject
134
+ end
135
+ rs
136
+ end
137
+
138
+ def self.verify_qlass_cppfile_qlass_docs(qlass, cppfile, rbfile, rbfile_contents, r)
139
+ return if NO_VERIFY_QLASS_DOCS.include?(qlass.name)
140
+
141
+ return if rbfile_contents.nil?
142
+ return if rbfile_contents.include?("# @see https://doc.qt.io/qt-6/#{qlass.name.downcase}.html")
143
+ raise "#{rbfile}: docs: Missing `# @see https://doc.qt.io/qt-6/...`"
144
+ end
145
+
146
+ def self.verify_qlass_cppfile_qlass_initialize(qlass, cppfile, rbfile, rbfile_contents, r)
147
+ return if NO_VERIFY_QLASS_INITIALIZE.include?(qlass.name)
148
+
149
+ constructor_methods = qlass.methods.select { |method| method.type == :constructor }
150
+ copy_constructor_method = constructor_methods.find { |method| method.rawline.include?('Arg("other")') }
151
+
152
+ constructor_methods.each do |method|
153
+ rawline = method.rawline
154
+ raise "#{cppfile}: Found default value in constructor method" if rawline.include?("nullptr")
155
+ raise "#{cppfile}: Found default value in constructor method" if rawline.include?("static_cast")
156
+ end
157
+
158
+ constructor_methods_count = constructor_methods.count
159
+ constructor_methods_count -= 1 if copy_constructor_method
160
+ case constructor_methods_count
161
+ when 2..99
162
+ raise "#{rbfile}: initialize: Missing `# @overload initialize...`" unless rbfile_contents.scan("# @overload initialize").count == constructor_methods_count
163
+ raise "#{rbfile}: initialize: Missing `alias_method :_initialize, :initialize`" unless rbfile_contents.include?("alias_method :_initialize, :initialize")
164
+ raise "#{rbfile}: initialize: Missing `def initialize(*args)`" unless rbfile_contents.include?("def initialize(*args)")
165
+ raise "#{rbfile}: initialize: Missing `_initialize(*args)`" unless rbfile_contents.include?("_initialize(*args)")
166
+ r.verified_initialize = 2
167
+ when 1
168
+ raise "#{rbfile}: initialize: Missing `alias_method :_initialize, :initialize`" unless rbfile_contents.include?("alias_method :_initialize, :initialize")
169
+ raise "#{rbfile}: initialize: Missing `def initialize...`" unless rbfile_contents.include?("def initialize")
170
+ raise "#{rbfile}: initialize: Missing `_initialize...`" unless rbfile_contents.include?("_initialize")
171
+ r.verified_initialize = 1
172
+ end
173
+ end
174
+
175
+ def self.verify_qlass_cppfile_qlass_methods(qlass, cppfile, rbfile, rbfile_contents, r)
176
+ qlass.methods.each do |method|
177
+ # Expected 'Arg("name")', but got 'Arg("")'
178
+ if method.rawline.include?('Arg("")')
179
+ raise method.inspect
180
+ end
181
+
182
+ # Expected 'to_qvariant', but got 'to_q_variant'
183
+ if method.rbname.include?("q_")
184
+ raise method.inspect
185
+ end
186
+
187
+ # Expected 'valid?', but got 'is_valid'
188
+ # Expected 'user_type', but got 'userType'
189
+ if method.cppname
190
+ expected =
191
+ if method.cppname.match?(/^is[A-Z]/) && method.type != :signals
192
+ "#{inflector_underscore(method.cppname)}?".sub(/^is_/, "")
193
+ else
194
+ inflector_underscore(method.cppname)
195
+ end
196
+ if expected != method.rbname.sub(/^_/, "")
197
+ raise method.inspect
198
+ end
199
+ end
200
+
201
+ # No virtual method
202
+ lambda do
203
+ return if NO_VERIFY_QLASS_VIRTUAL_METHODS[qlass.name]&.include?(method.rbname)
204
+ raise method.inspect if method.rbname.end_with?("_event")
205
+ raise method.inspect if VERIFY_QLASS_VIRTUAL_METHODS.include?(method.rbname)
206
+ end.call
207
+
208
+ # No unknonwn leading underscore method
209
+ if method.rbname.start_with?("_")
210
+ lambda do
211
+ return if method.type == :rubyqt6_defined_functions
212
+ return if rbfile_contents.match?(/def (self.)?#{method.rbname.sub(/^_/, "")}/)
213
+ return if NO_VERIFY_QLASS_LEADING_UNDERSCORE_METHODS[qlass.name]&.include?(method.rbname)
214
+ raise method.inspect
215
+ end.call
216
+ end
217
+
218
+ # No unknonwn operator method
219
+ unless method.rbname.start_with?(/_?[a-z]/)
220
+ lambda do
221
+ return if NO_VERIFY_QLASS_OPERATOR_METHODS[qlass.name]&.include?(method.rbname)
222
+ raise method.inspect
223
+ end.call
224
+ end
225
+
226
+ r.verified_methods_count ||= 0
227
+ r.verified_methods_count += 1
228
+ end
229
+ end
230
+
231
+ def self.verify_qlass_cppfile_qlass_enums(qlass, cppfile, rbfile, rbfile_contents, r)
232
+ qlass.enums.each do |enum|
233
+ raise "#{rbfile}: #{enum.name}: Missing `# @!parse class ...`" unless rbfile_contents.include?("# @!parse class #{enum.name}")
234
+ raise "#{rbfile}: #{enum.name}: Missing `rubyqt6_declare_enum_under ...`" unless rbfile_contents.include?("rubyqt6_declare_enum_under #{qlass.name}, #{qlass.name}::#{enum.name}")
235
+ r.verified_enums_count ||= 0
236
+ r.verified_enums_count += 1
237
+ end
238
+ end
239
+
240
+ def self.verify_qlass_cppfile_qlass_flags(qlass, cppfile, rbfile, rbfile_contents, r)
241
+ qlass.flags.each do |flag|
242
+ raise "#{rbfile}: #{flag.name}: Missing `# @!parse class ...`" unless rbfile_contents.include?("# @!parse class #{flag.name}")
243
+ raise "#{rbfile}: #{flag.name}: Missing `rubyqt6_declare_qflags ...`" unless rbfile_contents.include?("rubyqt6_declare_qflags #{qlass.name}::#{flag.name}, #{qlass.name}::#{flag.enum_name}")
244
+ r.verified_flags_count ||= 0
245
+ r.verified_flags_count += 1
246
+ end
247
+ end
248
+
249
+ def self.verify_qlass_cppfile_qlass_qobject_initialize(qlass, cppfile, rbfile, rbfile_contents, r)
250
+ constructor_methods = qlass.methods.select { |method| method.type == :constructor }
251
+ return if constructor_methods.size == 0
252
+ raise "#{cppfile}: Too many constructor methods" if constructor_methods.size > 1
253
+
254
+ unless NO_VERIFY_QLASS_QOBJECT_INITIALIZE.include?(qlass.name)
255
+ rawline = constructor_methods[0].rawline
256
+ rawargs = rawline.scan(/Arg\("(\w+)"\)/).map { |arg| arg[0] }
257
+ rawargs.each do |arg|
258
+ line = "@param #{arg} ["
259
+ raise "#{rbfile}: initialize: Missing `#{line}`" unless rbfile_contents.include?(line)
260
+ end
261
+
262
+ line = "@return [#{qlass.name}]"
263
+ raise "#{rbfile}: initialize: Missing `#{line}`" unless rbfile_contents.include?(line)
264
+
265
+ args = rawargs.map { |arg| "#{arg}( = .*)?" }
266
+ line = args.size.zero? ? /def initialize/ : /def initialize\(#{args.join(", ")}\)/
267
+ raise "#{rbfile}: initialize: Mismatch `#{line}`" unless rbfile_contents.match?(line)
268
+
269
+ args = rawargs.map { |arg| ".*#{arg}.*" }
270
+ line = args.size.zero? ? /_initialize/ : /_initialize\(#{args.join(", ")}\)/
271
+ raise "#{rbfile}: initialize: Mismatch `#{line}`" unless rbfile_contents.match?(line)
272
+ end
273
+ end
274
+
275
+ def self.verify_qlass_cppfile_qlass_qobject_methods(qlass, cppfile, rbfile, rbfile_contents, r)
276
+ metamethods = [].tap do |methods|
277
+ signal_methods = qlass.methods.select { |method| method.type == :signals }
278
+ signal_methods.each { |method| methods << method.cppname }
279
+ slot_methods = qlass.methods.select { |method| method.type == :public_slots }
280
+ slot_methods.each { |method| methods << method.cppname }
281
+ end.uniq
282
+
283
+ rbfile_metamethods = rbfile_contents.scan(/(signal|slot) "(.*)"/).map { |method| method[1] }
284
+ rbfile_metamethods = rbfile_metamethods.map { |method| method.split("(")[0] }.uniq
285
+ raise "#{rbfile}: q_object: Mismatch `#{rbfile_metamethods}` != `#{metamethods}`" if rbfile_metamethods != metamethods
286
+ end
287
+ end
288
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-qt6-rspec
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - John Doe
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: RSpec for RubyQt6.
13
+ email:
14
+ - johndoe@example.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - ".rspec"
20
+ - ".rubocop.yml"
21
+ - LICENSE
22
+ - README.md
23
+ - Rakefile
24
+ - lib/qt6/rspec.rb
25
+ - lib/qt6/rspec/bando_file_parser.rb
26
+ - lib/qt6/rspec/qlass_file_parser.rb
27
+ - lib/qt6/rspec/version.rb
28
+ homepage: https://github.com/souk4711/ruby-qt6
29
+ licenses: []
30
+ metadata:
31
+ homepage_uri: https://github.com/souk4711/ruby-qt6
32
+ source_code_uri: https://github.com/souk4711/ruby-qt6
33
+ changelog_uri: https://github.com/souk4711/ruby-qt6
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: 3.3.0
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubygems_version: 3.6.9
49
+ specification_version: 4
50
+ summary: RSpec for RubyQt6.
51
+ test_files: []