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
ffc915fd
Commit
ffc915fd
authored
May 28, 2019
by
KOBAYASHI Shuji
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix missing assertions in `mruby-pack` test
parent
1727f0b7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
49 deletions
+30
-49
mrbgems/mruby-pack/test/pack.rb
mrbgems/mruby-pack/test/pack.rb
+30
-49
No files found.
mrbgems/mruby-pack/test/pack.rb
View file @
ffc915fd
PACK_IS_LITTLE_ENDIAN
=
"
\x01\00
"
.
unpack
(
'S'
)[
0
]
==
0x01
def
assert_pack
tmpl
,
packed
,
unpacked
t
=
tmpl
.
inspect
assert_equal
packed
,
unpacked
.
pack
(
tmpl
),
"
#{
unpacked
.
inspect
}
.pack(
#{
t
}
)"
assert_equal
unpacked
,
packed
.
unpack
(
tmpl
),
"
#{
packed
.
inspect
}
.unpack(
#{
t
}
)"
end
# pack & unpack 'm' (base64)
# pack & unpack 'm' (base64)
assert
(
'[""].pack("m")'
)
do
assert
(
'[""].pack("m")'
)
do
ary
=
""
assert_pack
"m"
,
""
,
[
""
]
str
=
""
[
ary
].
pack
(
"m"
)
==
str
and
str
.
unpack
(
"m"
)
==
[
ary
]
end
end
assert
(
'["\0"].pack("m")'
)
do
assert
(
'["\0"].pack("m")'
)
do
ary
=
"
\0
"
assert_pack
"m"
,
"AA==
\n
"
,
[
"
\0
"
]
str
=
"AA==
\n
"
[
ary
].
pack
(
"m"
)
==
str
and
str
.
unpack
(
"m"
)
==
[
ary
]
end
end
assert
(
'["\0\0"].pack("m")'
)
do
assert
(
'["\0\0"].pack("m")'
)
do
ary
=
"
\0\0
"
assert_pack
"m"
,
"AAA=
\n
"
,
[
"
\0\0
"
]
str
=
"AAA=
\n
"
[
ary
].
pack
(
"m"
)
==
str
and
str
.
unpack
(
"m"
)
==
[
ary
]
end
end
assert
(
'["\0\0\0"].pack("m")'
)
do
assert
(
'["\0\0\0"].pack("m")'
)
do
ary
=
"
\0\0\0
"
assert_pack
"m"
,
"AAAA
\n
"
,
[
"
\0\0\0
"
]
str
=
"AAAA
\n
"
[
ary
].
pack
(
"m"
)
==
str
and
str
.
unpack
(
"m"
)
==
[
ary
]
end
end
assert
(
'["abc..xyzABC..XYZ"].pack("m")'
)
do
assert
(
'["abc..xyzABC..XYZ"].pack("m")'
)
do
[
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
].
pack
(
"m"
)
==
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJT
\n
VFVWV1hZWg==
\n
"
assert_pack
"m"
,
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJT
\n
VFVWV1hZWg==
\n
"
,
[
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
]
end
end
assert
(
'"YWJ...".unpack("m") should "abc..xyzABC..XYZ"'
)
do
assert
(
'"YWJ...".unpack("m") should "abc..xyzABC..XYZ"'
)
do
str
=
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
ary
=
[
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
]
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJT
\n
VFVWV1hZWg==
\n
"
.
unpack
(
"m"
)
==
[
str
]
and
assert_equal
ary
,
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJT
\n
VFVWV1hZWg==
\n
"
.
unpack
(
"m"
)
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWg==
\n
"
.
unpack
(
"m"
)
==
[
str
]
assert_equal
ary
,
"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWg==
\n
"
.
unpack
(
"m"
)
end
end
# pack & unpack 'H'
# pack & unpack 'H'
assert
(
'["3031"].pack("H*")'
)
do
assert
(
'["3031"].pack("H*")'
)
do
ary
=
"3031"
assert_pack
"H*"
,
"01"
,
[
"3031"
]
str
=
"01"
[
ary
].
pack
(
"H*"
)
==
str
and
str
.
unpack
(
"H*"
)
==
[
ary
]
end
end
assert
(
'["10"].pack("H*")'
)
do
assert
(
'["10"].pack("H*")'
)
do
ary
=
"10"
assert_pack
"H*"
,
"
\020
"
,
[
"10"
]
str
=
"
\020
"
[
ary
].
pack
(
"H*"
)
==
str
and
str
.
unpack
(
"H*"
)
==
[
ary
]
end
end
assert
(
'[0,1,127,128,255].pack("C*")'
)
do
assert
(
'[0,1,127,128,255].pack("C*")'
)
do
ary
=
[
0
,
1
,
127
,
128
,
255
]
assert_pack
"C*"
,
"
\x00\x01\x7F\x80\xFF
"
,
[
0
,
1
,
127
,
128
,
255
]
str
=
"
\x00\x01\x7F\x80\xFF
"
ary
.
pack
(
"C*"
)
==
str
and
str
.
unpack
(
"C*"
)
==
ary
end
end
# pack "a"
# pack "a"
assert
(
'["abc"].pack("a")'
)
do
assert
(
'["abc"].pack("a")'
)
do
[
"abc"
].
pack
(
"a"
)
==
"a"
and
assert_equal
"a"
,
[
"abc"
].
pack
(
"a"
)
[
"abc"
].
pack
(
"a*"
)
==
"abc"
and
assert_equal
"abc"
,
[
"abc"
].
pack
(
"a*"
)
[
"abc"
].
pack
(
"a4"
)
==
"abc
\0
"
assert_equal
"abc
\0
"
,
[
"abc"
].
pack
(
"a4"
)
end
end
# upack "a"
# upack "a"
assert
(
'["abc"].pack("a")'
)
do
assert
(
'["abc"].pack("a")'
)
do
"abc
\0
"
.
unpack
(
"a4"
)
==
[
"abc
\0
"
]
and
assert_equal
[
"abc
\0
"
],
"abc
\0
"
.
unpack
(
"a4"
)
"abc "
.
unpack
(
"a4"
)
==
[
"abc "
]
assert_equal
[
"abc "
],
"abc "
.
unpack
(
"a4"
)
end
end
# pack "A"
# pack "A"
assert
(
'["abc"].pack("A")'
)
do
assert
(
'["abc"].pack("A")'
)
do
[
"abc"
].
pack
(
"A"
)
==
"a"
and
assert_equal
"a"
,
[
"abc"
].
pack
(
"A"
)
[
"abc"
].
pack
(
"A*"
)
==
"abc"
and
assert_equal
"abc"
,
[
"abc"
].
pack
(
"A*"
)
[
"abc"
].
pack
(
"A4"
)
==
"abc "
assert_equal
"abc "
,
[
"abc"
].
pack
(
"A4"
)
end
end
# upack "A"
# upack "A"
assert
(
'["abc"].pack("A")'
)
do
assert
(
'["abc"].pack("A")'
)
do
"abc
\0
"
.
unpack
(
"A4"
)
==
[
"abc"
]
and
assert_equal
[
"abc"
],
"abc
\0
"
.
unpack
(
"A4"
)
"abc "
.
unpack
(
"A4"
)
==
[
"abc"
]
assert_equal
[
"abc"
],
"abc "
.
unpack
(
"A4"
)
end
end
# regression tests
# regression tests
assert
(
'issue #1'
)
do
assert
(
'issue #1'
)
do
[
1
,
2
].
pack
(
"nn"
)
==
"
\000\001\000\002
"
assert_equal
"
\000\001\000\002
"
,
[
1
,
2
].
pack
(
"nn"
)
end
end
def
assert_pack
tmpl
,
packed
,
unpacked
assert_equal
packed
,
unpacked
.
pack
(
tmpl
)
assert_equal
unpacked
,
packed
.
unpack
(
tmpl
)
end
PACK_IS_LITTLE_ENDIAN
=
"
\x01\00
"
.
unpack
(
'S'
)[
0
]
==
0x01
assert
'pack float'
do
assert
'pack float'
do
assert_pack
'e'
,
"
\x00\x00
@@"
,
[
3.0
]
assert_pack
'e'
,
"
\x00\x00
@@"
,
[
3.0
]
assert_pack
'g'
,
"@@
\x00\x00
"
,
[
3.0
]
assert_pack
'g'
,
"@@
\x00\x00
"
,
[
3.0
]
...
...
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