-
Notifications
You must be signed in to change notification settings - Fork 174
/
test_interface.rb
64 lines (53 loc) · 2 KB
/
test_interface.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require "minitest/autorun"
require "gosu" unless defined? Gosu
# Make a backup of the Gosu modules and its helpers on Numeric.
OrigGosu = Gosu
Object.send :remove_const, :Gosu
%w(gosu_to_radians radians_to_gosu degrees_to_radians radians_to_degrees).each do |helper|
Numeric.send :alias_method, :"orig_#{helper}", :"#{helper}"
Numeric.send :undef_method, :"#{helper}"
end
# Now load Gosu's documentation, a module that is only filled with method stubs, into GosuDocs.
require_relative "../rdoc/gosu.rb"
GosuDocs = Gosu
Object.send :remove_const, :Gosu
# And finally, restore the real Gosu module.
Gosu = OrigGosu
Object.send :remove_const, :OrigGosu
%w(gosu_to_radians radians_to_gosu degrees_to_radians radians_to_degrees).each do |helper|
Numeric.send :undef_method, :"#{helper}"
Numeric.send :alias_method, :"#{helper}", :"orig_#{helper}"
Numeric.send :undef_method, :"orig_#{helper}"
end
class TestInterface < Minitest::Test
def test_all_constants_exist
GosuDocs.constants.each do |constant|
assert Gosu.constants.include?(constant),
"Expected constant Gosu::#{constant}"
end
end
def test_constant_types
GosuDocs.constants.each do |constant|
case constant
when /(Kb|Gp|Ms)/, /(KB_|GP_|MS_)/, /_VERSION/
expected_class = Integer
when :VERSION, :LICENSES
expected_class = String
else
next
end
assert_kind_of expected_class, Gosu.const_get(constant),
"Gosu::#{constant} must be #{expected_class}, is #{Gosu.const_get(constant).class}"
end
end
def test_no_extra_constants
Gosu.constants.each do |constant|
next if constant =~ /KB_|GP_|MS_/ # TODO: not yet documented
next if constant == :Button # backwards compatibility
next if constant == :ImmutableColor # implementation detail
next if constant == :MAX_TEXTURE_SIZE # not sure if we still need this :/
assert GosuDocs.constants.include?(constant),
"Unexpected Gosu::#{constant}"
end
end
end