Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
99 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require "minitest/autorun" | ||
require "gosu" unless defined? Gosu | ||
|
||
class TestConstants < Minitest::Test | ||
def test_version | ||
assert_match(/\A#{Gosu::MAJOR_VERSION}.#{Gosu::MINOR_VERSION}.#{Gosu::POINT_VERSION}/, | ||
Gosu::VERSION) | ||
end | ||
|
||
def test_licenses | ||
assert_match(/Gosu/, Gosu::LICENSES) | ||
assert_match(/SDL/, Gosu::LICENSES) | ||
unless RUBY_PLATFORM =~ /darwin/ | ||
assert_match(/libsndfile/, Gosu::LICENSES) | ||
assert_match(/OpenAL/, Gosu::LICENSES) if RUBY_PLATFORM =~ /win/ | ||
end | ||
|
||
# Backward compatibility | ||
assert_equal Gosu::LICENSES, Gosu::GOSU_COPYRIGHT_NOTICE | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |