Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

update rubyspec to 5ab3e915145a145f592dc7f9d493f1cae18e7012

  • Loading branch information...
commit 6f271a4ee975e9927e2568e54468f46536bd85f2 1 parent ca1401b
@Watson1978 Watson1978 authored
Showing with 4,087 additions and 4,158 deletions.
  1. +6 −0 spec/frozen/command_line/dash_a_spec.rb
  2. +6 −0 spec/frozen/command_line/dash_p_spec.rb
  3. +1 −3 spec/frozen/core/argf/rewind_spec.rb
  4. +4 −0 spec/frozen/core/array/join_spec.rb
  5. +49 −9 spec/frozen/core/array/pack/i_spec.rb
  6. +193 −9 spec/frozen/core/array/pack/l_spec.rb
  7. +10 −10 spec/frozen/core/array/pack/q_spec.rb
  8. +49 −9 spec/frozen/core/array/pack/s_spec.rb
  9. +0 −2,419 spec/frozen/core/array/pack_spec.rb
  10. +94 −40 spec/frozen/core/array/rotate_spec.rb
  11. +39 −7 spec/frozen/core/array/shared/collect.rb
  12. +2 −2 spec/frozen/core/array/values_at_spec.rb
  13. +4 −1 spec/frozen/core/basicobject/__id__spec.rb
  14. +2 −1  spec/frozen/core/bignum/case_compare_spec.rb
  15. +2 −29 spec/frozen/core/bignum/equal_value_spec.rb
  16. +31 −0 spec/frozen/core/bignum/shared/equal.rb
  17. +12 −0 spec/frozen/core/binding/eval_spec.rb
  18. +3 −36 spec/frozen/core/class/initialize_spec.rb
  19. +34 −1 spec/frozen/core/class/new_spec.rb
  20. +9 −1 spec/frozen/core/complex/marshal_dump_spec.rb
  21. +19 −1 spec/frozen/core/complex/marshal_load_spec.rb
  22. +14 −4 spec/frozen/core/dir/shared/delete.rb
  23. +2 −2 spec/frozen/core/encoding/aliases_spec.rb
  24. +20 −5 spec/frozen/core/encoding/compatible_spec.rb
  25. +3 −2 spec/frozen/core/encoding/converter/replacement_spec.rb
  26. +1 −1  spec/frozen/core/fiber/resume_spec_disabled.rb
  27. +5 −0 spec/frozen/core/file/open_spec.rb
  28. +6 −0 spec/frozen/core/file/stat/zero_spec.rb
  29. +6 −0 spec/frozen/core/file/zero_spec.rb
  30. +6 −0 spec/frozen/core/filetest/zero_spec.rb
  31. +2 −1  spec/frozen/core/fixnum/case_compare_spec.rb
  32. +2 −22 spec/frozen/core/fixnum/equal_value_spec.rb
  33. +19 −1 spec/frozen/core/fixnum/even_spec.rb
  34. +19 −1 spec/frozen/core/fixnum/odd_spec.rb
  35. +24 −0 spec/frozen/core/fixnum/shared/equal.rb
  36. +11 −1 spec/frozen/core/fixnum/succ_spec.rb
  37. +2 −1  spec/frozen/core/float/case_compare_spec.rb
  38. +2 −12 spec/frozen/core/float/equal_value_spec.rb
  39. +14 −0 spec/frozen/core/float/shared/equal.rb
  40. +30 −6 spec/frozen/core/float/shared/modulo.rb
  41. +1 −5 spec/frozen/core/float/to_int_spec.rb
  42. +4 −0 spec/frozen/core/hash/constructor_spec.rb
  43. +8 −0 spec/frozen/core/hash/fixtures/classes.rb
  44. +21 −4 spec/frozen/core/integer/shared/next.rb
  45. +35 −0 spec/frozen/core/io/advise_spec.rb
  46. +2 −19 spec/frozen/core/io/ioctl_spec.rb
  47. +72 −78 spec/frozen/core/io/popen_spec.rb
  48. +0 −10 spec/frozen/core/io/set_encoding_spec.rb
  49. +124 −15 spec/frozen/core/io/shared/new.rb
  50. +6 −1 spec/frozen/core/io/sysopen_spec.rb
  51. +1 −10 spec/frozen/core/kernel/String_spec.rb
  52. +23 −13 spec/frozen/core/kernel/exec_spec.rb
  53. +17 −41 spec/frozen/core/kernel/exit_spec.rb
  54. +37 −69 spec/frozen/core/kernel/freeze_spec.rb
  55. +28 −15 spec/frozen/core/kernel/instance_eval_spec.rb
  56. +4 −0 spec/frozen/core/kernel/open_spec.rb
  57. +18 −3 spec/frozen/core/kernel/respond_to_missing_spec.rb
  58. +24 −6 spec/frozen/core/kernel/respond_to_spec.rb
  59. +2 −1  spec/frozen/core/kernel/shared/load.rb
  60. +30 −7 spec/frozen/core/kernel/taint_spec.rb
  61. +0 −4 spec/frozen/core/kernel/to_s_spec.rb
  62. +15 −12 spec/frozen/core/kernel/trust_spec.rb
  63. +29 −1 spec/frozen/core/kernel/untaint_spec.rb
  64. +16 −10 spec/frozen/core/kernel/untrust_spec.rb
  65. +15 −0 spec/frozen/core/main/fixtures/classes.rb
  66. +1 −0  spec/frozen/core/main/fixtures/wrapped_include.rb
  67. +18 −0 spec/frozen/core/main/include_spec.rb
  68. +13 −0 spec/frozen/core/main/private_spec.rb
  69. +13 −0 spec/frozen/core/main/public_spec.rb
  70. +7 −0 spec/frozen/core/main/to_s_spec.rb
  71. +371 −325 spec/frozen/core/marshal/dump_spec.rb
  72. +4 −10 spec/frozen/core/marshal/fixtures/marshal_data.rb
  73. +3 −567 spec/frozen/core/marshal/load_spec.rb
  74. +7 −0 spec/frozen/core/marshal/major_version_spec.rb
  75. +7 −0 spec/frozen/core/marshal/minor_version_spec.rb
  76. +2 −1  spec/frozen/core/marshal/restore_spec.rb
  77. +625 −0 spec/frozen/core/marshal/shared/load.rb
  78. +31 −6 spec/frozen/core/math/atan2_spec.rb
  79. +8 −0 spec/frozen/core/method/arity_spec.rb
  80. +8 −0 spec/frozen/core/method/fixtures/classes.rb
  81. +12 −0 spec/frozen/core/method/hash_spec.rb
  82. +7 −1 spec/frozen/core/method/name_spec.rb
  83. +8 −0 spec/frozen/core/method/owner_spec.rb
  84. +9 −0 spec/frozen/core/method/receiver_spec.rb
  85. +9 −0 spec/frozen/core/method/shared/call.rb
  86. +13 −6 spec/frozen/core/method/shared/eql.rb
  87. +7 −1 spec/frozen/core/method/source_location_spec.rb
  88. +5 −0 spec/frozen/core/method/versions/parameters_1.9.rb
  89. +14 −0 spec/frozen/core/module/alias_method_spec.rb
  90. +9 −0 spec/frozen/core/module/autoload_spec.rb
  91. +6 −0 spec/frozen/core/module/const_set_spec.rb
  92. +16 −0 spec/frozen/core/module/define_method_spec.rb
  93. +11 −0 spec/frozen/core/module/fixtures/autoload_subclass.rb
  94. +4 −0 spec/frozen/core/module/fixtures/module.rb
  95. +0 −5 spec/frozen/core/module/include_spec.rb
  96. +0 −1  spec/frozen/core/module/instance_method_spec.rb
  97. +75 −19 spec/frozen/core/module/name_spec.rb
  98. +6 −0 spec/frozen/core/module/remove_class_variable_spec.rb
  99. +16 −0 spec/frozen/core/module/remove_method_spec.rb
  100. +10 −0 spec/frozen/core/process/abort_spec.rb
  101. +0 −7 spec/frozen/core/process/daemon_spec.rb
  102. +127 −0 spec/frozen/core/process/daemon_spec_disable.rb
  103. +44 −0 spec/frozen/core/process/fixtures/common.rb
  104. +111 −0 spec/frozen/core/process/fixtures/daemon.rb
  105. +9 −1 spec/frozen/core/rational/marshal_dump_spec.rb
  106. +19 −1 spec/frozen/core/rational/marshal_load_spec.rb
  107. +6 −0 spec/frozen/core/string/allocate_spec.rb
  108. +12 −0 spec/frozen/core/string/chop_spec.rb
  109. +16 −5 spec/frozen/core/string/end_with_spec.rb
  110. +6 −0 spec/frozen/core/string/new_spec.rb
  111. +6 −4 spec/frozen/core/string/shared/concat.rb
  112. +8 −6 spec/frozen/core/string/split_spec.rb
  113. +16 −5 spec/frozen/core/string/start_with_spec.rb
  114. +4 −0 spec/frozen/core/string/tr_spec.rb
  115. +76 −16 spec/frozen/core/string/unpack/i_spec.rb
  116. +266 −14 spec/frozen/core/string/unpack/l_spec.rb
  117. +18 −14 spec/frozen/core/string/unpack/q_spec.rb
  118. +76 −16 spec/frozen/core/string/unpack/s_spec.rb
  119. +28 −0 spec/frozen/core/thread/element_set_spec.rb
  120. +30 −0 spec/frozen/core/thread/key_spec.rb
  121. +33 −0 spec/frozen/core/thread/keys_spec.rb
  122. +21 −0 spec/frozen/core/unboundmethod/fixtures/classes.rb
  123. +12 −0 spec/frozen/core/unboundmethod/hash_spec.rb
  124. +24 −1 spec/frozen/core/unboundmethod/source_location_spec.rb
  125. +1 −1  spec/frozen/fixtures/code/wrap_fixture.rb
  126. +13 −3 spec/frozen/language/array_spec.rb
  127. +48 −0 spec/frozen/language/block_spec.rb
  128. +24 −0 spec/frozen/language/fixtures/module.rb
  129. +15 −0 spec/frozen/language/fixtures/super.rb
  130. +32 −97 spec/frozen/language/module_spec.rb
  131. +1 −1  spec/frozen/language/not_spec.rb
  132. +19 −2 spec/frozen/language/regexp/modifiers_spec.rb
  133. +16 −0 spec/frozen/language/super_spec.rb
  134. +86 −0 spec/frozen/language/versions/block_1.9.rb
  135. +1 −1  spec/frozen/library/datetime/hour_spec.rb
  136. +14 −4 spec/frozen/library/delegate/delegator/method_spec.rb
  137. +10 −2 spec/frozen/library/delegate/delegator/send_spec.rb
  138. +10 −0 spec/frozen/library/etc/group_spec.rb
  139. +2 −2 spec/frozen/library/net/http/httpheader/each_capitalized_name_spec.rb
  140. +2 −2 spec/frozen/library/net/http/httpheader/each_value_spec.rb
  141. +2 −2 spec/frozen/library/net/http/httpheader/shared/each_capitalized.rb
  142. +2 −2 spec/frozen/library/net/http/httpheader/shared/each_header.rb
  143. +2 −2 spec/frozen/library/net/http/httpheader/shared/each_name.rb
  144. +14 −6 spec/frozen/library/openstruct/initialize_copy_spec.rb
  145. +5 −3 spec/frozen/library/openstruct/new_ostruct_member_spec.rb
  146. +2 −0  spec/frozen/library/openstruct/table_spec.rb
  147. +1 −0  spec/frozen/library/rexml/attributes/each_attribute_spec.rb
  148. +1 −0  spec/frozen/library/rexml/attributes/each_spec.rb
  149. +23 −0 spec/frozen/library/socket/basicsocket/ioctl_spec.rb
  150. +3 −3 spec/frozen/library/socket/socket/gethostname_spec.rb
  151. +2 −2 spec/frozen/library/socket/socket/getnameinfo_spec.rb
  152. +18 −5 spec/frozen/library/tmpdir/dir/mktmpdir_spec.rb
  153. +16 −0 spec/frozen/optional/capi/array_spec.rb
  154. +25 −0 spec/frozen/optional/capi/encoding_spec.rb
  155. +11 −0 spec/frozen/optional/capi/ext/array_spec.c
  156. +26 −0 spec/frozen/optional/capi/ext/encoding_spec.c
  157. +2 −0  spec/frozen/optional/capi/ext/rubyspec.h
  158. +1 −1  spec/frozen/optional/capi/marshal_spec.rb
  159. +1 −1  spec/frozen/shared/file/zero.rb
  160. +22 −21 spec/frozen/shared/mutex/try_lock.rb
  161. +1 −1  spec/frozen/shared/object/object_id.rb
  162. +1 −1  spec/frozen/upstream
View
6 spec/frozen/command_line/dash_a_spec.rb
@@ -8,4 +8,10 @@
:args => " < #{@names}").should ==
"jones\nfield\ngrey\n"
end
+
+ it "sets $-a" do
+ ruby_exe("puts $-a", :options => "-n -a", :escape => true,
+ :args => " < #{@names}").should ==
+ "true\ntrue\ntrue\n"
+ end
end
View
6 spec/frozen/command_line/dash_p_spec.rb
@@ -8,4 +8,10 @@
:args => " < #{@names}").should ==
"ALICE\nBOB\nJAMES\n"
end
+
+ it "sets $-p" do
+ ruby_exe("$_ = $-p", :options => "-p", :escape => true,
+ :args => " < #{@names}").should ==
+ "truetruetrue"
+ end
end
View
4 spec/frozen/core/argf/rewind_spec.rb
@@ -28,9 +28,7 @@
end
end
- # This fails on all versions as reported in bug #1693. If it's deemed not to
- # be a bug, this guard can be removed
- ruby_bug "#1693", "1.8.7.302" do
+ ruby_bug "#1693", "1.8" do
it "resets ARGF.lineno to 0" do
argv [@file2_name] do
ARGF.lineno = 0
View
4 spec/frozen/core/array/join_spec.rb
@@ -26,4 +26,8 @@
obj = mock("not a string")
lambda { [1, 2].join(obj) }.should raise_error(TypeError)
end
+
+ it "raises a TypeError if passed false as the separator" do
+ lambda { [1, 2].join(false) }.should raise_error(TypeError)
+ end
end
View
58 spec/frozen/core/array/pack/i_spec.rb
@@ -21,24 +21,64 @@
end
ruby_version_is "1.9.3" do
- describe "Array#pack with modifier '>'" do
- describe "with format 'I'" do
+ describe "Array#pack with format 'I'" do
+ describe "with modifier '<'" do
+ it_behaves_like :array_pack_32bit_le, 'I<'
+ end
+
+ describe "with modifier '<' and '_'" do
+ it_behaves_like :array_pack_32bit_le, 'I<_'
+ it_behaves_like :array_pack_32bit_le, 'I_<'
+ end
+
+ describe "with modifier '<' and '!'" do
+ it_behaves_like :array_pack_32bit_le, 'I<!'
+ it_behaves_like :array_pack_32bit_le, 'I!<'
+ end
+
+ describe "with modifier '>'" do
it_behaves_like :array_pack_32bit_be, 'I>'
end
- describe "with format 'i'" do
- it_behaves_like :array_pack_32bit_be, 'i>'
+ describe "with modifier '>' and '_'" do
+ it_behaves_like :array_pack_32bit_be, 'I>_'
+ it_behaves_like :array_pack_32bit_be, 'I_>'
end
- end
- describe "Array#pack with modifier '<'" do
- describe "with format 'I'" do
- it_behaves_like :array_pack_32bit_le, 'I<'
+ describe "with modifier '>' and '!'" do
+ it_behaves_like :array_pack_32bit_be, 'I>!'
+ it_behaves_like :array_pack_32bit_be, 'I!>'
end
+ end
- describe "with format 'i'" do
+ describe "Array#pack with format 'i'" do
+ describe "with modifier '<'" do
it_behaves_like :array_pack_32bit_le, 'i<'
end
+
+ describe "with modifier '<' and '_'" do
+ it_behaves_like :array_pack_32bit_le, 'i<_'
+ it_behaves_like :array_pack_32bit_le, 'i_<'
+ end
+
+ describe "with modifier '<' and '!'" do
+ it_behaves_like :array_pack_32bit_le, 'i<!'
+ it_behaves_like :array_pack_32bit_le, 'i!<'
+ end
+
+ describe "with modifier '>'" do
+ it_behaves_like :array_pack_32bit_be, 'i>'
+ end
+
+ describe "with modifier '>' and '_'" do
+ it_behaves_like :array_pack_32bit_be, 'i>_'
+ it_behaves_like :array_pack_32bit_be, 'i_>'
+ end
+
+ describe "with modifier '>' and '!'" do
+ it_behaves_like :array_pack_32bit_be, 'i>!'
+ it_behaves_like :array_pack_32bit_be, 'i!>'
+ end
end
end
View
202 spec/frozen/core/array/pack/l_spec.rb
@@ -21,24 +21,208 @@
end
ruby_version_is "1.9.3" do
- describe "Array#pack with modifier '>'" do
- describe "with format 'L'" do
+ describe "Array#pack with format 'L'" do
+ describe "with modifier '<'" do
+ it_behaves_like :array_pack_32bit_le, 'L<'
+ end
+
+ describe "with modifier '>'" do
it_behaves_like :array_pack_32bit_be, 'L>'
end
- describe "with format 'l'" do
- it_behaves_like :array_pack_32bit_be, 'l>'
+ platform_is :wordsize => 32 do
+ describe "with modifier '<' and '_'" do
+ it_behaves_like :array_pack_32bit_le, 'L<_'
+ it_behaves_like :array_pack_32bit_le, 'L_<'
+ end
+
+ describe "with modifier '<' and '!'" do
+ it_behaves_like :array_pack_32bit_le, 'L<!'
+ it_behaves_like :array_pack_32bit_le, 'L!<'
+ end
+
+ describe "with modifier '>' and '_'" do
+ it_behaves_like :array_pack_32bit_be, 'L>_'
+ it_behaves_like :array_pack_32bit_be, 'L_>'
+ end
+
+ describe "with modifier '>' and '!'" do
+ it_behaves_like :array_pack_32bit_be, 'L>!'
+ it_behaves_like :array_pack_32bit_be, 'L!>'
+ end
end
- end
- describe "Array#pack with modifier '<'" do
- describe "with format 'L'" do
- it_behaves_like :array_pack_32bit_le, 'L<'
+ platform_is :wordsize => 64 do
+ platform_is_not :os => :windows do
+ describe "with modifier '<' and '_'" do
+ it_behaves_like :array_pack_64bit_le, 'L<_'
+ it_behaves_like :array_pack_64bit_le, 'L_<'
+ end
+
+ describe "with modifier '<' and '!'" do
+ it_behaves_like :array_pack_64bit_le, 'L<!'
+ it_behaves_like :array_pack_64bit_le, 'L!<'
+ end
+
+ describe "with modifier '>' and '_'" do
+ it_behaves_like :array_pack_64bit_be, 'L>_'
+ it_behaves_like :array_pack_64bit_be, 'L_>'
+ end
+
+ describe "with modifier '>' and '!'" do
+ it_behaves_like :array_pack_64bit_be, 'L>!'
+ it_behaves_like :array_pack_64bit_be, 'L!>'
+ end
+ end
+
+ platform_is :os => :windows do
+ not_compliant_on :jruby do
+ describe "with modifier '<' and '_'" do
+ it_behaves_like :array_pack_32bit_le, 'L<_'
+ it_behaves_like :array_pack_32bit_le, 'L_<'
+ end
+
+ describe "with modifier '<' and '!'" do
+ it_behaves_like :array_pack_32bit_le, 'L<!'
+ it_behaves_like :array_pack_32bit_le, 'L!<'
+ end
+
+ describe "with modifier '>' and '_'" do
+ it_behaves_like :array_pack_32bit_be, 'L>_'
+ it_behaves_like :array_pack_32bit_be, 'L_>'
+ end
+
+ describe "with modifier '>' and '!'" do
+ it_behaves_like :array_pack_32bit_be, 'L>!'
+ it_behaves_like :array_pack_32bit_be, 'L!>'
+ end
+ end
+
+ deviates_on :jruby do
+ describe "with modifier '<' and '_'" do
+ it_behaves_like :array_pack_64bit_le, 'L<_'
+ it_behaves_like :array_pack_64bit_le, 'L_<'
+ end
+
+ describe "with modifier '<' and '!'" do
+ it_behaves_like :array_pack_64bit_le, 'L<!'
+ it_behaves_like :array_pack_64bit_le, 'L!<'
+ end
+
+ describe "with modifier '>' and '_'" do
+ it_behaves_like :array_pack_64bit_be, 'L>_'
+ it_behaves_like :array_pack_64bit_be, 'L_>'
+ end
+
+ describe "with modifier '>' and '!'" do
+ it_behaves_like :array_pack_64bit_be, 'L>!'
+ it_behaves_like :array_pack_64bit_be, 'L!>'
+ end
+ end
+ end
end
+ end
- describe "with format 'l'" do
+ describe "Array#pack with format 'l'" do
+ describe "with modifier '<'" do
it_behaves_like :array_pack_32bit_le, 'l<'
end
+
+ describe "with modifier '>'" do
+ it_behaves_like :array_pack_32bit_be, 'l>'
+ end
+
+ platform_is :wordsize => 32 do
+ describe "with modifier '<' and '_'" do
+ it_behaves_like :array_pack_32bit_le, 'l<_'
+ it_behaves_like :array_pack_32bit_le, 'l_<'
+ end
+
+ describe "with modifier '<' and '!'" do
+ it_behaves_like :array_pack_32bit_le, 'l<!'
+ it_behaves_like :array_pack_32bit_le, 'l!<'
+ end
+
+ describe "with modifier '>' and '_'" do
+ it_behaves_like :array_pack_32bit_be, 'l>_'
+ it_behaves_like :array_pack_32bit_be, 'l_>'
+ end
+
+ describe "with modifier '>' and '!'" do
+ it_behaves_like :array_pack_32bit_be, 'l>!'
+ it_behaves_like :array_pack_32bit_be, 'l!>'
+ end
+ end
+
+ platform_is :wordsize => 64 do
+ platform_is_not :os => :windows do
+ describe "with modifier '<' and '_'" do
+ it_behaves_like :array_pack_64bit_le, 'l<_'
+ it_behaves_like :array_pack_64bit_le, 'l_<'
+ end
+
+ describe "with modifier '<' and '!'" do
+ it_behaves_like :array_pack_64bit_le, 'l<!'
+ it_behaves_like :array_pack_64bit_le, 'l!<'
+ end
+
+ describe "with modifier '>' and '_'" do
+ it_behaves_like :array_pack_64bit_be, 'l>_'
+ it_behaves_like :array_pack_64bit_be, 'l_>'
+ end
+
+ describe "with modifier '>' and '!'" do
+ it_behaves_like :array_pack_64bit_be, 'l>!'
+ it_behaves_like :array_pack_64bit_be, 'l!>'
+ end
+ end
+
+ platform_is :os => :windows do
+ not_compliant_on :jruby do
+ describe "with modifier '<' and '_'" do
+ it_behaves_like :array_pack_32bit_le, 'l<_'
+ it_behaves_like :array_pack_32bit_le, 'l_<'
+ end
+
+ describe "with modifier '<' and '!'" do
+ it_behaves_like :array_pack_32bit_le, 'l<!'
+ it_behaves_like :array_pack_32bit_le, 'l!<'
+ end
+
+ describe "with modifier '>' and '_'" do
+ it_behaves_like :array_pack_32bit_be, 'l>_'
+ it_behaves_like :array_pack_32bit_be, 'l_>'
+ end
+
+ describe "with modifier '>' and '!'" do
+ it_behaves_like :array_pack_32bit_be, 'l>!'
+ it_behaves_like :array_pack_32bit_be, 'l!>'
+ end
+ end
+
+ deviates_on :jruby do
+ describe "with modifier '<' and '_'" do
+ it_behaves_like :array_pack_64bit_le, 'l<_'
+ it_behaves_like :array_pack_64bit_le, 'l_<'
+ end
+
+ describe "with modifier '<' and '!'" do
+ it_behaves_like :array_pack_64bit_le, 'l<!'
+ it_behaves_like :array_pack_64bit_le, 'l!<'
+ end
+
+ describe "with modifier '>' and '_'" do
+ it_behaves_like :array_pack_64bit_be, 'l>_'
+ it_behaves_like :array_pack_64bit_be, 'l_>'
+ end
+
+ describe "with modifier '>' and '!'" do
+ it_behaves_like :array_pack_64bit_be, 'l>!'
+ it_behaves_like :array_pack_64bit_be, 'l!>'
+ end
+ end
+ end
+ end
end
end
View
20 spec/frozen/core/array/pack/q_spec.rb
@@ -23,23 +23,23 @@
end
ruby_version_is "1.9.3" do
- describe "Array#pack with modifier '>'" do
- describe "with format 'Q'" do
- it_behaves_like :array_pack_64bit_be, 'Q>'
+ describe "Array#pack with format 'Q'" do
+ describe "with modifier '<'" do
+ it_behaves_like :array_pack_64bit_le, 'Q<'
end
- describe "with format 'q'" do
- it_behaves_like :array_pack_64bit_be, 'q>'
+ describe "with modifier '>'" do
+ it_behaves_like :array_pack_64bit_be, 'Q>'
end
end
- describe "Array#pack with modifier '<'" do
- describe "with format 'Q'" do
- it_behaves_like :array_pack_64bit_le, 'Q<'
+ describe "Array#pack with format 'q'" do
+ describe "with modifier '<'" do
+ it_behaves_like :array_pack_64bit_le, 'q<'
end
- describe "with format 'q'" do
- it_behaves_like :array_pack_64bit_le, 'q<'
+ describe "with modifier '>'" do
+ it_behaves_like :array_pack_64bit_be, 'q>'
end
end
end
View
58 spec/frozen/core/array/pack/s_spec.rb
@@ -21,24 +21,64 @@
end
ruby_version_is "1.9.3" do
- describe "Array#pack with modifier '>'" do
- describe "with format 'S'" do
+ describe "Array#pack with format 'S'" do
+ describe "with modifier '<'" do
+ it_behaves_like :array_pack_16bit_le, 'S<'
+ end
+
+ describe "with modifier '<' and '_'" do
+ it_behaves_like :array_pack_16bit_le, 'S<_'
+ it_behaves_like :array_pack_16bit_le, 'S_<'
+ end
+
+ describe "with modifier '<' and '!'" do
+ it_behaves_like :array_pack_16bit_le, 'S<!'
+ it_behaves_like :array_pack_16bit_le, 'S!<'
+ end
+
+ describe "with modifier '>'" do
it_behaves_like :array_pack_16bit_be, 'S>'
end
- describe "with format 's'" do
- it_behaves_like :array_pack_16bit_be, 's>'
+ describe "with modifier '>' and '_'" do
+ it_behaves_like :array_pack_16bit_be, 'S>_'
+ it_behaves_like :array_pack_16bit_be, 'S_>'
end
- end
- describe "Array#pack with modifier '<'" do
- describe "with format 'S'" do
- it_behaves_like :array_pack_16bit_le, 'S<'
+ describe "with modifier '>' and '!'" do
+ it_behaves_like :array_pack_16bit_be, 'S>!'
+ it_behaves_like :array_pack_16bit_be, 'S!>'
end
+ end
- describe "with format 's'" do
+ describe "Array#pack with format 's'" do
+ describe "with modifier '<'" do
it_behaves_like :array_pack_16bit_le, 's<'
end
+
+ describe "with modifier '<' and '_'" do
+ it_behaves_like :array_pack_16bit_le, 's<_'
+ it_behaves_like :array_pack_16bit_le, 's_<'
+ end
+
+ describe "with modifier '<' and '!'" do
+ it_behaves_like :array_pack_16bit_le, 's<!'
+ it_behaves_like :array_pack_16bit_le, 's!<'
+ end
+
+ describe "with modifier '>'" do
+ it_behaves_like :array_pack_16bit_be, 's>'
+ end
+
+ describe "with modifier '>' and '_'" do
+ it_behaves_like :array_pack_16bit_be, 's>_'
+ it_behaves_like :array_pack_16bit_be, 's_>'
+ end
+
+ describe "with modifier '>' and '!'" do
+ it_behaves_like :array_pack_16bit_be, 's>!'
+ it_behaves_like :array_pack_16bit_be, 's!>'
+ end
end
end
View
2,419 spec/frozen/core/array/pack_spec.rb
@@ -1,2419 +0,0 @@
-# -*- coding: ISO-8859-1 -*-
-# ~~~~~~~~~~
-# Script encoding of this file should be neither ASCII-8BIT, US-ASCII nor UTF-8.
-# This makes it easier to verify that Strings are converted into correct encodings.
-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-
-# general behavior
-
-describe "Array#pack" do
- it "returns a String" do
- ["abc", "def"].pack("A*").should be_kind_of(String)
- end
-
- it "raises an ArgumentError with ('%')" do
- lambda { [].pack("%") }.should raise_error(ArgumentError)
- end
-
- it "raises an ArgumentError on empty array" do
- ['A', 'a', 'B', 'b', 'C', 'c', 'D', 'd',
- 'E', 'e', 'F', 'f', 'G', 'g', 'H', 'h',
- 'I', 'i', 'L', 'l', 'M', 'm', 'N', 'n',
- 'Q', 'q', 'U', 'u','w', 'Z'].each { |pat|
- lambda { [].pack(pat) }.should raise_error(ArgumentError)
- }
- end
-
- it "sequentially processes each pack format, which consumes element in the array, and finally concatenates their result" do
- ["abc", 1, 2, 3, '01000001', 0x20].pack('Av2NB8c').should ==
- encode("a\x01\x00\x02\x00\x00\x00\x00\x03A ", "binary")
- end
-
- it "ignores white spaces" do
- ["abc", 1, 2, 3, '01000001', 0x20, 0x61].pack("A \f v2\tN\rB8\nc\vC").should ==
- encode("a\x01\x00\x02\x00\x00\x00\x00\x03A a", "binary")
- end
-
- it "skips everything till the end of line (LF) string with ('#')" do
- ["abc", "def"].pack("A*#A10%").should == "abc"
- ["abc", "def"].pack("A*#junk junk junk junk junk\nA10").should == "abcdef "
- ["abc", "def"].pack("A*#junk junk junk junk junk\rA10").should == "abc"
- end
-
- ruby_version_is '1.8.8' do
- it "returns a tainted string when the format is tainted" do
- ["abcd", 0x20].pack("A3C".taint).tainted?.should be_true
- end
-
- it "returns a tainted string when the format is tainted even if the given format is empty" do
- ["abcd", 0x20].pack("".taint).tainted?.should be_true
- end
- end
-
- it "returns a tainted string when a pack argument is tainted" do
- ["abcd".taint, 0x20].pack("A3C").tainted?.should be_true
- end
-
- it "returns a not tainted string even if the array is tainted" do
- ["abcd", 0x20].taint.pack("A3C").tainted?.should be_false
- end
-
- ruby_version_is '1.9' do
- it "returns a untrusted string when the format is untrusted" do
- ["abcd", 0x20].pack("A3C".untrust).untrusted?.should be_true
- end
-
- it "returns a untrusted string when the format is untrusted even if the given format is empty" do
- ["abcd", 0x20].pack("".untrust).untrusted?.should be_true
- end
-
- it "returns a untrusted string when a pack argument is untrusted" do
- ["abcd".untrust, 0x20].pack("A3C").untrusted?.should be_true
- end
-
- it "returns a trusted string even if the array is untrusted" do
- ["abcd", 0x20].untrust.pack("A3C").untrusted?.should be_false
- end
-
- it "returns a string in encoding of common to the concatenated results" do
- ["\u{3042 3044 3046 3048}", 0x2000B].pack("A*U").encoding.should ==
- Encoding::ASCII_8BIT
- ["abcde\xd1", "\xFF\xFe\x81\x82"].pack("A*u").encoding.should ==
- Encoding::ASCII_8BIT
- ["abcde".encode(Encoding::US_ASCII), "\xFF\xFe\x81\x82"].pack("A*u").encoding.should ==
- Encoding::ASCII_8BIT
- # under discussion [ruby-dev:37294]
- ["\u{3042 3044 3046 3048}", 1].pack("A*N").encoding.should == Encoding::ASCII_8BIT
- end
- end
-
- # Scenario taken from Mongrel's use of the SO_ACCEPTFILTER struct
- it "reuses last array element as often as needed to complete the string" do
- expected = "httpready" + ("\000" * 247)
- ['httpready', nil].pack('a16a240').should == expected
- end
-end
-
-describe "Array#pack with the empty format" do
- it "returns an empty string" do
- [1, 2, 3, true].pack("").should == ""
- end
-
- ruby_version_is '1.9' do
- it "returns an empty String in US-ASCII" do
- [1, 2, 3, true].pack("").encoding.should == Encoding::US_ASCII
- end
- end
-end
-
-# string to string formats
-
-describe "Array#pack with ASCII-string format", :shared => true do
- before do
- @format = @method
- def self.format(count = nil)
- "#{@format}#{count}"
- end
- end
-
- it "returns a String" do
- ["abc"].pack(format).should be_kind_of(String)
- end
-
- it "cuts string if its size greater than directive count" do
- ['abcde'].pack(format(3)).should == 'abc'
- end
-
- it "considers count = 1 if count omited" do
- ['abcde'].pack(format).should == 'a'
- end
-
- it "returns empty string if count = 0 with" do
- ['abcde'].pack(format(0)).should == ''
- end
-
- it "returns the whole argument string with star parameter" do
- ['abcdef'].pack(format('*')).should == 'abcdef'
- end
-
- it "comsumres only one array item per a format" do
- ["abc", "def"].pack(format('*')).should == "abc"
- ["abc", "def"].pack(format('*')+format('*')).should == "abcdef"
- end
-
- it "tries to convert the pack argument to a String using #to_str" do
- obj = mock('to_str')
- obj.should_receive(:to_str).and_return("abc")
- [obj].pack(format).should == "a"
- end
-
- it "raises a TypeError if array item is not String with ('A<count>')" do
- lambda { [123].pack(format(5)) }.should raise_error(TypeError)
- lambda { [[]].pack(format(5)) }.should raise_error(TypeError)
- lambda { [mock('not string')].pack(format(5)) }.should raise_error(TypeError)
- end
-
- ruby_version_is '1.9' do
- it "treats a multibyte character just as a byte sequence" do
- s = "\u3042\u3044\u3046\u3048"
- [s].pack(format('*')).bytes.to_a.should == s.bytes.to_a
- [s].pack(format('3')).bytesize.should == 3
-
- # example of dummy encoding
- s = "\u3042".encode(Encoding::UTF_32BE)
- [s].pack(format('*')).bytes.to_a.should == s.bytes.to_a
-
- # example of stateful encoding
- s = "\u3042".encode(Encoding::ISO_2022_JP)
- [s].pack(format('*')).bytes.to_a.should == s.bytes.to_a
- end
-
- # This feature is under discussion - [ruby-dev:37278]
- it "returns result in ASCII-8BIT" do
- ["abcd"].pack(format).encoding.should == Encoding::ASCII_8BIT
- ["\u3042"].pack(format).encoding.should == Encoding::ASCII_8BIT
- ["\u3042".encode(Encoding::UTF_32BE)].pack(format).encoding.should ==
- Encoding::ASCII_8BIT
- ["\u3042".encode(Encoding::ISO_2022_JP)].pack(format).encoding.should ==
- Encoding::ASCII_8BIT
- end
-
- # This feature is under discussion - [ruby-dev:37278]
- it "cuts byte sequence even if it breaks a multibyte character" do
- ["\u3042"].pack(format).should == "\xe3".force_encoding('ascii-8bit')
- ["\u3042".encode(Encoding::UTF_32BE)].pack(format(2)).should == "\x00\x00"
- ["\u3042".encode(Encoding::ISO_2022_JP)].pack(format(4)).should == "\e$B$"
- end
- end
-end
-
-describe "Array#pack with format 'A'" do
- it_behaves_like "Array#pack with ASCII-string format", 'A'
-
- it "returns space padded string" do
- ['abcde'].pack('A7').should == 'abcde '
- end
-end
-
-describe "Array#pack with format 'a'" do
- it_behaves_like "Array#pack with ASCII-string format", 'a'
-
- it "returns null padded string with ('a<count>')" do
- ['abcdef'].pack('a7').should == "abcdef\x0"
- end
-end
-
-describe "Array#pack with format 'Z'" do
- it_behaves_like "Array#pack with ASCII-string format", 'a'
-
- it "returns null padded string with ('a<count>')" do
- ['abcdef'].pack('a7').should == "abcdef\x0"
- end
-end
-
-describe "Array#pack with format 'B'" do
- it "returns packed bit-string descending order" do
- ["011000010110001001100011"].pack('B24').should == encode('abc', "binary")
- end
-
- # [ruby-dev:37279]
- it "accepts characters other than 0 or 1 for compatibility to perl" do
- lambda{ ["abbbbccddefffgghiijjjkkl"].pack('B24') }.should_not raise_error
- end
- ruby_version_is '1.9' do
- it "treats the pack argument as a byte sequence when its characters are other than 0 or 1" do
- ["\u3042"*8].pack('B*').length.should == "\u3042".bytesize * 8 / 8
- end
- end
-
- it "conversion edge case: all zeros" do
- ["00000000"].pack('B8').should == encode("\000", "binary")
- end
-
- it "conversion edge case: all ones" do
- ["11111111"].pack('B8').should == encode("\xFF", "binary")
- end
-
- it "conversion edge case: left one" do
- ["10000000"].pack('B8').should == encode("\x80", "binary")
- end
-
- it "conversion edge case: right one" do
- ["00000001"].pack('B8').should == encode("\x01", "binary")
- end
-
- it "conversion edge case: edge sequences not in first char" do
- ["0000000010000000000000011111111100000000"].pack('B40').should == encode("\x00\x80\x01\xFF\x00", "binary")
- end
-
- it "uses zeros if count is not multiple of 8" do
- ["00111111"].pack('B4').should == ["00110000"].pack('B8')
- end
-
- it "returns zero-char for each 2 of count that greater than string length" do
- [""].pack('B6').should == encode("\x00\x00\x00", "binary")
- end
-
- it "returns extra zero char if count is odd and greater than string length" do
- [""].pack('B7').should == encode("\x00\x00\x00\x00", "binary")
- end
-
- it "starts new char if string is ended before char's 8 bits" do
- ["0011"].pack('B8').should == encode("0\x00\x00", "binary")
- end
-
- it "considers count = 1 if no explicit count it given" do
- ["10000000"].pack('B').should == ["10000000"].pack('B1')
- ["01000000"].pack('B').should == ["01000000"].pack('B1')
- end
-
- it "returns empty string if count = 0" do
- ["10101010"].pack('B0').should == encode("", "binary")
- end
-
- it "uses argument string length as count if count = *" do
- ["00111111010"].pack('B*').should == ["00111111010"].pack('B11')
- end
-
- it "consumes only one array item per a format" do
- ["0011", "1111"].pack('B*').should == ["0011"].pack('B4')
- ["0011", "1011"].pack('B*B*').should == ["0011"].pack('B4') + ["1011"].pack('B4')
- end
-
- it "raises a TypeError if corresponding array item is not String" do
- lambda { [123].pack('B8') }.should raise_error(TypeError)
- lambda { [[]].pack('B8') }.should raise_error(TypeError)
- lambda { [mock('not string')].pack('B8') }.should raise_error(TypeError)
- end
-
- ruby_version_is '1.9' do
- it "returns an ASCII-8BIT string" do
- ["01000001"].pack("B").encoding.should == Encoding::ASCII_8BIT # ASCII "A"
- ["11111111"].pack("B").encoding.should == Encoding::ASCII_8BIT # invalid as ASCII
- ["1111111010000000000000011000000000000010"].pack("B").encoding.should == Encoding::ASCII_8BIT # valid as UTF-8
- end
- end
-end
-
-
-describe "Array#pack with format 'b'" do
- it "returns packed bit-string descending order" do
- ["100001100100011011000110"].pack('b24').should == encode('abc', "binary")
- end
-
- it "conversion edge case: all zeros" do
- ["00000000"].pack('b8').should == encode("\x00", "binary")
- end
-
- it "conversion edge case: all ones" do
- ["11111111"].pack('b8').should == encode("\xFF", "binary")
- end
-
- it "conversion edge case: left one" do
- ["10000000"].pack('b8').should == encode("\x01", "binary")
- end
-
- it "conversion edge case: right one" do
- ["00000001"].pack('b8').should == encode("\x80", "binary")
- end
-
- it "conversion edge case: edge sequences not in first char" do
- ["0000000010000000000000011111111100000000"].pack('b40').should == encode("\x00\x01\x80\xFF\x00", "binary")
- end
-
- # [ruby-dev:37279]
- it "accepts characters other than 0 or 1 for compatibility to perl" do
- lambda{ ["abbbbccddefffgghiijjjkkl"].pack('b24') }.should_not raise_error
- end
- ruby_version_is '1.9' do
- it "treats the pack argument as a byte sequence when its characters are other than 0 or 1" do
- ["\u3042"*8].pack('b*').length.should == "\u3042".bytesize * 8 / 8
- end
- end
-
- it "uses zeros if count is not multiple of 8" do
- ["00111111"].pack('b4').should == ["00110000"].pack('b8')
- end
-
- it "returns zero-char for each 2 of count that greater than string length" do
- [""].pack('b6').should == encode("\x00\x00\x00", "binary")
- end
-
- it "returns extra zero char if count is odd and greater than string length" do
- [""].pack('b7').should == encode("\x00\x00\x00\x00", "binary")
- end
-
- it "starts new char if argument string is ended before char's 8 bits" do
- ["0011"].pack('b8').should == encode("\x0C\x00\x00", "binary")
- end
-
- it "considers count = 1 if no explicit count it given" do
- ["10000000"].pack('b').should == ["10000000"].pack('b1')
- ["01000000"].pack('b').should == ["01000000"].pack('b1')
- end
-
- it "returns empty string if count = 0" do
- ["10101010"].pack('b0').should == encode("", "binary")
- end
-
- it "uses argument string length as count if count = *" do
- ["00111111010"].pack('b*').should == ["00111111010"].pack('b11')
- end
-
- it "consumes only one array item per a format" do
- ["0011", "1111"].pack('b*').should == ["0011"].pack('b4')
- ["0011", "1011"].pack('b*b*').should == ["0011"].pack('b4') + ["1011"].pack('b4')
- end
-
- it "raises a TypeError if corresponding array item is not String" do
- lambda { [123].pack('b8') }.should raise_error(TypeError)
- lambda { [[]].pack('b8') }.should raise_error(TypeError)
- lambda { [mock('not string')].pack('b8') }.should raise_error(TypeError)
- end
-
- ruby_version_is '1.9' do
- it "returns an ASCII-8BIT string" do
- ["10000010"].pack("b").encoding.should == Encoding::ASCII_8BIT # ASCII "A"
- ["11111111"].pack("b").encoding.should == Encoding::ASCII_8BIT # invalid as ASCII
- ["1111111010000000000000011000000000000010"].pack("b").encoding.should == Encoding::ASCII_8BIT # valid as UTF-8
- end
- end
-end
-
-describe "Array#pack with format 'H'" do
- it "encodes hexadecimal digits to byte sequence in the order of high-nibble first" do
- ["41"].pack("H2").should == encode("\x41", "binary")
- ["61"].pack("H2").should == encode("\x61", "binary")
- ["7e"].pack("H2").should == encode("\x7E", "binary")
- ["7E"].pack("H2").should == encode("\x7E", "binary")
- ["1"].pack("H").should == encode("\x10", "binary")
- ["7E1"].pack("H3").should == encode("\x7E\x10", "binary")
- end
-
- it "ignores rest of the pack argument when the argument is too long" do
- ["41424344"].pack('H2').should == encode("\x41", "binary")
- ["41424344"].pack('H4').should == encode("\x41\x42", "binary")
- end
-
- it "fills low-nibble of the last byte with 0 when count is odd" do
- ["41424344"].pack('H3').should == encode("\x41\x40", "binary")
- ["41424344"].pack('H5').should == encode("\x41\x42\x40", "binary")
- end
-
- it "fills the rest bytes with 0 if pack argument has insufficient length" do
- ["4142"].pack("H4").should == encode("\x41\x42", "binary")
- ["4142"].pack("H5").should == encode("\x41\x42\x00", "binary")
- ["4142"].pack("H6").should == encode("\x41\x42\x00", "binary")
- ["4142"].pack("H7").should == encode("\x41\x42\x00\x00", "binary")
- end
-
- ruby_bug("[ruby-dev:37283]", "1.8.7.73") do
- it "fills low-nibble of the last byte with 0 when count is odd even if pack argument has insufficient length" do
- ["414"].pack("H3").should == encode("\x41\x40", "binary")
- ["414"].pack("H4").should == encode("\x41\x40", "binary")
- ["414"].pack("H5").should == encode("\x41\x40\x00", "binary")
- ["414"].pack("H6").should == encode("\x41\x40\x00", "binary")
- end
- end
-
- it "considers count = 1 if count omited" do
- ['41'].pack('H').should == "\x40"
- end
-
- it "returns empty string if count = 0 with" do
- ['4142'].pack('H0').should == ''
- end
-
- it "returns the whole argument string with star parameter" do
- ['414243444546'].pack('H*').should == encode("\x41\x42\x43\x44\x45\x46", "binary")
- end
-
- it "consumes only one array item per a format" do
- %w(41 31 2a).pack("H2").should == encode("\x41", "binary")
- %w(41 31 2a).pack("H2H2H2").should == encode("\x41\x31\x2A", "binary")
- %w(41 31 2a).pack("H6").should == encode("\x41\x00\x00", "binary")
- end
-
- it "tries to convert the pack argument to a String using #to_str" do
- obj = mock('to_str')
- obj.should_receive(:to_str).and_return("41")
- [obj].pack('H2').should == "\x41"
- end
-
- ruby_version_is '1.9' do
- it "returns an ASCII-8BIT string" do
- ["41"].pack("H").encoding.should == Encoding::ASCII_8BIT
- end
- end
-end
-
-describe "Array#pack with format 'h'" do
- it "encodes hexadecimal digits to byte sequence in the order of low-nibble first" do
- ["14"].pack("h2").should == encode("\x41", "binary")
- ["16"].pack("h2").should == encode("\x61", "binary")
- ["e7"].pack("h2").should == encode("\x7E", "binary")
- ["E7"].pack("h2").should == encode("\x7E", "binary")
- ["1"].pack("h").should == encode("\x01", "binary")
- ["E71"].pack("h3").should == encode("\x7E\x01", "binary")
- end
-
- it "ignores rest of the pack argument when the argument is too long" do
- ["14243444"].pack('h2').should == encode("\x41", "binary")
- ["14243444"].pack('h4').should == encode("\x41\x42", "binary")
- end
-
- it "fills low-nibble of the last byte with 0 when count is odd" do
- ["14243444"].pack('h3').should == encode("\x41\x02", "binary")
- ["14243444"].pack('h5').should == encode("\x41\x42\x03", "binary")
- end
-
- it "fills the rest bytes with 0 if pack argument has insufficient length" do
- ["1424"].pack("h4").should == encode("\x41\x42", "binary")
- ["1424"].pack("h5").should == encode("\x41\x42\x00", "binary")
- ["1424"].pack("h6").should == encode("\x41\x42\x00", "binary")
- ["1424"].pack("h7").should == encode("\x41\x42\x00\x00", "binary")
- end
-
- ruby_bug("[ruby-dev:37283]", "1.8.7.73") do
- it "fills high-nibble of the last byte with 0 when count is odd even if pack argument has insufficient length" do
- ["142"].pack("h3").should == encode("\x41\x02", "binary")
- ["142"].pack("h4").should == encode("\x41\x02", "binary")
- ["142"].pack("h5").should == encode("\x41\x02\x00", "binary")
- ["142"].pack("h6").should == encode("\x41\x02\x00", "binary")
- end
- end
-
- it "considers count = 1 if count omited" do
- ['14'].pack('h').should == "\x01"
- end
-
- it "returns empty string if count = 0 with" do
- ['1424'].pack('h0').should == ''
- end
-
- it "returns the whole argument string with star parameter" do
- ['142434445464'].pack('h*').should == encode("\x41\x42\x43\x44\x45\x46", "binary")
- end
-
- it "consumes only one array item per a format" do
- %w(14 13 a2).pack("h2").should == encode("\x41", "binary")
- %w(14 13 a2).pack("h2h2h2").should == encode("\x41\x31\x2A", "binary")
- %w(14 13 a2).pack("h6").should == encode("\x41\x00\x00", "binary")
- end
-
- it "tries to convert the pack argument to a String using #to_str" do
- obj = mock('to_str')
- obj.should_receive(:to_str).and_return("14")
- [obj].pack('h2').should == "\x41"
- end
-
- ruby_version_is '1.9' do
- it "returns an ASCII-8BIT string" do
- ["14"].pack("h").encoding.should == Encoding::ASCII_8BIT
- end
- end
-end
-
-
-
-
-#
-# shared behaviours for integer formats
-#
-
-describe "Array#pack with integer format which can not have platform dependent width", :shared => true do
- before do
- @format = @method
- def self.format(count = nil)
- "#{@format}#{count}"
- end
- end
-
- it "raises ArgumentError when tails suffix '_'" do
- lambda{ [1].pack("#{format}_") }.should raise_error(ArgumentError)
- end
-
- it "raises ArgumentError when tails suffix '!'" do
- lambda{ [1].pack("#{format}!") }.should raise_error(ArgumentError)
- end
-end
-
-describe "Array#pack with integer format (8bit)", :shared => true do
- before do
- @format = @method
- def self.format(count = nil)
- "#{@format}#{count}"
- end
- end
-
- it "returns a string with byte of appropriate number" do
- [49].pack(format).should == encode('1', "binary")
- end
-
- it "regards negative values as 2's complement in order to converts it to positive" do
- [-1].pack(format).should == encode("\xFF", "binary")
- [-(2**7)].pack(format).should == encode("\x80", "binary")
- end
-
- it "reduces value to fit in byte" do
- [2**8-1].pack(format).should == encode("\xFF", "binary")
- [2**8 ].pack(format).should == encode("\x00", "binary")
- [2**8+1].pack(format).should == encode("\x01", "binary")
-
- [-2**8+1].pack(format).should == encode("\x01", "binary")
- [-2**8 ].pack(format).should == encode("\x00", "binary")
- [-2**8-1].pack(format).should == encode("\xFF", "binary")
- end
-
- it "tries to convert the pack argument to an Integer using #to_int" do
- [5.0].pack(format).should == encode("\x05", "binary")
-
- obj = mock('to_int')
- obj.should_receive(:to_int).and_return(5)
- [obj].pack(format).should == encode("\x05", "binary")
- end
-
- not_compliant_on :rubinius do
- ruby_version_is '' ... '1.9' do
- it "accepts a Symbol as a pack argument because it responds to #to_int" do
- [:hello].pack(format).should == [:hello.to_i].pack('C')
- end
- end
- end
-
- it "raises a TypeError if a pack argument can't be coerced to Integer" do
- lambda { ["5"].pack(format) }.should raise_error(TypeError)
-
- obj = mock('not an integer')
- lambda { [obj].pack(format) }.should raise_error(TypeError)
- end
-
- it "processes count number of array elements if count given" do
- [1, 2, 3].pack(format(3)).should == encode("\x01\x02\x03", "binary")
- [1, 2, 3].pack(format(2) + format(1)).should == encode("\x01\x02\x03", "binary")
- end
-
- it "returns empty string if count = 0" do
- [1, 2, 3].pack(format(0)).should == encode('', "binary")
- end
-
- it "with star parameter processes all remaining array items" do
- [1, 2, 3, 4, 5].pack(format('*')).should == encode("\x01\x02\x03\x04\x05", "binary")
- end
-
- it "raises an ArgumentError if count is greater than array elements left" do
- lambda { [1, 2].pack(format(3)) }.should raise_error(ArgumentError)
- end
-
- ruby_version_is '1.9' do
- it "returns an ASCII-8BIT string" do
- [0x41].pack(format).encoding.should == Encoding::ASCII_8BIT
- [0xFF].pack(format).encoding.should == Encoding::ASCII_8BIT
- [0xE3, 0x81, 0x82].pack(format(3)).encoding.should == Encoding::ASCII_8BIT
- end
- end
-end
-
-describe "Array#pack with integer format (16bit, little endian)", :shared => true do
- before do
- @format = @method
- def self.format(count = nil)
- "#{@format}#{count}"
- end
- end
-
- it "returns a string containing 2 bytes for an integer" do
- [0].pack(format).should == encode("\x00\x00", "binary")
- [0xABCD].pack(format).should == encode("\xCD\xAB", "binary")
- end
-
- it "regards negative values as 2's complement in order to converts it to positive" do
- [-1].pack(format).should == encode("\xFF\xFF", "binary")
- [-2**15].pack(format).should == encode("\x00\x80", "binary")
- end
-
- it "drops higher bytes when a pack argument is >= 2**16" do
- [2**16-1].pack(format).should == encode("\xFF\xFF", "binary")
- [2**16 ].pack(format).should == encode("\x00\x00", "binary")
- [2**16+1].pack(format).should == encode("\x01\x00", "binary")
- end
- it "drops higher bytes when a pack argument is < -2**16" do
- [-2**16+1].pack(format).should == encode("\x01\x00", "binary") # 0x ..F 00 01
- [-2**16 ].pack(format).should == encode("\x00\x00", "binary") # 0x ..F 00 00
- [-2**16-1].pack(format).should == encode("\xFF\xFF", "binary") # 0x .FE FF FF
- end
-
- ruby_version_is '' ... '1.9' do
- platform_is :wordsize => 32 do
- it "may raise a RangeError when a pack argument is >= 2**32" do
- lambda { [2**32-1].pack(format) }.should_not raise_error(RangeError)
- lambda { [2**32].pack(format) }.should raise_error(RangeError)
- end
-
- it "may raise a RangeError when a pack argument is <= -2**32" do
- lambda { [-2**32+1].pack(format) }.should_not raise_error(RangeError)
- lambda { [-2**32].pack(format) }.should raise_error(RangeError)
- end
- end
- platform_is :wordsize => 64 do
- it "may raise a RangeError when a pack argument is >= 2**64" do
- lambda { [2**64-1].pack(format) }.should_not raise_error(RangeError)
- lambda { [2**64].pack(format) }.should raise_error(RangeError)
- end
-
- it "may raise a RangeError when a pack argument is <= -2**64" do
- lambda { [-2**64+1].pack(format) }.should_not raise_error(RangeError)
- lambda { [-2**64].pack(format) }.should raise_error(RangeError)
- end
- end
- end
- # feature changed by MRI r5542 - [ruby-dev:22654].
- ruby_version_is '1.9' do
- platform_is :wordsize => 32 do
- it "does not raise a RangeError even when a pack argument is >= 2**32" do
- [2**32-1].pack(format).should == encode("\xFF\xFF", "binary")
- [2**32 ].pack(format).should == encode("\x00\x00", "binary")
- [2**32+1].pack(format).should == encode("\x01\x00", "binary")
- end
-
- it "does not raise a RangeError even when a pack argument is <= -2**32" do
- [-2**32+1].pack(format).should == encode("\x01\x00", "binary")
- [-2**32 ].pack(format).should == encode("\x00\x00", "binary")
- [-2**32-1].pack(format).should == encode("\xFF\xFF", "binary")
- end
- end
- platform_is :wordsize => 64 do
- it "does not raise a RangeError even when a pack argument is >= 2**64" do
- [2**64-1].pack(format).should == encode("\xFF\xFF", "binary")
- [2**64 ].pack(format).should == encode("\x00\x00", "binary")
- [2**64+1].pack(format).should == encode("\x01\x00", "binary")
- end
-
- it "does not raise a RangeError even when a pack argument is <= -2**64" do
- [-2**64+1].pack(format).should == encode("\x01\x00", "binary")
- [-2**64 ].pack(format).should == encode("\x00\x00", "binary")
- [-2**64-1].pack(format).should == encode("\xFF\xFF", "binary")
- end
- end
- end
-
- it "tries to convert the pack argument to an Integer using #to_int" do
- [5.0].pack(format).should == encode("\x05\x00", "binary")
-
- obj = mock('to_int')
- obj.should_receive(:to_int).and_return(5)
- [obj].pack(format).should == encode("\x05\x00", "binary")
- end
-
- it "raises a TypeError if a pack argument can't be coerced to Integer" do
- lambda { ["5"].pack(format) }.should raise_error(TypeError)
-
- obj = mock('not an integer')
- lambda { [obj].pack(format) }.should raise_error(TypeError)
- end
-
- it "processes count number of array elements if count given" do
- [1, 2, 3].pack(format(3)).should == encode("\x01\x00\x02\x00\x03\x00", "binary")
- [1, 2, 3].pack(format(2) + format(1)).should == encode("\x01\x00\x02\x00\x03\x00", "binary")
- end
-
- it "returns empty string if count = 0" do
- [1, 2, 3].pack(format(0)).should == encode('', "binary")
- end
-
- it "with star parameter processes all remaining array items" do
- [1, 2, 3, 4, 5].pack(format('*')).should ==
- encode("\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00", "binary")
- end
-
- it "raises an ArgumentError if count is greater than array elements left" do
- lambda { [1, 2].pack(format(3)) }.should raise_error(ArgumentError)
- end
-
- ruby_version_is '1.9' do
- it "returns an ASCII-8BIT string" do
- [0x41].pack(format).encoding.should == Encoding::ASCII_8BIT
- [0xFF].pack(format).encoding.should == Encoding::ASCII_8BIT
- end
- end
-end
-
-describe "Array#pack with integer format (16bit, big endian)", :shared => true do
- before do
- @format = @method
- def self.format(count = nil)
- "#{@format}#{count}"
- end
- end
-
- it "returns a string containing 2 bytes for an integer" do
- [0].pack(format).should == encode("\x00\x00", "binary")
- [0xABCD].pack(format).should == encode("\xAB\xCD", "binary")
- end
-
- it "regards negative values as 2's complement in order to converts it to positive" do
- [-1].pack(format).should == encode("\xFF\xFF", "binary")
- [-2**15].pack(format).should == encode("\x80\x00", "binary")
- end
-
- it "drops higher bytes when a pack argument is >= 2**32" do
- [2**16-1].pack(format).should == encode("\xFF\xFF", "binary")
- [2**16 ].pack(format).should == encode("\x00\x00", "binary")
- [2**16+1].pack(format).should == encode("\x00\x01", "binary")
- end
-
- it "drops higher bytes when a pack argument is < -2**32" do
- [-2**16+1].pack(format).should == encode("\x00\x01", "binary") # 0x ..F 00 01
- [-2**16 ].pack(format).should == encode("\x00\x00", "binary") # 0x ..F 00 00
- [-2**16-1].pack(format).should == encode("\xFF\xFF", "binary") # 0x .FE FF FF
- end
-
- it "tries to convert the pack argument to an Integer using #to_int" do
- [5.0].pack(format).should == encode("\x00\x05", "binary")
-
- obj = mock('to_int')
- obj.should_receive(:to_int).and_return(5)
- [obj].pack(format).should == encode("\x00\x05", "binary")
- end
-
- ruby_version_is '' ... '1.9' do
- platform_is :wordsize => 32 do
- it "may raise a RangeError when a pack argument is >= 2**32" do
- lambda { [2**32-1].pack(format) }.should_not raise_error(RangeError)
- lambda { [2**32].pack(format) }.should raise_error(RangeError)
- end
-
- it "may raise a RangeError when a pack argument is <= -2**32" do
- lambda { [-2**32+1].pack(format) }.should_not raise_error(RangeError)
- lambda { [-2**32].pack(format) }.should raise_error(RangeError)
- end
- end
- platform_is :wordsize => 64 do
- it "may raise a RangeError when a pack argument is >= 2**64" do
- lambda { [2**64-1].pack(format) }.should_not raise_error(RangeError)
- lambda { [2**64].pack(format) }.should raise_error(RangeError)
- end
-
- it "may raise a RangeError when a pack argument is <= -2**64" do
- lambda { [-2**64+1].pack(format) }.should_not raise_error(RangeError)
- lambda { [-2**64].pack(format) }.should raise_error(RangeError)
- end
- end
- end
- # feature changed by MRI r5542 - [ruby-dev:22654].
- ruby_version_is '1.9' do
- platform_is :wordsize => 32 do
- it "does not raise a RangeError even when a pack argument is >= 2**32" do
- [2**32-1].pack(format).should == encode("\xFF\xFF", "binary")
- [2**32 ].pack(format).should == encode("\x00\x00", "binary")
- [2**32+1].pack(format).should == encode("\x00\x01", "binary")
- end
-
- it "does not raise a RangeError even when a pack argument is <= -2**32" do
- [-2**32+1].pack(format).should == encode("\x00\x01", "binary")
- [-2**32 ].pack(format).should == encode("\x00\x00", "binary")
- [-2**32-1].pack(format).should == encode("\xFF\xFF", "binary")
- end
- end
- platform_is :wordsize => 64 do
- it "does not raise a RangeError even when a pack argument is >= 2**64" do
- [2**64-1].pack(format).should == encode("\xFF\xFF", "binary")
- [2**64 ].pack(format).should == encode("\x00\x00", "binary")
- [2**64+1].pack(format).should == encode("\x00\x01", "binary")
- end
-
- it "does not raise a RangeError even when a pack argument is <= -2**64" do
- [-2**64+1].pack(format).should == encode("\x00\x01", "binary")
- [-2**64 ].pack(format).should == encode("\x00\x00", "binary")
- [-2**64-1].pack(format).should == encode("\xFF\xFF", "binary")
- end
- end
- end
-
- it "raises a TypeError if a pack argument can't be coerced to Integer" do
- lambda { ["5"].pack(format) }.should raise_error(TypeError)
-
- obj = mock('not an integer')
- lambda { [obj].pack(format) }.should raise_error(TypeError)
- end
-
- it "processes count number of array elements if count given" do
- [1, 2, 3].pack(format(3)).should == encode("\x00\x01\x00\x02\x00\x03", "binary")
- [1, 2, 3].pack(format(2) + format(1)).should == encode("\x00\x01\x00\x02\x00\x03", "binary")
- end
-
- it "returns empty string if count = 0" do
- [1, 2, 3].pack(format(0)).should == encode('', "binary")
- end
-
- it "with star parameter processes all remaining array items" do
- [1, 2, 3, 4, 5].pack(format('*')).should ==
- encode("\x00\x01\x00\x02\x00\x03\x00\x04\x00\x05", "binary")
- end
-
- it "raises an ArgumentError if count is greater than array elements left" do
- lambda { [1, 2].pack(format(3)) }.should raise_error(ArgumentError)
- end
-
- ruby_version_is '1.9' do
- it "returns an ASCII-8BIT string" do
- [0x41].pack(format).encoding.should == Encoding::ASCII_8BIT
- [0xFF].pack(format).encoding.should == Encoding::ASCII_8BIT
- end
- end
-end
-
-describe "Array#pack with integer format (32bit, little endian)", :shared => true do
- before do
- @format = @method
- def self.format(count = nil)
- "#{@format}#{count}"
- end
- end
-
- it "returns a string containing 4 bytes for an integer" do
- [0].pack(format).should == encode("\x00\x00\x00\x00", "binary")
- [0xABCDEF01].pack(format).should == encode("\x01\xEF\xCD\xAB", "binary")
- end
-
- ruby_version_is '' ... '1.9' do
- platform_is :wordsize => 32 do
- it "raises a RangeError when a pack argument is >= 2**32" do
- lambda { [2**32-1].pack(format) }.should_not raise_error(RangeError)
- lambda { [2**32].pack(format) }.should raise_error(RangeError)
- end
-
- it "raises a RangeError when a pack argument is <= -2**32" do
- lambda { [-2**32+1].pack(format) }.should_not raise_error(RangeError)
- lambda { [-2**32].pack(format) }.should raise_error(RangeError)
- end
- end
- platform_is :wordsize => 64 do
- it "drops higher bytes when a pack argument is >= 2**32" do
- [2**32-1].pack(format).should == encode("\xFF\xFF\xFF\xFF", "binary")
- [2**32 ].pack(format).should == encode("\x00\x00\x00\x00", "binary")
- [2**32+1].pack(format).should == encode("\x01\x00\x00\x00", "binary")
- end
-
- it "drops higher bytes when a pack argument is < -2**32" do
- [-2**32+1].pack(format).should == encode("\x01\x00\x00\x00", "binary") # 0x ..F 00 00 00 01
- [-2**32 ].pack(format).should == encode("\x00\x00\x00\x00", "binary") # 0x ..F 00 00 00 00
- [-2**32-1].pack(format).should == encode("\xFF\xFF\xFF\xFF", "binary") # 0x .FE FF FF FF FF
- end
- end
- end
- # feature changed by MRI r5542 - [ruby-dev:22654].
- ruby_version_is '1.9' do
- it "drops higher bytes when a pack argument is >= 2**32" do
- [2**32-1].pack(format).should == encode("\xFF\xFF\xFF\xFF", "binary")
- [2**32 ].pack(format).should == encode("\x00\x00\x00\x00", "binary")
- [2**32+1].pack(format).should == encode("\x01\x00\x00\x00", "binary")
- end
-
- it "drops higher bytes when a pack argument is < -2**32" do
- [-2**32+1].pack(format).should == encode("\x01\x00\x00\x00", "binary") # 0x ..F 00 00 00 01
- [-2**32 ].pack(format).should == encode("\x00\x00\x00\x00", "binary") # 0x ..F 00 00 00 00
- [-2**32-1].pack(format).should == encode("\xFF\xFF\xFF\xFF", "binary") # 0x .FE FF FF FF FF
- end
- end
-
- it "regards negative values as 2's complement in order to converts it to positive" do
- [-1].pack(format).should == encode("\xFF\xFF\xFF\xFF", "binary")
- [-2**31].pack(format).should == encode("\x00\x00\x00\x80", "binary")
- end
-
- it "tries to convert the pack argument to an Integer using #to_int" do
- [5.0].pack(format).should == encode("\x05\x00\x00\x00", "binary")
-
- obj = mock('to_int')
- obj.should_receive(:to_int).and_return(5)
- [obj].pack(format).should == encode("\x05\x00\x00\x00", "binary")
- end
-
- it "raises a TypeError if a pack argument can't be coerced to Integer" do
- lambda { ["5"].pack(format) }.should raise_error(TypeError)
-
- obj = mock('not an integer')
- lambda { [obj].pack(format) }.should raise_error(TypeError)
- end
-
- it "processes count number of array elements if count given" do
- [1, 2, 3].pack(format(3)).should == encode("\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00", "binary")
- [1, 2, 3].pack(format(2) + format(1)).should == encode("\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00", "binary")
- end
-
- it "returns empty string if count = 0" do
- [1, 2, 3].pack(format(0)).should == encode('', "binary")
- end
-
- it "with star parameter processes all remaining array items" do
- [1, 2, 3, 4, 5].pack(format('*')).should ==
- encode("\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00\x05\x00\x00\x00", "binary")
- end
-
- it "raises an ArgumentError if count is greater than array elements left" do
- lambda { [1, 2].pack(format(3)) }.should raise_error(ArgumentError)
- end
-
- ruby_version_is '1.9' do
- it "returns an ASCII-8BIT string" do
- [0x41].pack(format).encoding.should == Encoding::ASCII_8BIT
- [0xFF].pack(format).encoding.should == Encoding::ASCII_8BIT
- end
- end
-end
-
-describe "Array#pack with integer format (32bit, big endian)", :shared => true do
- before do
- @format = @method
- def self.format(count = nil)
- "#{@format}#{count}"
- end
- end
-
- it "returns a string containing 4 bytes for an integer" do
- [0].pack(format).should == encode("\x00\x00\x00\x00", "binary")
- [0xABCDEF01].pack(format).should == encode("\xAB\xCD\xEF\x01", "binary")
- end
-
- it "regards negative values as 2's complement in order to converts it to positive" do
- [-1].pack(format).should == encode("\xFF\xFF\xFF\xFF", "binary")
- [-2**31].pack(format).should == encode("\x80\x00\x00\x00", "binary")
- end
-
- ruby_version_is '' ... '1.9' do
- platform_is :wordsize => 32 do
- it "raises a RangeError when a pack argument is >= 2**32" do
- lambda { [2**32-1].pack(format) }.should_not raise_error(RangeError)
- lambda { [2**32].pack(format) }.should raise_error(RangeError)
- end
-
- it "raises a RangeError when a pack argument is <= -2**32" do
- lambda { [-2**32+1].pack(format) }.should_not raise_error(RangeError)
- lambda { [-2**32].pack(format) }.should raise_error(RangeError)
- end
- end
- platform_is :wordsize => 64 do
- it "drops higher bytes when a pack argument is >= 2**32" do
- [2**32-1].pack(format).should == encode("\xFF\xFF\xFF\xFF", "binary")
- [2**32 ].pack(format).should == encode("\x00\x00\x00\x00", "binary")
- [2**32+1].pack(format).should == encode("\x00\x00\x00\x01", "binary")
- end
-
- it "drops higher bytes when a pack argument is < -2**32" do
- [-2**32+1].pack(format).should == encode("\x00\x00\x00\x01", "binary") # 0x ..F 00 00 00 01
- [-2**32 ].pack(format).should == encode("\x00\x00\x00\x00", "binary") # 0x ..F 00 00 00 00
- [-2**32-1].pack(format).should == encode("\xFF\xFF\xFF\xFF", "binary") # 0x .FE FF FF FF FF
- end
- end
- end
- # feature changed by MRI r5542 - [ruby-dev:22654].
- ruby_version_is '1.9' do
- it "drops higher bytes when a pack argument is >= 2**32" do
- [2**32-1].pack(format).should == encode("\xFF\xFF\xFF\xFF", "binary")
- [2**32 ].pack(format).should == encode("\x00\x00\x00\x00", "binary")
- [2**32+1].pack(format).should == encode("\x00\x00\x00\x01", "binary")
- end
-
- it "drops higher bytes when a pack argument is < -2**32" do
- [-2**32+1].pack(format).should == encode("\x00\x00\x00\x01", "binary") # 0x ..F 00 00 00 01
- [-2**32 ].pack(format).should == encode("\x00\x00\x00\x00", "binary") # 0x ..F 00 00 00 00
- [-2**32-1].pack(format).should == encode("\xFF\xFF\xFF\xFF", "binary") # 0x .FE FF FF FF FF
- end
- end
-
- it "tries to convert the pack argument to an Integer using #to_int" do
- [5.0].pack(format).should == encode("\x00\x00\x00\x05", "binary")
-
- obj = mock('to_int')
- obj.should_receive(:to_int).and_return(5)
- [obj].pack(format).should == encode("\x00\x00\x00\x05", "binary")
- end
-
- it "raises a TypeError if a pack argument can't be coerced to Integer" do
- lambda { ["5"].pack(format) }.should raise_error(TypeError)
-
- obj = mock('not an integer')
- lambda { [obj].pack(format) }.should raise_error(TypeError)
- end
-
- it "processes count number of array elements if count given" do
- [1, 2, 3].pack(format(3)).should == encode("\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03", "binary")
- [1, 2, 3].pack(format(2) + format(1)).should == encode("\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03", "binary")
- end
-
- it "returns empty string if count = 0" do
- [1, 2, 3].pack(format(0)).should == encode('', "binary")
- end
-
- it "with star parameter processes all remaining array items" do
- [1, 2, 3, 4, 5].pack(format('*')).should ==
- encode("\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00\x05", "binary")
- end
-
- it "raises an ArgumentError if count is greater than array elements left" do
- lambda { [1, 2].pack(format(3)) }.should raise_error(ArgumentError)
- end
-
- ruby_version_is '1.9' do
- it "returns an ASCII-8BIT string" do
- [0x41].pack(format).encoding.should == Encoding::ASCII_8BIT
- [0xFF].pack(format).encoding.should == Encoding::ASCII_8BIT
- end
- end
-end
-
-describe "Array#pack with integer format (64bit, little endian)", :shared => true do
- before do
- @format = @method
- def self.format(count = nil)
- "#{@format}#{count}"
- end
- end
-
- it "returns a string containing 8 bytes for an integer" do
- [0].pack(format).should == encode("\x00\x00\x00\x00\x00\x00\x00\x00", "binary")
- [0xABCDEF0123456789].pack(format).should == encode("\x89\x67\x45\x23\x01\xEF\xCD\xAB", "binary")
- end
-
- it "regards negative values as 2's complement in order to converts it to positive" do
- [-1].pack(format).should == encode("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", "binary")
- [-2**63].pack(format).should == encode("\x00\x00\x00\x00\x00\x00\x00\x80", "binary")
- end
-
- ruby_version_is '' ... '1.9' do
- it "raises a RangeError when a pack argument is >= 2**64" do
- lambda { [2**64-1].pack(format) }.should_not raise_error(RangeError)
- lambda { [2**64].pack(format) }.should raise_error(RangeError)
- end
-
- it "raises a RangeError when a pack argument is <= -2**64" do
- lambda { [-2**64+1].pack(format) }.should_not raise_error(RangeError)
- lambda { [-2**64].pack(format) }.should raise_error(RangeError)
- end
- end
- # feature changed by MRI r5542 - [ruby-dev:22654].
- ruby_version_is '1.9' do
- it "drops higher bytes when a pack argument is >= 2**64" do
- [2**64-1].pack(format).should == encode("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", "binary")
- [2**64 ].pack(format).should == encode("\x00\x00\x00\x00\x00\x00\x00\x00", "binary")
- [2**64+1].pack(format).should == encode("\x01\x00\x00\x00\x00\x00\x00\x00", "binary")
- end
-
- it "drops higher bytes when a pack argument is < -2**64" do
- [-2**64+1].pack(format).should == encode("\x01\x00\x00\x00\x00\x00\x00\x00", "binary") # 0x ..F 00 00 00 00 00 00 00 01
- [-2**64 ].pack(format).should == encode("\x00\x00\x00\x00\x00\x00\x00\x00", "binary") # 0x ..F 00 00 00 00 00 00 00 00
- [-2**64-1].pack(format).should == encode("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", "binary") # 0x .FE FF FF FF FF FF FF FF FF
- end
- end
-
- it "tries to convert the pack argument to an Integer using #to_int" do
- [5.0].pack(format).should == encode("\x05\x00\x00\x00\x00\x00\x00\x00", "binary")
-
- obj = mock('to_int')
- obj.should_receive(:to_int).and_return(5)
- [obj].pack(format).should == encode("\x05\x00\x00\x00\x00\x00\x00\x00", "binary")
- end
-
- it "raises a TypeError if a pack argument can't be coerced to Integer" do
- lambda { ["5"].pack(format) }.should raise_error(TypeError)
-
- obj = mock('not an integer')
- lambda { [obj].pack(format) }.should raise_error(TypeError)
- end
-
- it "processes count number of array elements if count given" do
- [1, 2, 3].pack(format(3)).should == encode(
- "\x01\x00\x00\x00\x00\x00\x00\x00" +
- "\x02\x00\x00\x00\x00\x00\x00\x00" +
- "\x03\x00\x00\x00\x00\x00\x00\x00" , "binary")
- [1, 2, 3].pack(format(2) + format(1)).should == encode(
- "\x01\x00\x00\x00\x00\x00\x00\x00" +
- "\x02\x00\x00\x00\x00\x00\x00\x00" +
- "\x03\x00\x00\x00\x00\x00\x00\x00" , "binary")
- end
-
- it "returns empty string if count = 0" do
- [1, 2, 3].pack(format(0)).should == encode('', "binary")
- end
-
- it "with star parameter processes all remaining array items" do
- [1, 2, 3, 4, 5].pack(format('*')).should == encode(
- "\x01\x00\x00\x00\x00\x00\x00\x00" +
- "\x02\x00\x00\x00\x00\x00\x00\x00" +
- "\x03\x00\x00\x00\x00\x00\x00\x00" +
- "\x04\x00\x00\x00\x00\x00\x00\x00" +
- "\x05\x00\x00\x00\x00\x00\x00\x00" , "binary")
- end
-
- it "raises an ArgumentError if count is greater than array elements left" do
- lambda { [1, 2].pack(format(3)) }.should raise_error(ArgumentError)
- end
-
- ruby_version_is '1.9' do
- it "returns an ASCII-8BIT string" do
- [0x41].pack(format).encoding.should == Encoding::ASCII_8BIT
- [0xFF].pack(format).encoding.should == Encoding::ASCII_8BIT
- end
- end
-end
-
-describe "Array#pack with integer format (64bit, big endian)", :shared => true do
- before do
- @format = @method
- def self.format(count = nil)
- "#{@format}#{count}"
- end
- end
-
- it "returns a string containing 8 bytes for an integer" do
- [0].pack(format).should == encode("\x00\x00\x00\x00\x00\x00\x00\x00", "binary")
- [0xABCDEF0123456789].pack(format).should == encode("\xAB\xCD\xEF\x01\x23\x45\x67\x89", "binary")
- end
-
- it "regards negative values as 2's complement in order to converts it to positive" do
- [-1].pack(format).should == encode("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", "binary")
- [-2**63].pack(format).should == encode("\x80\x00\x00\x00\x00\x00\x00\x00", "binary")
- end
-
- ruby_version_is '' ... '1.9' do
- it "raises a RangeError when a pack argument is >= 2**64" do
- lambda { [2**64-1].pack(format) }.should_not raise_error(RangeError)
- lambda { [2**64].pack(format) }.should raise_error(RangeError)
- end
-
- it "raises a RangeError when a pack argument is <= -2**64" do
- lambda { [-2**64+1].pack(format) }.should_not raise_error(RangeError)
- lambda { [-2**64].pack(format) }.should raise_error(RangeError)
- end
- end
- # feature changed by MRI r5542 - [ruby-dev:22654].
- ruby_version_is '1.9' do
- it "drops higher bytes when a pack argument is >= 2**64" do
- [2**64-1].pack(format).should == encode("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", "binary")
- [2**64 ].pack(format).should == encode("\x00\x00\x00\x00\x00\x00\x00\x00", "binary")
- [2**64+1].pack(format).should == encode("\x00\x00\x00\x00\x00\x00\x00\x01", "binary")
- end
-
- it "drops higher bytes when a pack argument is < -2**64" do
- [-2**64+1].pack(format).should == encode("\x00\x00\x00\x00\x00\x00\x00\x01", "binary") # 0x ..F 00 00 00 00 00 00 00 01
- [-2**64 ].pack(format).should == encode("\x00\x00\x00\x00\x00\x00\x00\x00", "binary") # 0x ..F 00 00 00 00 00 00 00 00
- [-2**64-1].pack(format).should == encode("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", "binary") # 0x .FE FF FF FF FF FF FF FF FF
- end
- end
-
- it "tries to convert the pack argument to an Integer using #to_int" do
- [5.0].pack(format).should == encode("\x00\x00\x00\x00\x00\x00\x00\x05", "binary")
-
- obj = mock('to_int')
- obj.should_receive(:to_int).and_return(5)
- [obj].pack(format).should == encode("\x00\x00\x00\x00\x00\x00\x00\x05", "binary")
- end
-
- it "raises a TypeError if a pack argument can't be coerced to Integer" do
- lambda { ["5"].pack(format) }.should raise_error(TypeError)
-
- obj = mock('not an integer')
- lambda { [obj].pack(format) }.should raise_error(TypeError)
- end
-
- it "processes count number of array elements if count given" do
- [1, 2, 3].pack(format(3)).should == encode(
- "\x00\x00\x00\x00\x00\x00\x00\x01" +
- "\x00\x00\x00\x00\x00\x00\x00\x02" +
- "\x00\x00\x00\x00\x00\x00\x00\x03" , "binary")
- [1, 2, 3].pack(format(2) + format(1)).should == encode(
- "\x00\x00\x00\x00\x00\x00\x00\x01" +
- "\x00\x00\x00\x00\x00\x00\x00\x02" +
- "\x00\x00\x00\x00\x00\x00\x00\x03" , "binary")
- end
-
- it "returns empty string if count = 0" do
- [1, 2, 3].pack(format(0)).should == encode('', "binary")
- end
-
- it "with star parameter processes all remaining array items" do
- [1, 2, 3, 4, 5].pack(format('*')).should == encode(
- "\x00\x00\x00\x00\x00\x00\x00\x01" +
- "\x00\x00\x00\x00\x00\x00\x00\x02" +
- "\x00\x00\x00\x00\x00\x00\x00\x03" +
- "\x00\x00\x00\x00\x00\x00\x00\x04" +
- "\x00\x00\x00\x00\x00\x00\x00\x05" , "binary")
- end
-
- it "raises an ArgumentError if count is greater than array elements left" do
- lambda { [1, 2].pack(format(3)) }.should raise_error(ArgumentError)
- end
-
- ruby_version_is '1.9' do
- it "returns an ASCII-8BIT string" do
- [0x41].pack(format).encoding.should == Encoding::ASCII_8BIT
- [0xFF].pack(format).encoding.should == Encoding::ASCII_8BIT
- end
- end
-end
-
-
-
-# integer formats which has platform independent width and fixed byte order
-
-describe "Array#pack with format 'C'" do
- it_behaves_like "Array#pack with integer format (8bit)", 'C'
- it_behaves_like "Array#pack with integer format which can not have platform dependent width", 'C'
-end
-describe "Array#pack with format 'c'" do
- it_behaves_like "Array#pack with integer format (8bit)", 'c'
- it_behaves_like "Array#pack with integer format which can not have platform dependent width", 'c'
-end
-
-describe "Array#pack with format 'n'" do
- it_behaves_like "Array#pack with integer format (16bit, big endian)", 'n'
- it_behaves_like "Array#pack with integer format which can not have platform dependent width", 'n'
-end
-describe "Array#pack with format 'v'" do
- it_behaves_like "Array#pack with integer format (16bit, little endian)", 'v'
- it_behaves_like "Array#pack with integer format which can not have platform dependent width", 'v'
-end
-
-describe "Array#pack with format 'N'" do
- it_behaves_like "Array#pack with integer format (32bit, big endian)", 'N'
- it_behaves_like "Array#pack with integer format which can not have platform dependent width", 'N'
-end
-describe "Array#pack with format 'V'" do
- it_behaves_like "Array#pack with integer format (32bit, little endian)", 'V'
- it_behaves_like "Array#pack with integer format which can not have platform dependent width", 'V'
-end
-
-
-# integer formats which has platform independent width but endian dependent
-
-describe "Array#pack with format 's'" do
- big_endian { it_behaves_like "Array#pack with integer format (16bit, big endian)", 's' }
- little_endian { it_behaves_like "Array#pack with integer format (16bit, little endian)", 's' }
-end
-describe "Array#pack with format 'S'" do
- big_endian { it_behaves_like "Array#pack with integer format (16bit, big endian)", 'S' }
- little_endian { it_behaves_like "Array#pack with integer format (16bit, little endian)", 'S' }
-end
-
-describe "Array#pack with format 'l'" do
- big_endian { it_behaves_like "Array#pack with integer format (32bit, big endian)", 'l' }
- little_endian { it_behaves_like "Array#pack with integer format (32bit, little endian)", 'l' }
-end
-describe "Array#pack with format 'L'" do
- big_endian { it_behaves_like "Array#pack with integer format (32bit, big endian)", 'L' }
- little_endian { it_behaves_like "Array#pack with integer format (32bit, little endian)", 'L' }
-end
-
-describe "Array#pack with format 'q'" do
- big_endian { it_behaves_like "Array#pack with integer format (64bit, big endian)", 'q' }
- little_endian { it_behaves_like "Array#pack with integer format (64bit, little endian)", 'q' }
-end
-describe "Array#pack with format 'Q'" do
- big_endian { it_behaves_like "Array#pack with integer format (64bit, big endian)", 'Q' }
- little_endian { it_behaves_like "Array#pack with integer format (64bit, little endian)", 'Q' }
-end
-
-
-# integer formats which has platform depended width
-
-# signed short int
-describe "Array#pack with format 's!'" do
- platform_is :wordsize => 32 do
- big_endian { it_behaves_like "Array#pack with integer format (16bit, big endian)", 's!' }
- little_endian { it_behaves_like "Array#pack with integer format (16bit, little endian)", 's!' }
- end
- platform_is :wordsize => 64 do
- # TODO: Is there an architecture whose short int is 32bit width?
- big_endian { it_behaves_like "Array#pack with integer format (16bit, big endian)", 's!' }
- little_endian { it_behaves_like "Array#pack with integer format (16bit, little endian)", 's!' }
- end
-end
-describe "Array#pack with format 's_'" do
- platform_is :wordsize => 32 do
- big_endian { it_behaves_like "Array#pack with integer format (16bit, big endian)", 's_' }
- little_endian { it_behaves_like "Array#pack with integer format (16bit, little endian)", 's_' }
- end
- platform_is :wordsize => 64 do
- # TODO: Is there an architecture whose short int is 32bit width?
- big_endian { it_behaves_like "Array#pack with integer format (16bit, big endian)", 's_' }
- little_endian { it_behaves_like "Array#pack with integer format (16bit, little endian)", 's_' }
- end
-end
-# unsigned short int
-describe "Array#pack with format 'S!'" do
- platform_is :wordsize => 32 do
- big_endian { it_behaves_like "Array#pack with integer format (16bit, big endian)", 's' }
- little_endian { it_behaves_like "Array#pack with integer format (16bit, little endian)", 's' }
- end
- platform_is :wordsize => 64 do
- # TODO: Is there an architecture whose short int is 32bit width?
- big_endian { it_behaves_like "Array#pack with integer format (16bit, big endian)", 's' }
- little_endian { it_behaves_like "Array#pack with integer format (16bit, little endian)", 's' }
- end
-end
-describe "Array#pack with format 'S_'" do
- platform_is :wordsize => 32 do
- big_endian { it_behaves_like "Array#pack with integer format (16bit, big endian)", 'S_' }
- little_endian { it_behaves_like "Array#pack with integer format (16bit, little endian)", 'S_' }
- end
- platform_is :wordsize => 64 do
- # TODO: Is there an architecture whose short int is 32bit width?
- big_endian { it_behaves_like "Array#pack with integer format (16bit, big endian)", 'S_' }
- little_endian { it_behaves_like "Array#pack with integer format (16bit, little endian)", 'S_' }
- end
-end
-
-# signed int
-describe "Array#pack with format 'i'" do
- platform_is :wordsize => 32 do
- big_endian { it_behaves_like "Array#pack with integer format (32bit, big endian)", 'i' }
- little_endian { it_behaves_like "Array#pack with integer format (32bit, little endian)", 'i' }
- end
- platform_is :wordsize => 64 do
- # TODO: supporting ILP64 architechture
- big_endian { it_behaves_like "Array#pack with integer format (32bit, big endian)", 'i' }
- little_endian { it_behaves_like "Array#pack with integer format (32bit, little endian)", 'i' }
- end
-end
-describe "Array#pack with format 'i!'" do
- platform_is :wordsize => 32 do
- big_endian { it_behaves_like "Array#pack with integer format (32bit, big endian)", 'i!' }
- little_endian { it_behaves_like "Array#pack with integer format (32bit, little endian)", 'i!' }
- end
- platform_is :wordsize => 64 do
- # TODO: supporting ILP64 architechture
- big_endian { it_behaves_like "Array#pack with integer format (32bit, big endian)", 'i!' }
- little_endian { it_behaves_like "Array#pack with integer format (32bit, little endian)", 'i!' }
- end
-end
-describe "Array#pack with format 'i_'" do
- platform_is :wordsize => 32 do
- big_endian { it_behaves_like "Array#pack with integer format (32bit, big endian)", 'i_' }
- little_endian { it_behaves_like "Array#pack with integer format (32bit, little endian)", 'i_' }
- end
- platform_is :wordsize => 64 do
- # TODO: supporting ILP64 architechture
- big_endian { it_behaves_like "Array#pack with integer format (32bit, big endian)", 'i_' }
- little_endian { it_behaves_like "Array#pack with integer format (32bit, little endian)", 'i_' }
- end
-end
-
-# unsigned int
-describe "Array#pack with format 'I'" do
- platform_is :wordsize => 32 do
- big_endian { it_behaves_like "Array#pack with integer format (32bit, big endian)", 'I' }
- little_endian { it_behaves_like "Array#pack with integer format (32bit, little endian)", 'I' }
- end
- platform_is :wordsize => 64 do
- # TODO: supporting ILP64 architechture
- big_endian { it_behaves_like "Array#pack with integer format (32bit, big endian)", 'I' }
- little_endian { it_behaves_like "Array#pack with integer format (32bit, little endian)", 'I' }
- end
-end
-describe "Array#pack with format 'I!'" do
- platform_is :wordsize => 32 do
- big_endian { it_behaves_like "Array#pack with integer format (32bit, big endian)", 'I!' }
- little_endian { it_behaves_like "Array#pack with integer format (32bit, little endian)", 'I!' }
- end
- platform_is :wordsize => 64 do
- # TODO: supporting ILP64 architechture
- big_endian { it_behaves_like "Array#pack with integer format (32bit, big endian)", 'I!' }
- little_endian { it_behaves_like "Array#pack with integer format (32bit, little endian)", 'I!' }
- end
-end
-describe "Array#pack with format 'I_'" do
- platform_is :wordsize => 32 do
- big_endian { it_behaves_like "Array#pack with integer format (32bit, big endian)", 'I_' }
- little_endian { it_behaves_like "Array#pack with integer format (32bit, little endian)", 'I_' }
- end
- platform_is :wordsize => 64 do
- # TODO: supporting ILP64 architechture
- big_endian { it_behaves_like "Array#pack with integer format (32bit, big endian)", 'I_' }
- little_endian { it_behaves_like "Array#pack with integer format (32bit, little endian)", 'I_' }
- end
-end
-
-# signed long
-describe "Array#pack with format 'l!'" do
- platform_is :wordsize => 32 do
- big_endian { it_behaves_like "Array#pack with integer format (32bit, big endian)", 'l!' }
- little_endian { it_behaves_like "Array#pack with integer format (32bit, little endian)", 'l!' }
- end
- platform_is :wordsize => 64 do
- # TODO: Is there anything other LLP64 platform which ruby can run on?
- platform_is :os => :mswin do
- not_compliant_on :jruby do
- big_endian { it_behaves_like "Array#pack with integer format (32bit, big endian)", 'l!' }
- little_endian { it_behaves_like "Array#pack with integer format (32bit, little endian)", 'l!' }
- end
- deviates_on :jruby do
- big_endian { it_behaves_like "Array#pack with integer format (64bit, big endian)", 'l!' }
- little_endian { it_behaves_like "Array#pack with integer format (64bit, little endian)", 'l!' }
- end
- end
- platform_is_not :os => :mswin do
- big_endian { it_behaves_like "Array#pack with integer format (64bit, big endian)", 'l!' }
- little_endian { it_behaves_like "Array#pack with integer format (64bit, little endian)", 'l!' }
- end
- end
-end
-describe "Array#pack with format 'l_'" do
- platform_is :wordsize => 32 do
- big_endian { it_behaves_like "Array#pack with integer format (32bit, big endian)", 'l_' }
- little_endian { it_behaves_like "Array#pack with integer format (32bit, little endian)", 'l_' }
- end
- platform_is :wordsize => 64 do
- # TODO: Is there anything other LLP64 platform which ruby can run on?
- platform_is :os => :mswin do
- not_compliant_on :jruby do
- big_endian { it_behaves_like "Array#pack with integer format (32bit, big endian)", 'l_' }
- little_endian { it_behaves_like "Array#pack with integer format (32bit, little endian)", 'l_' }
- end
- deviates_on :jruby do
- big_endian { it_behaves_like "Array#pack with integer format (64bit, big endian)", 'l_' }
- little_endian { it_behaves_like "Array#pack with integer format (64bit, little endian)", 'l_' }
- end
- end
- platform_is_not :os => :mswin do
- big_endian { it_behaves_like "Array#pack with integer format (64bit, big endian)", 'l_' }
- little_endian { it_behaves_like "Array#pack with integer format (64bit, little endian)", 'l_' }
- end
- end