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
Show 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
# Struct ISO Test
if
Object
.
const_defined?
(
:Struct
)
assert
(
'Struct'
,
'15.2.18'
)
do
assert
(
'Struct'
,
'15.2.18'
)
do
Struct
.
class
==
Class
Struct
.
class
==
Class
end
end
assert
(
'Struct superclass'
,
'15.2.18.2'
)
do
assert
(
'Struct superclass'
,
'15.2.18.2'
)
do
Struct
.
superclass
==
Object
Struct
.
superclass
==
Object
end
end
assert
(
'Struct.new'
,
'15.2.18.3.1'
)
do
assert
(
'Struct.new'
,
'15.2.18.3.1'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
)
c
=
Struct
.
new
(
:m1
,
:m2
)
c
.
superclass
==
Struct
and
c
.
superclass
==
Struct
and
c
.
members
==
[
:m1
,
:m2
]
c
.
members
==
[
:m1
,
:m2
]
end
end
# Check crash bug with Struc.new and no params.
# Check crash bug with Struc.new and no params.
assert
(
'Struct.new'
,
'15.2.18.3.1'
)
do
assert
(
'Struct.new'
,
'15.2.18.3.1'
)
do
c
=
Struct
.
new
()
c
=
Struct
.
new
()
c
.
superclass
==
Struct
and
c
.
members
==
[]
c
.
superclass
==
Struct
and
c
.
members
==
[]
end
end
assert
(
'Struct#=='
,
'15.2.18.4.1'
)
do
assert
(
'Struct#=='
,
'15.2.18.4.1'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
)
c
=
Struct
.
new
(
:m1
,
:m2
)
cc1
=
c
.
new
(
1
,
2
)
cc1
=
c
.
new
(
1
,
2
)
cc2
=
c
.
new
(
1
,
2
)
cc2
=
c
.
new
(
1
,
2
)
cc1
==
cc2
cc1
==
cc2
end
end
assert
(
'Struct#[]'
,
'15.2.18.4.2'
)
do
assert
(
'Struct#[]'
,
'15.2.18.4.2'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
)
c
=
Struct
.
new
(
:m1
,
:m2
)
cc
=
c
.
new
(
1
,
2
)
cc
=
c
.
new
(
1
,
2
)
cc
[
:m1
]
==
1
and
cc
[
"m2"
]
==
2
cc
[
:m1
]
==
1
and
cc
[
"m2"
]
==
2
end
end
assert
(
'Struct#[]='
,
'15.2.18.4.3'
)
do
assert
(
'Struct#[]='
,
'15.2.18.4.3'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
)
c
=
Struct
.
new
(
:m1
,
:m2
)
cc
=
c
.
new
(
1
,
2
)
cc
=
c
.
new
(
1
,
2
)
cc
[
:m1
]
=
3
cc
[
:m1
]
=
3
cc
[
:m1
]
==
3
cc
[
:m1
]
==
3
end
end
assert
(
'Struct#each'
,
'15.2.18.4.4'
)
do
assert
(
'Struct#each'
,
'15.2.18.4.4'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
)
c
=
Struct
.
new
(
:m1
,
:m2
)
cc
=
c
.
new
(
1
,
2
)
cc
=
c
.
new
(
1
,
2
)
a
=
[]
a
=
[]
...
@@ -50,9 +49,9 @@ if Object.const_defined?(:Struct)
...
@@ -50,9 +49,9 @@ if Object.const_defined?(:Struct)
a
<<
x
a
<<
x
}
}
a
[
0
]
==
1
and
a
[
1
]
==
2
a
[
0
]
==
1
and
a
[
1
]
==
2
end
end
assert
(
'Struct#each_pair'
,
'15.2.18.4.5'
)
do
assert
(
'Struct#each_pair'
,
'15.2.18.4.5'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
)
c
=
Struct
.
new
(
:m1
,
:m2
)
cc
=
c
.
new
(
1
,
2
)
cc
=
c
.
new
(
1
,
2
)
a
=
[]
a
=
[]
...
@@ -60,21 +59,21 @@ if Object.const_defined?(:Struct)
...
@@ -60,21 +59,21 @@ if Object.const_defined?(:Struct)
a
<<
[
k
,
v
]
a
<<
[
k
,
v
]
}
}
a
[
0
]
==
[
:m1
,
1
]
and
a
[
1
]
==
[
:m2
,
2
]
a
[
0
]
==
[
:m1
,
1
]
and
a
[
1
]
==
[
:m2
,
2
]
end
end
assert
(
'Struct#members'
,
'15.2.18.4.6'
)
do
assert
(
'Struct#members'
,
'15.2.18.4.6'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
)
c
=
Struct
.
new
(
:m1
,
:m2
)
cc
=
c
.
new
(
1
,
2
)
cc
=
c
.
new
(
1
,
2
)
cc
.
members
==
[
:m1
,
:m2
]
cc
.
members
==
[
:m1
,
:m2
]
end
end
assert
(
'Struct#select'
,
'15.2.18.4.7'
)
do
assert
(
'Struct#select'
,
'15.2.18.4.7'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
)
c
=
Struct
.
new
(
:m1
,
:m2
)
cc
=
c
.
new
(
1
,
2
)
cc
=
c
.
new
(
1
,
2
)
cc
.
select
{
|
v
|
v
%
2
==
0
}
==
[
2
]
cc
.
select
{
|
v
|
v
%
2
==
0
}
==
[
2
]
end
end
assert
(
'large struct'
)
do
assert
(
'large struct'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
,
:m3
,
:m4
,
:m5
,
:m6
,
:m7
,
:m8
,
:m9
,
:m10
,
:m11
,
:m12
,
:m13
)
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
)
cc
=
c
.
new
(
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
)
assert_equal
1
,
cc
.
m1
assert_equal
1
,
cc
.
m1
...
@@ -93,24 +92,23 @@ if Object.const_defined?(:Struct)
...
@@ -93,24 +92,23 @@ if Object.const_defined?(:Struct)
assert_equal
'test'
,
cc
.
m13
assert_equal
'test'
,
cc
.
m13
assert_raise
(
NoMethodError
)
{
cc
.
m14
}
assert_raise
(
NoMethodError
)
{
cc
.
m14
}
end
end
assert
(
'wrong struct arg count'
)
do
assert
(
'wrong struct arg count'
)
do
c
=
Struct
.
new
(
:m1
)
c
=
Struct
.
new
(
:m1
)
assert_raise
ArgumentError
do
assert_raise
ArgumentError
do
cc
=
c
.
new
(
1
,
2
,
3
)
cc
=
c
.
new
(
1
,
2
,
3
)
end
end
end
end
assert
(
'struct inspect'
)
do
assert
(
'struct inspect'
)
do
c
=
Struct
.
new
(
:m1
,
:m2
,
:m3
,
:m4
,
:m5
)
c
=
Struct
.
new
(
:m1
,
:m2
,
:m3
,
:m4
,
:m5
)
cc
=
c
.
new
(
1
,
2
,
3
,
4
,
5
)
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
assert_equal
"#<struct
#{
c
.
inspect
}
m1=1, m2=2, m3=3, m4=4, m5=5>"
,
cc
.
inspect
end
end
assert
(
'Struct#length, Struct#size'
)
do
assert
(
'Struct#length, Struct#size'
)
do
s
=
Struct
.
new
(
:f1
,
:f2
).
new
(
0
,
1
)
s
=
Struct
.
new
(
:f1
,
:f2
).
new
(
0
,
1
)
assert_equal
2
,
s
.
size
assert_equal
2
,
s
.
size
assert_equal
2
,
s
.
length
assert_equal
2
,
s
.
length
end
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