Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
f092c8df
Commit
f092c8df
authored
Jun 15, 2013
by
Daniel Bovensiepen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve Module Tests
parent
4bd527ce
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
82 deletions
+87
-82
test/t/module.rb
test/t/module.rb
+87
-82
No files found.
test/t/module.rb
View file @
f092c8df
...
@@ -2,11 +2,11 @@
...
@@ -2,11 +2,11 @@
# Module ISO Test
# Module ISO Test
assert
(
'Module'
,
'15.2.2'
)
do
assert
(
'Module'
,
'15.2.2'
)
do
Module
.
class
==
Class
assert_equal
Module
.
class
,
Class
end
end
assert
(
'Module superclass'
,
'15.2.2.2'
)
do
assert
(
'Module superclass'
,
'15.2.2.2'
)
do
Module
.
superclass
==
Object
assert_equal
Module
.
superclass
,
Object
end
end
# TODO not implemented ATM assert('Module.constants', '15.2.2.3.1') do
# TODO not implemented ATM assert('Module.constants', '15.2.2.3.1') do
...
@@ -18,7 +18,10 @@ assert('Module#ancestors', '15.2.2.4.9') do
...
@@ -18,7 +18,10 @@ assert('Module#ancestors', '15.2.2.4.9') do
end
end
sc
=
Test4ModuleAncestors
.
singleton_class
sc
=
Test4ModuleAncestors
.
singleton_class
r
=
String
.
ancestors
r
=
String
.
ancestors
r
.
class
==
Array
and
r
.
include?
(
String
)
and
r
.
include?
(
Object
)
assert_equal
r
.
class
,
Array
assert_true
r
.
include?
(
String
)
assert_true
r
.
include?
(
Object
)
end
end
assert
(
'Module#append_features'
,
'15.2.2.4.10'
)
do
assert
(
'Module#append_features'
,
'15.2.2.4.10'
)
do
...
@@ -31,7 +34,7 @@ assert('Module#append_features', '15.2.2.4.10') do
...
@@ -31,7 +34,7 @@ assert('Module#append_features', '15.2.2.4.10') do
include
Test4AppendFeatures
include
Test4AppendFeatures
end
end
Test4AppendFeatures2
.
const_get
(
:Const4AppendFeatures2
)
==
Test4AppendFeatures2
assert_equal
Test4AppendFeatures2
.
const_get
(
:Const4AppendFeatures2
),
Test4AppendFeatures2
end
end
assert
(
'Module#class_eval'
,
'15.2.2.4.15'
)
do
assert
(
'Module#class_eval'
,
'15.2.2.4.15'
)
do
...
@@ -44,9 +47,11 @@ assert('Module#class_eval', '15.2.2.4.15') do
...
@@ -44,9 +47,11 @@ assert('Module#class_eval', '15.2.2.4.15') do
end
end
end
end
r
=
Test4ClassEval
.
instance_methods
r
=
Test4ClassEval
.
instance_methods
Test4ClassEval
.
class_eval
{
@a
}
==
11
and
Test4ClassEval
.
class_eval
{
@b
}
==
12
and
assert_equal
Test4ClassEval
.
class_eval
{
@a
},
11
r
.
class
==
Array
and
r
.
include?
(
:method1
)
assert_equal
Test4ClassEval
.
class_eval
{
@b
},
12
assert_equal
r
.
class
,
Array
assert_true
r
.
include?
(
:method1
)
end
end
assert
(
'Module#class_variable_defined?'
,
'15.2.2.4.16'
)
do
assert
(
'Module#class_variable_defined?'
,
'15.2.2.4.16'
)
do
...
@@ -54,8 +59,8 @@ assert('Module#class_variable_defined?', '15.2.2.4.16') do
...
@@ -54,8 +59,8 @@ assert('Module#class_variable_defined?', '15.2.2.4.16') do
@@cv
=
99
@@cv
=
99
end
end
Test4ClassVariableDefined
.
class_variable_defined?
(
:@@cv
)
and
assert_true
Test4ClassVariableDefined
.
class_variable_defined?
(
:@@cv
)
not
Test4ClassVariableDefined
.
class_variable_defined?
(
:@@noexisting
)
assert_false
Test4ClassVariableDefined
.
class_variable_defined?
(
:@@noexisting
)
end
end
assert
(
'Module#class_variable_get'
,
'15.2.2.4.17'
)
do
assert
(
'Module#class_variable_get'
,
'15.2.2.4.17'
)
do
...
@@ -63,7 +68,7 @@ assert('Module#class_variable_get', '15.2.2.4.17') do
...
@@ -63,7 +68,7 @@ assert('Module#class_variable_get', '15.2.2.4.17') do
@@cv
=
99
@@cv
=
99
end
end
Test4ClassVariableGet
.
class_variable_get
(
:@@cv
)
==
99
assert_equal
Test4ClassVariableGet
.
class_variable_get
(
:@@cv
),
99
end
end
assert
(
'Module#class_variable_set'
,
'15.2.2.4.18'
)
do
assert
(
'Module#class_variable_set'
,
'15.2.2.4.18'
)
do
...
@@ -74,12 +79,11 @@ assert('Module#class_variable_set', '15.2.2.4.18') do
...
@@ -74,12 +79,11 @@ assert('Module#class_variable_set', '15.2.2.4.18') do
end
end
end
end
Test4ClassVariableSet
.
class_variable_set
(
:@@cv
,
99
)
assert_true
Test4ClassVariableSet
.
class_variable_set
(
:@@cv
,
99
)
Test4ClassVariableSet
.
class_variable_set
(
:@@foo
,
101
)
assert_true
Test4ClassVariableSet
.
class_variable_set
(
:@@foo
,
101
)
assert_true
Test4ClassVariableSet
.
class_variables
.
include?
:@@cv
Test4ClassVariableSet
.
class_variables
.
include?
:@@cv
and
assert_equal
Test4ClassVariableSet
.
class_variable_get
(
:@@cv
),
99
Test4ClassVariableSet
.
class_variable_get
(
:@@cv
)
==
99
and
assert_equal
Test4ClassVariableSet
.
new
.
foo
,
101
Test4ClassVariableSet
.
new
.
foo
==
101
end
end
assert
(
'Module#class_variables'
,
'15.2.2.4.19'
)
do
assert
(
'Module#class_variables'
,
'15.2.2.4.19'
)
do
...
@@ -90,8 +94,8 @@ assert('Module#class_variables', '15.2.2.4.19') do
...
@@ -90,8 +94,8 @@ assert('Module#class_variables', '15.2.2.4.19') do
@@var2
=
2
@@var2
=
2
end
end
Test4ClassVariables1
.
class_variables
==
[
:@@var1
]
&&
assert_equal
Test4ClassVariables1
.
class_variables
,
[
:@@var1
]
Test4ClassVariables2
.
class_variables
==
[
:@@var2
,
:@@var1
]
assert_equal
Test4ClassVariables2
.
class_variables
,
[
:@@var2
,
:@@var1
]
end
end
assert
(
'Module#const_defined?'
,
'15.2.2.4.20'
)
do
assert
(
'Module#const_defined?'
,
'15.2.2.4.20'
)
do
...
@@ -99,8 +103,8 @@ assert('Module#const_defined?', '15.2.2.4.20') do
...
@@ -99,8 +103,8 @@ assert('Module#const_defined?', '15.2.2.4.20') do
Const4Test4ConstDefined
=
true
Const4Test4ConstDefined
=
true
end
end
Test4ConstDefined
.
const_defined?
(
:Const4Test4ConstDefined
)
and
assert_true
Test4ConstDefined
.
const_defined?
(
:Const4Test4ConstDefined
)
not
Test4ConstDefined
.
const_defined?
(
:NotExisting
)
assert_false
Test4ConstDefined
.
const_defined?
(
:NotExisting
)
end
end
assert
(
'Module#const_get'
,
'15.2.2.4.21'
)
do
assert
(
'Module#const_get'
,
'15.2.2.4.21'
)
do
...
@@ -108,7 +112,7 @@ assert('Module#const_get', '15.2.2.4.21') do
...
@@ -108,7 +112,7 @@ assert('Module#const_get', '15.2.2.4.21') do
Const4Test4ConstGet
=
42
Const4Test4ConstGet
=
42
end
end
Test4ConstGet
.
const_get
(
:Const4Test4ConstGet
)
==
42
assert_equal
Test4ConstGet
.
const_get
(
:Const4Test4ConstGet
),
42
end
end
assert
(
'Module.const_missing'
,
'15.2.2.4.22'
)
do
assert
(
'Module.const_missing'
,
'15.2.2.4.22'
)
do
...
@@ -118,7 +122,7 @@ assert('Module.const_missing', '15.2.2.4.22') do
...
@@ -118,7 +122,7 @@ assert('Module.const_missing', '15.2.2.4.22') do
end
end
end
end
Test4ConstMissing
.
const_get
(
:ConstDoesntExist
)
==
42
assert_equal
Test4ConstMissing
.
const_get
(
:ConstDoesntExist
),
42
end
end
assert
(
'Module#const_get'
,
'15.2.2.4.23'
)
do
assert
(
'Module#const_get'
,
'15.2.2.4.23'
)
do
...
@@ -126,8 +130,8 @@ assert('Module#const_get', '15.2.2.4.23') do
...
@@ -126,8 +130,8 @@ assert('Module#const_get', '15.2.2.4.23') do
Const4Test4ConstSet
=
42
Const4Test4ConstSet
=
42
end
end
Test4ConstSet
.
const_set
(
:Const4Test4ConstSet
,
23
)
assert_true
Test4ConstSet
.
const_set
(
:Const4Test4ConstSet
,
23
)
Test4ConstSet
.
const_get
(
:Const4Test4ConstSet
)
==
23
assert_equal
Test4ConstSet
.
const_get
(
:Const4Test4ConstSet
),
23
end
end
assert
(
'Module.constants'
,
'15.2.2.4.24'
)
do
assert
(
'Module.constants'
,
'15.2.2.4.24'
)
do
...
@@ -141,8 +145,8 @@ assert('Module.constants', '15.2.2.4.24') do
...
@@ -141,8 +145,8 @@ assert('Module.constants', '15.2.2.4.24') do
$n
=
constants
.
sort
$n
=
constants
.
sort
end
end
TestA
.
constants
==
[
:Const
]
and
assert_equal
TestA
.
constants
,
[
:Const
]
$n
==
[
:Const
,
:Const2
]
assert_equal
$n
,
[
:Const
,
:Const2
]
end
end
assert
(
'Module#include'
,
'15.2.2.4.27'
)
do
assert
(
'Module#include'
,
'15.2.2.4.27'
)
do
...
@@ -153,7 +157,7 @@ assert('Module#include', '15.2.2.4.27') do
...
@@ -153,7 +157,7 @@ assert('Module#include', '15.2.2.4.27') do
include
Test4Include
include
Test4Include
end
end
Test4Include2
.
const_get
(
:Const4Include
)
==
42
assert_equal
Test4Include2
.
const_get
(
:Const4Include
),
42
end
end
assert
(
'Module#include?'
,
'15.2.2.4.28'
)
do
assert
(
'Module#include?'
,
'15.2.2.4.28'
)
do
...
@@ -165,9 +169,9 @@ assert('Module#include?', '15.2.2.4.28') do
...
@@ -165,9 +169,9 @@ assert('Module#include?', '15.2.2.4.28') do
class
Test4IncludeP3
<
Test4IncludeP2
class
Test4IncludeP3
<
Test4IncludeP2
end
end
Test4IncludeP2
.
include?
(
Test4IncludeP
)
&&
assert_true
Test4IncludeP2
.
include?
(
Test4IncludeP
)
Test4IncludeP3
.
include?
(
Test4IncludeP
)
&&
assert_true
Test4IncludeP3
.
include?
(
Test4IncludeP
)
!
Test4IncludeP
.
include?
(
Test4IncludeP
)
assert_false
Test4IncludeP
.
include?
(
Test4IncludeP
)
end
end
assert
(
'Module#included'
,
'15.2.2.4.29'
)
do
assert
(
'Module#included'
,
'15.2.2.4.29'
)
do
...
@@ -181,8 +185,8 @@ assert('Module#included', '15.2.2.4.29') do
...
@@ -181,8 +185,8 @@ assert('Module#included', '15.2.2.4.29') do
include
Test4Included
include
Test4Included
end
end
Test4Included2
.
const_get
(
:Const4Included
)
==
42
and
assert_equal
Test4Included2
.
const_get
(
:Const4Included
),
42
Test4Included2
.
const_get
(
:Const4Included2
)
==
Test4Included2
assert_equal
Test4Included2
.
const_get
(
:Const4Included2
),
Test4Included2
end
end
assert
(
'Module#included_modules'
,
'15.2.2.4.30'
)
do
assert
(
'Module#included_modules'
,
'15.2.2.4.30'
)
do
...
@@ -191,28 +195,31 @@ assert('Module#included_modules', '15.2.2.4.30') do
...
@@ -191,28 +195,31 @@ assert('Module#included_modules', '15.2.2.4.30') do
module
Test4includedModules2
module
Test4includedModules2
include
Test4includedModules
include
Test4includedModules
end
end
r
=
Test4includedModules2
.
included_modules
r
=
Test4includedModules2
.
included_modules
r
.
class
==
Array
and
r
.
include?
(
Test4includedModules
)
assert_equal
r
.
class
,
Array
assert_true
r
.
include?
(
Test4includedModules
)
end
end
assert
(
'Module#instance_methods'
,
'15.2.2.4.33'
)
do
assert
(
'Module#instance_methods'
,
'15.2.2.4.33'
)
do
module
Test4InstanceMethodsA
module
Test4InstanceMethodsA
def
method1
()
end
def
method1
()
end
end
end
class
Test4InstanceMethodsB
class
Test4InstanceMethodsB
def
method2
()
end
def
method2
()
end
end
end
class
Test4InstanceMethodsC
<
Test4InstanceMethodsB
class
Test4InstanceMethodsC
<
Test4InstanceMethodsB
def
method3
()
end
def
method3
()
end
end
end
r
=
Test4InstanceMethodsC
.
instance_methods
(
true
)
r
=
Test4InstanceMethodsC
.
instance_methods
(
true
)
Test4InstanceMethodsA
.
instance_methods
==
[
:method1
]
and
assert_equal
Test4InstanceMethodsA
.
instance_methods
,
[
:method1
]
Test4InstanceMethodsB
.
instance_methods
(
false
)
==
[
:method2
]
and
assert_equal
Test4InstanceMethodsB
.
instance_methods
(
false
),
[
:method2
]
Test4InstanceMethodsC
.
instance_methods
(
false
)
==
[
:method3
]
and
assert_equal
Test4InstanceMethodsC
.
instance_methods
(
false
),
[
:method3
]
r
.
class
==
Array
and
r
.
include?
(
:method3
)
and
r
.
include?
(
:method2
)
assert_equal
r
.
class
,
Array
assert_true
r
.
include?
(
:method3
)
assert_true
r
.
include?
(
:method2
)
end
end
assert
(
'Module#method_defined?'
,
'15.2.2.4.34'
)
do
assert
(
'Module#method_defined?'
,
'15.2.2.4.34'
)
do
...
@@ -231,21 +238,22 @@ assert('Module#method_defined?', '15.2.2.4.34') do
...
@@ -231,21 +238,22 @@ assert('Module#method_defined?', '15.2.2.4.34') do
end
end
end
end
Test4MethodDefined
::
A
.
method_defined?
:method1
and
assert_true
Test4MethodDefined
::
A
.
method_defined?
:method1
Test4MethodDefined
::
C
.
method_defined?
:method1
and
assert_true
Test4MethodDefined
::
C
.
method_defined?
:method1
Test4MethodDefined
::
C
.
method_defined?
"method2"
and
assert_true
Test4MethodDefined
::
C
.
method_defined?
"method2"
Test4MethodDefined
::
C
.
method_defined?
"method3"
and
assert_true
Test4MethodDefined
::
C
.
method_defined?
"method3"
not
Test4MethodDefined
::
C
.
method_defined?
"method4"
assert_false
Test4MethodDefined
::
C
.
method_defined?
"method4"
end
end
assert
(
'Module#module_eval'
,
'15.2.2.4.35'
)
do
assert
(
'Module#module_eval'
,
'15.2.2.4.35'
)
do
module
Test4ModuleEval
module
Test4ModuleEval
@a
=
11
@a
=
11
@b
=
12
@b
=
12
end
end
Test4ModuleEval
.
module_eval
{
@a
}
==
11
and
Test4ModuleEval
.
module_eval
{
@b
}
==
12
assert_equal
Test4ModuleEval
.
module_eval
{
@a
},
11
assert_equal
Test4ModuleEval
.
module_eval
{
@b
},
12
end
end
assert
(
'Module#remove_class_variable'
,
'15.2.2.4.39'
)
do
assert
(
'Module#remove_class_variable'
,
'15.2.2.4.39'
)
do
...
@@ -253,16 +261,16 @@ assert('Module#remove_class_variable', '15.2.2.4.39') do
...
@@ -253,16 +261,16 @@ assert('Module#remove_class_variable', '15.2.2.4.39') do
@@cv
=
99
@@cv
=
99
end
end
Test4RemoveClassVariable
.
remove_class_variable
(
:@@cv
)
==
99
and
assert_equal
Test4RemoveClassVariable
.
remove_class_variable
(
:@@cv
),
99
not
Test4RemoveClassVariable
.
class_variables
.
include?
:@@cv
assert_false
Test4RemoveClassVariable
.
class_variables
.
include?
:@@cv
end
end
assert
(
'Module#remove_const'
,
'15.2.2.4.40'
)
do
assert
(
'Module#remove_const'
,
'15.2.2.4.40'
)
do
module
Test4RemoveConst
module
Test4RemoveConst
ExistingConst
=
23
ExistingConst
=
23
end
end
result
=
Test4RemoveConst
.
module_eval
{
remove_const
:ExistingConst
}
result
=
Test4RemoveConst
.
module_eval
{
remove_const
:ExistingConst
}
name_error
=
false
name_error
=
false
begin
begin
...
@@ -272,11 +280,11 @@ assert('Module#remove_const', '15.2.2.4.40') do
...
@@ -272,11 +280,11 @@ assert('Module#remove_const', '15.2.2.4.40') do
end
end
# Constant removed from Module
# Constant removed from Module
not
Test4RemoveConst
.
const_defined?
:ExistingConst
and
assert_false
Test4RemoveConst
.
const_defined?
:ExistingConst
# Return value of binding
# Return value of binding
result
==
23
and
assert_equal
result
,
23
# Name Error raised when Constant doesn't exist
# Name Error raised when Constant doesn't exist
name_error
assert_true
name_error
end
end
assert
(
'Module#remove_method'
,
'15.2.2.4.41'
)
do
assert
(
'Module#remove_method'
,
'15.2.2.4.41'
)
do
...
@@ -289,13 +297,12 @@ assert('Module#remove_method', '15.2.2.4.41') do
...
@@ -289,13 +297,12 @@ assert('Module#remove_method', '15.2.2.4.41') do
class
Child
<
Parent
class
Child
<
Parent
def
hello
def
hello
end
end
end
end
end
end
Test4RemoveMethod
::
Child
.
class_eval
{
remove_method
:hello
}
assert_true
Test4RemoveMethod
::
Child
.
class_eval
{
remove_method
:hello
}
assert_true
Test4RemoveMethod
::
Child
.
instance_methods
.
include?
:hello
Test4RemoveMethod
::
Child
.
instance_methods
.
include?
:hello
and
assert_false
Test4RemoveMethod
::
Child
.
instance_methods
(
false
).
include?
:hello
not
Test4RemoveMethod
::
Child
.
instance_methods
(
false
).
include?
:hello
end
end
assert
(
'Module.undef_method'
,
'15.2.2.4.42'
)
do
assert
(
'Module.undef_method'
,
'15.2.2.4.42'
)
do
...
@@ -313,27 +320,25 @@ assert('Module.undef_method', '15.2.2.4.42') do
...
@@ -313,27 +320,25 @@ assert('Module.undef_method', '15.2.2.4.42') do
class
GrandChild
<
Child
class
GrandChild
<
Child
end
end
end
end
Test4UndefMethod
::
Child
.
class_eval
{
undef_method
:hello
}
Test4UndefMethod
::
Child
.
class_eval
{
undef_method
:hello
}
Test4UndefMethod
::
Parent
.
new
.
respond_to?
(
:hello
)
and
assert_true
Test4UndefMethod
::
Parent
.
new
.
respond_to?
(
:hello
)
not
Test4UndefMethod
::
Child
.
new
.
respond_to?
(
:hello
)
and
assert_false
Test4UndefMethod
::
Child
.
new
.
respond_to?
(
:hello
)
not
Test4UndefMethod
::
GrandChild
.
new
.
respond_to?
(
:hello
)
assert_false
Test4UndefMethod
::
GrandChild
.
new
.
respond_to?
(
:hello
)
end
end
# Not ISO specified
# Not ISO specified
assert
(
'Module#to_s'
)
do
assert
(
'Module#to_s'
)
do
module
Test4to_sModules
module
Test4to_sModules
end
end
Test4to_sModules
.
to_s
==
'Test4to_sModules'
assert_equal
Test4to_sModules
.
to_s
,
'Test4to_sModules'
end
end
assert
(
'Module#inspect'
)
do
assert
(
'Module#inspect'
)
do
module
Test4to_sModules
module
Test4to_sModules
end
end
Test4to_sModules
.
inspect
==
'Test4to_sModules'
assert_equal
Test4to_sModules
.
inspect
,
'Test4to_sModules'
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment