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
db6e8682
Commit
db6e8682
authored
Apr 21, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2101 from take-cheeze/struct_test
Remove `Struct` defined check in test.
parents
56e52061
30c672f8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
95 additions
and
97 deletions
+95
-97
mrbgems/mruby-struct/test/struct.rb
mrbgems/mruby-struct/test/struct.rb
+95
-97
No files found.
mrbgems/mruby-struct/test/struct.rb
View file @
db6e8682
##
# Struct ISO Test
if
Object
.
const_defined?
(
:Struct
)
assert
(
'Struct'
,
'15.2.18'
)
do
Struct
.
class
==
Class
end
assert
(
'Struct'
,
'15.2.18'
)
do
Struct
.
class
==
Class
end
assert
(
'Struct superclass'
,
'15.2.18.2'
)
do
Struct
.
superclass
==
Object
end
assert
(
'Struct superclass'
,
'15.2.18.2'
)
do
Struct
.
superclass
==
Object
end
assert
(
'Struct.new'
,
'15.2.18.3.1'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
)
c
.
superclass
==
Struct
and
c
.
members
==
[
:m1
,
:m2
]
end
assert
(
'Struct.new'
,
'15.2.18.3.1'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
)
c
.
superclass
==
Struct
and
c
.
members
==
[
:m1
,
:m2
]
end
# Check crash bug with Struc.new and no params.
assert
(
'Struct.new'
,
'15.2.18.3.1'
)
do
c
=
Struct
.
new
()
c
.
superclass
==
Struct
and
c
.
members
==
[]
end
# Check crash bug with Struc.new and no params.
assert
(
'Struct.new'
,
'15.2.18.3.1'
)
do
c
=
Struct
.
new
()
c
.
superclass
==
Struct
and
c
.
members
==
[]
end
assert
(
'Struct#=='
,
'15.2.18.4.1'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
)
cc1
=
c
.
new
(
1
,
2
)
cc2
=
c
.
new
(
1
,
2
)
cc1
==
cc2
end
assert
(
'Struct#=='
,
'15.2.18.4.1'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
)
cc1
=
c
.
new
(
1
,
2
)
cc2
=
c
.
new
(
1
,
2
)
cc1
==
cc2
end
assert
(
'Struct#[]'
,
'15.2.18.4.2'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
)
cc
=
c
.
new
(
1
,
2
)
cc
[
:m1
]
==
1
and
cc
[
"m2"
]
==
2
end
assert
(
'Struct#[]'
,
'15.2.18.4.2'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
)
cc
=
c
.
new
(
1
,
2
)
cc
[
:m1
]
==
1
and
cc
[
"m2"
]
==
2
end
assert
(
'Struct#[]='
,
'15.2.18.4.3'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
)
cc
=
c
.
new
(
1
,
2
)
cc
[
:m1
]
=
3
cc
[
:m1
]
==
3
end
assert
(
'Struct#[]='
,
'15.2.18.4.3'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
)
cc
=
c
.
new
(
1
,
2
)
cc
[
:m1
]
=
3
cc
[
:m1
]
==
3
end
assert
(
'Struct#each'
,
'15.2.18.4.4'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
)
cc
=
c
.
new
(
1
,
2
)
a
=
[]
cc
.
each
{
|
x
|
a
<<
x
}
a
[
0
]
==
1
and
a
[
1
]
==
2
end
assert
(
'Struct#each'
,
'15.2.18.4.4'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
)
cc
=
c
.
new
(
1
,
2
)
a
=
[]
cc
.
each
{
|
x
|
a
<<
x
}
a
[
0
]
==
1
and
a
[
1
]
==
2
end
assert
(
'Struct#each_pair'
,
'15.2.18.4.5'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
)
cc
=
c
.
new
(
1
,
2
)
a
=
[]
cc
.
each_pair
{
|
k
,
v
|
a
<<
[
k
,
v
]
}
a
[
0
]
==
[
:m1
,
1
]
and
a
[
1
]
==
[
:m2
,
2
]
end
assert
(
'Struct#each_pair'
,
'15.2.18.4.5'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
)
cc
=
c
.
new
(
1
,
2
)
a
=
[]
cc
.
each_pair
{
|
k
,
v
|
a
<<
[
k
,
v
]
}
a
[
0
]
==
[
:m1
,
1
]
and
a
[
1
]
==
[
:m2
,
2
]
end
assert
(
'Struct#members'
,
'15.2.18.4.6'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
)
cc
=
c
.
new
(
1
,
2
)
cc
.
members
==
[
:m1
,
:m2
]
end
assert
(
'Struct#members'
,
'15.2.18.4.6'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
)
cc
=
c
.
new
(
1
,
2
)
cc
.
members
==
[
:m1
,
:m2
]
end
assert
(
'Struct#select'
,
'15.2.18.4.7'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
)
cc
=
c
.
new
(
1
,
2
)
cc
.
select
{
|
v
|
v
%
2
==
0
}
==
[
2
]
end
assert
(
'Struct#select'
,
'15.2.18.4.7'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
)
cc
=
c
.
new
(
1
,
2
)
cc
.
select
{
|
v
|
v
%
2
==
0
}
==
[
2
]
end
assert
(
'large struct'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
,
:m3
,
:m4
,
:m5
,
:m6
,
:m7
,
:m8
,
:m9
,
:m10
,
:m11
,
:m12
,
:m13
)
cc
=
c
.
new
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
)
assert_equal
1
,
cc
.
m1
assert_equal
2
,
cc
.
m2
assert_equal
3
,
cc
.
m3
assert_equal
4
,
cc
.
m4
assert_equal
5
,
cc
.
m5
assert_equal
6
,
cc
.
m6
assert_equal
7
,
cc
.
m7
assert_equal
8
,
cc
.
m8
assert_equal
9
,
cc
.
m9
assert_equal
10
,
cc
.
m10
assert_equal
13
,
cc
.
m13
cc
.
m13
=
'test'
assert_equal
'test'
,
cc
.
m13
assert_raise
(
NoMethodError
)
{
cc
.
m14
}
end
assert
(
'large struct'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
,
:m3
,
:m4
,
:m5
,
:m6
,
:m7
,
:m8
,
:m9
,
:m10
,
:m11
,
:m12
,
:m13
)
cc
=
c
.
new
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
)
assert_equal
1
,
cc
.
m1
assert_equal
2
,
cc
.
m2
assert_equal
3
,
cc
.
m3
assert_equal
4
,
cc
.
m4
assert_equal
5
,
cc
.
m5
assert_equal
6
,
cc
.
m6
assert_equal
7
,
cc
.
m7
assert_equal
8
,
cc
.
m8
assert_equal
9
,
cc
.
m9
assert_equal
10
,
cc
.
m10
assert_equal
13
,
cc
.
m13
cc
.
m13
=
'test'
assert_equal
'test'
,
cc
.
m13
assert_raise
(
NoMethodError
)
{
cc
.
m14
}
end
assert
(
'wrong struct arg count'
)
do
c
=
Struct
.
new
(
:m1
)
assert_raise
ArgumentError
do
cc
=
c
.
new
(
1
,
2
,
3
)
end
assert
(
'wrong struct arg count'
)
do
c
=
Struct
.
new
(
:m1
)
assert_raise
ArgumentError
do
cc
=
c
.
new
(
1
,
2
,
3
)
end
end
assert
(
'struct inspect'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
,
:m3
,
:m4
,
:m5
)
cc
=
c
.
new
(
1
,
2
,
3
,
4
,
5
)
assert_equal
"#<struct
#{
c
.
inspect
}
m1=1, m2=2, m3=3, m4=4, m5=5>"
,
cc
.
inspect
end
assert
(
'struct inspect'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
,
:m3
,
:m4
,
:m5
)
cc
=
c
.
new
(
1
,
2
,
3
,
4
,
5
)
assert_equal
"#<struct
#{
c
.
inspect
}
m1=1, m2=2, m3=3, m4=4, m5=5>"
,
cc
.
inspect
end
assert
(
'Struct#length, Struct#size'
)
do
s
=
Struct
.
new
(
:f1
,
:f2
).
new
(
0
,
1
)
assert_equal
2
,
s
.
size
assert_equal
2
,
s
.
length
end
assert
(
'Struct#length, Struct#size'
)
do
s
=
Struct
.
new
(
:f1
,
:f2
).
new
(
0
,
1
)
assert_equal
2
,
s
.
size
assert_equal
2
,
s
.
length
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