script_core 0.2.7 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (283) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/Gemfile +2 -2
  4. data/ext/enterprise_script_service/Rakefile +1 -1
  5. data/ext/enterprise_script_service/mruby/.github/workflows/build.yml +117 -74
  6. data/ext/enterprise_script_service/mruby/.github/workflows/codeql-analysis.yml +41 -37
  7. data/ext/enterprise_script_service/mruby/.github/workflows/lint.yml +23 -0
  8. data/ext/enterprise_script_service/mruby/.github/workflows/oss-fuzz.yml +27 -0
  9. data/ext/enterprise_script_service/mruby/.github/workflows/spell-checker.yml +17 -0
  10. data/ext/enterprise_script_service/mruby/.gitlab-ci.yml +3 -3
  11. data/ext/enterprise_script_service/mruby/.markdownlint.yml +16 -0
  12. data/ext/enterprise_script_service/mruby/.travis.yml +2 -2
  13. data/ext/enterprise_script_service/mruby/.yamllint +8 -0
  14. data/ext/enterprise_script_service/mruby/AUTHORS +3 -0
  15. data/ext/enterprise_script_service/mruby/CODEOWNERS +1 -0
  16. data/ext/enterprise_script_service/mruby/CONTRIBUTING.md +6 -13
  17. data/ext/enterprise_script_service/mruby/Doxyfile +4 -4
  18. data/ext/enterprise_script_service/mruby/LICENSE +1 -1
  19. data/ext/enterprise_script_service/mruby/Makefile +1 -1
  20. data/ext/enterprise_script_service/mruby/README.md +4 -14
  21. data/ext/enterprise_script_service/mruby/Rakefile +18 -108
  22. data/ext/enterprise_script_service/mruby/TODO.md +17 -0
  23. data/ext/enterprise_script_service/mruby/appveyor.yml +31 -25
  24. data/ext/enterprise_script_service/mruby/benchmark/bm_ao_render.rb +1 -1
  25. data/ext/enterprise_script_service/mruby/build_config.rb +9 -152
  26. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_ArduinoDue.rb → build_config/ArduinoDue.rb} +2 -19
  27. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_IntelEdison.rb → build_config/IntelEdison.rb} +2 -2
  28. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_IntelGalileo.rb → build_config/IntelGalileo.rb} +1 -18
  29. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_RX630.rb → build_config/RX630.rb} +2 -19
  30. data/ext/enterprise_script_service/mruby/build_config/android_arm64-v8a.rb +11 -0
  31. data/ext/enterprise_script_service/mruby/build_config/android_armeabi.rb +11 -0
  32. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_android_armeabi_v7a_neon_hard.rb → build_config/android_armeabi_v7a_neon_hard.rb} +0 -15
  33. data/ext/enterprise_script_service/mruby/build_config/bench.rb +11 -0
  34. data/ext/enterprise_script_service/mruby/build_config/boxing.rb +21 -0
  35. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_chipKITMax32.rb → build_config/chipKITMax32.rb} +2 -19
  36. data/ext/enterprise_script_service/mruby/{travis_config.rb → build_config/ci/gcc-clang.rb} +10 -10
  37. data/ext/enterprise_script_service/mruby/build_config/ci/msvc.rb +20 -0
  38. data/ext/enterprise_script_service/mruby/build_config/clang-asan.rb +11 -0
  39. data/ext/enterprise_script_service/mruby/build_config/cross-32bit.rb +14 -0
  40. data/ext/enterprise_script_service/mruby/build_config/default.rb +80 -0
  41. data/ext/enterprise_script_service/mruby/{examples/targets/build_config_dreamcast_shelf.rb → build_config/dreamcast_shelf.rb} +5 -19
  42. data/ext/enterprise_script_service/mruby/build_config/gameboyadvance.rb +73 -0
  43. data/ext/enterprise_script_service/mruby/build_config/host-cxx.rb +12 -0
  44. data/ext/enterprise_script_service/mruby/build_config/host-debug.rb +20 -0
  45. data/ext/enterprise_script_service/mruby/build_config/host-gprof.rb +14 -0
  46. data/ext/enterprise_script_service/mruby/build_config/host-m32.rb +15 -0
  47. data/ext/enterprise_script_service/mruby/build_config/host-shared.rb +36 -0
  48. data/ext/enterprise_script_service/mruby/build_config/mrbc.rb +11 -0
  49. data/ext/enterprise_script_service/mruby/build_config/no-float.rb +17 -0
  50. data/ext/enterprise_script_service/mruby/doc/guides/compile.md +138 -49
  51. data/ext/enterprise_script_service/mruby/doc/guides/debugger.md +5 -4
  52. data/ext/enterprise_script_service/mruby/doc/guides/gc-arena-howto.md +1 -1
  53. data/ext/enterprise_script_service/mruby/doc/guides/mrbconf.md +49 -22
  54. data/ext/enterprise_script_service/mruby/doc/guides/mrbgems.md +31 -14
  55. data/ext/enterprise_script_service/mruby/doc/guides/symbol.md +83 -0
  56. data/ext/enterprise_script_service/mruby/doc/limitations.md +35 -36
  57. data/ext/enterprise_script_service/mruby/doc/mruby3.md +163 -0
  58. data/ext/enterprise_script_service/mruby/doc/opcode.md +93 -107
  59. data/ext/enterprise_script_service/mruby/examples/mrbgems/c_and_ruby_extension_example/mrblib/example.rb +1 -1
  60. data/ext/enterprise_script_service/mruby/examples/mrbgems/c_and_ruby_extension_example/src/example.c +5 -1
  61. data/ext/enterprise_script_service/mruby/examples/mrbgems/c_extension_example/src/example.c +5 -1
  62. data/ext/enterprise_script_service/mruby/examples/mrbgems/ruby_extension_example/mrblib/example.rb +1 -1
  63. data/ext/enterprise_script_service/mruby/include/mrbconf.h +81 -62
  64. data/ext/enterprise_script_service/mruby/include/mruby.h +137 -96
  65. data/ext/enterprise_script_service/mruby/include/mruby/array.h +23 -6
  66. data/ext/enterprise_script_service/mruby/include/mruby/boxing_nan.h +73 -48
  67. data/ext/enterprise_script_service/mruby/include/mruby/boxing_no.h +8 -8
  68. data/ext/enterprise_script_service/mruby/include/mruby/boxing_word.h +79 -48
  69. data/ext/enterprise_script_service/mruby/include/mruby/class.h +10 -8
  70. data/ext/enterprise_script_service/mruby/include/mruby/common.h +4 -1
  71. data/ext/enterprise_script_service/mruby/include/mruby/compile.h +13 -7
  72. data/ext/enterprise_script_service/mruby/include/mruby/debug.h +2 -2
  73. data/ext/enterprise_script_service/mruby/include/mruby/dump.h +17 -35
  74. data/ext/enterprise_script_service/mruby/include/mruby/endian.h +44 -0
  75. data/ext/enterprise_script_service/mruby/include/mruby/error.h +39 -5
  76. data/ext/enterprise_script_service/mruby/include/mruby/gc.h +1 -0
  77. data/ext/enterprise_script_service/mruby/include/mruby/hash.h +33 -13
  78. data/ext/enterprise_script_service/mruby/include/mruby/irep.h +64 -14
  79. data/ext/enterprise_script_service/mruby/include/mruby/khash.h +6 -14
  80. data/ext/enterprise_script_service/mruby/include/mruby/numeric.h +36 -63
  81. data/ext/enterprise_script_service/mruby/include/mruby/opcode.h +1 -27
  82. data/ext/enterprise_script_service/mruby/include/mruby/ops.h +27 -23
  83. data/ext/enterprise_script_service/mruby/include/mruby/presym.h +40 -0
  84. data/ext/enterprise_script_service/mruby/include/mruby/presym/disable.h +70 -0
  85. data/ext/enterprise_script_service/mruby/include/mruby/presym/enable.h +37 -0
  86. data/ext/enterprise_script_service/mruby/include/mruby/presym/scanning.h +73 -0
  87. data/ext/enterprise_script_service/mruby/include/mruby/proc.h +80 -13
  88. data/ext/enterprise_script_service/mruby/include/mruby/string.h +10 -15
  89. data/ext/enterprise_script_service/mruby/include/mruby/throw.h +14 -3
  90. data/ext/enterprise_script_service/mruby/include/mruby/value.h +29 -19
  91. data/ext/enterprise_script_service/mruby/include/mruby/variable.h +1 -0
  92. data/ext/enterprise_script_service/mruby/include/mruby/version.h +26 -7
  93. data/ext/enterprise_script_service/mruby/lib/mruby/build.rb +198 -44
  94. data/ext/enterprise_script_service/mruby/lib/mruby/build/command.rb +55 -37
  95. data/ext/enterprise_script_service/mruby/lib/mruby/build/load_gems.rb +12 -10
  96. data/ext/enterprise_script_service/mruby/lib/{mruby-core-ext.rb → mruby/core_ext.rb} +10 -3
  97. data/ext/enterprise_script_service/mruby/lib/mruby/gem.rb +75 -32
  98. data/ext/enterprise_script_service/mruby/lib/mruby/lockfile.rb +1 -1
  99. data/ext/enterprise_script_service/mruby/lib/mruby/presym.rb +132 -0
  100. data/ext/enterprise_script_service/mruby/mrbgems/default-no-fpu.gembox +3 -0
  101. data/ext/enterprise_script_service/mruby/mrbgems/default-no-stdio.gembox +4 -0
  102. data/ext/enterprise_script_service/mruby/mrbgems/default.gembox +9 -88
  103. data/ext/enterprise_script_service/mruby/mrbgems/full-core.gembox +1 -4
  104. data/ext/enterprise_script_service/mruby/mrbgems/math.gembox +10 -0
  105. data/ext/enterprise_script_service/mruby/mrbgems/metaprog.gembox +15 -0
  106. data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/mrblib/array.rb +1 -1
  107. data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/src/array.c +5 -4
  108. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-config/mrbgem.rake +28 -19
  109. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-config/mruby-config +18 -8
  110. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/bintest/mrdb.rb +3 -6
  111. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/bintest/print.rb +10 -10
  112. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c +14 -9
  113. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apiprint.c +3 -2
  114. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.c +4 -3
  115. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.h +2 -6
  116. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdbconf.h +4 -4
  117. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mirb/bintest/mirb.rb +23 -5
  118. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mirb/mrbgem.rake +11 -2
  119. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +41 -34
  120. data/ext/enterprise_script_service/mruby/mrbgems/{mruby-compiler → mruby-bin-mrbc}/bintest/mrbc.rb +0 -0
  121. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mrbc/mrbgem.rake +3 -4
  122. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mrbc/tools/mrbc/mrbc.c +19 -9
  123. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/bintest/mruby.rb +25 -4
  124. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/mrbgem.rake +1 -1
  125. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c +22 -6
  126. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-strip/bintest/mruby-strip.rb +1 -1
  127. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-strip/tools/mruby-strip/mruby-strip.c +2 -2
  128. data/ext/enterprise_script_service/mruby/mrbgems/mruby-catch/mrbgem.rake +5 -0
  129. data/ext/enterprise_script_service/mruby/mrbgems/mruby-catch/mrblib/catch.rb +27 -0
  130. data/ext/enterprise_script_service/mruby/mrbgems/mruby-class-ext/src/class.c +2 -1
  131. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/codegen.c +430 -399
  132. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/keywords +5 -0
  133. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/lex.def +49 -44
  134. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/parse.y +559 -217
  135. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/y.tab.c +4774 -4193
  136. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/mrbgem.rake +18 -19
  137. data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/mrblib/complex.rb +1 -1
  138. data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/src/complex.c +8 -7
  139. data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/test/complex.rb +4 -4
  140. data/ext/enterprise_script_service/mruby/mrbgems/mruby-enumerator/mrblib/enumerator.rb +1 -0
  141. data/ext/enterprise_script_service/mruby/mrbgems/mruby-enumerator/test/enumerator.rb +2 -2
  142. data/ext/enterprise_script_service/mruby/mrbgems/mruby-error/mrbgem.rake +2 -2
  143. data/ext/enterprise_script_service/mruby/mrbgems/mruby-eval/src/eval.c +17 -25
  144. data/ext/enterprise_script_service/mruby/mrbgems/mruby-fiber/src/fiber.c +18 -13
  145. data/ext/enterprise_script_service/mruby/mrbgems/mruby-hash-ext/src/hash-ext.c +30 -2
  146. data/ext/enterprise_script_service/mruby/mrbgems/mruby-hash-ext/test/hash.rb +7 -0
  147. data/ext/enterprise_script_service/mruby/mrbgems/mruby-inline-struct/test/inline.c +2 -2
  148. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/README.md +18 -16
  149. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/include/mruby/ext/io.h +2 -2
  150. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/file.rb +9 -4
  151. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/io.rb +2 -2
  152. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/file.c +55 -52
  153. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/file_test.c +4 -2
  154. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/io.c +99 -87
  155. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/file.rb +2 -0
  156. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/io.rb +2 -3
  157. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/mruby_io_test.c +1 -1
  158. data/ext/enterprise_script_service/mruby/mrbgems/mruby-kernel-ext/src/kernel.c +7 -6
  159. data/ext/enterprise_script_service/mruby/mrbgems/mruby-math/src/math.c +13 -12
  160. data/ext/enterprise_script_service/mruby/mrbgems/mruby-math/test/math.rb +5 -4
  161. data/ext/enterprise_script_service/mruby/mrbgems/mruby-metaprog/src/metaprog.c +43 -58
  162. data/ext/enterprise_script_service/mruby/mrbgems/mruby-metaprog/test/metaprog.rb +4 -4
  163. data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/README.md +4 -3
  164. data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/src/method.c +77 -74
  165. data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/test/method.rb +4 -4
  166. data/ext/enterprise_script_service/mruby/mrbgems/mruby-numeric-ext/src/numeric_ext.c +14 -13
  167. data/ext/enterprise_script_service/mruby/mrbgems/mruby-object-ext/src/object.c +5 -4
  168. data/ext/enterprise_script_service/mruby/mrbgems/mruby-objectspace/src/mruby_objectspace.c +18 -12
  169. data/ext/enterprise_script_service/mruby/mrbgems/mruby-os-memsize/mrbgem.rake +10 -0
  170. data/ext/enterprise_script_service/mruby/mrbgems/mruby-os-memsize/src/memsize.c +231 -0
  171. data/ext/enterprise_script_service/mruby/mrbgems/mruby-os-memsize/test/memsize.rb +63 -0
  172. data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/README.md +15 -18
  173. data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/src/pack.c +38 -88
  174. data/ext/enterprise_script_service/mruby/mrbgems/mruby-print/mrblib/print.rb +1 -30
  175. data/ext/enterprise_script_service/mruby/mrbgems/mruby-print/src/print.c +62 -26
  176. data/ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/src/proc.c +32 -19
  177. data/ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/test/proc.c +1 -1
  178. data/ext/enterprise_script_service/mruby/mrbgems/mruby-random/src/random.c +98 -43
  179. data/ext/enterprise_script_service/mruby/mrbgems/mruby-random/test/random.rb +2 -2
  180. data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/mrblib/range.rb +39 -6
  181. data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/src/range.c +20 -40
  182. data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/test/range.rb +27 -3
  183. data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/mrblib/rational.rb +11 -17
  184. data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/src/rational.c +216 -38
  185. data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/test/rational.rb +6 -6
  186. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sleep/README.md +6 -4
  187. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sleep/src/mrb_sleep.c +4 -4
  188. data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/README.md +3 -2
  189. data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/src/socket.c +47 -45
  190. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/src/sprintf.c +102 -71
  191. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/test/sprintf.rb +4 -2
  192. data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/mrblib/string.rb +23 -1
  193. data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/src/string.c +13 -9
  194. data/ext/enterprise_script_service/mruby/mrbgems/mruby-struct/mrblib/struct.rb +1 -1
  195. data/ext/enterprise_script_service/mruby/mrbgems/mruby-struct/src/struct.c +18 -25
  196. data/ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/src/symbol.c +6 -5
  197. data/ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/test/symbol.rb +1 -1
  198. data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/README.md +0 -1
  199. data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/driver.c +5 -5
  200. data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/mrbgem.rake +16 -44
  201. data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/vformat.c +4 -4
  202. data/ext/enterprise_script_service/mruby/mrbgems/mruby-time/src/time.c +27 -27
  203. data/ext/enterprise_script_service/mruby/mrbgems/stdlib-ext.gembox +18 -0
  204. data/ext/enterprise_script_service/mruby/mrbgems/stdlib-io.gembox +12 -0
  205. data/ext/enterprise_script_service/mruby/mrbgems/stdlib.gembox +54 -0
  206. data/ext/enterprise_script_service/mruby/mrblib/10error.rb +4 -0
  207. data/ext/enterprise_script_service/mruby/mrblib/array.rb +17 -9
  208. data/ext/enterprise_script_service/mruby/mrblib/enum.rb +1 -1
  209. data/ext/enterprise_script_service/mruby/mrblib/hash.rb +0 -20
  210. data/ext/enterprise_script_service/mruby/mrblib/init_mrblib.c +0 -11
  211. data/ext/enterprise_script_service/mruby/mrblib/numeric.rb +36 -11
  212. data/ext/enterprise_script_service/mruby/mrblib/range.rb +25 -3
  213. data/ext/enterprise_script_service/mruby/oss-fuzz/mruby_proto_fuzzer.cpp +2 -2
  214. data/ext/enterprise_script_service/mruby/oss-fuzz/proto_to_ruby.h +1 -1
  215. data/ext/enterprise_script_service/mruby/src/array.c +43 -80
  216. data/ext/enterprise_script_service/mruby/src/backtrace.c +16 -17
  217. data/ext/enterprise_script_service/mruby/src/class.c +774 -182
  218. data/ext/enterprise_script_service/mruby/src/codedump.c +223 -198
  219. data/ext/enterprise_script_service/mruby/src/debug.c +6 -6
  220. data/ext/enterprise_script_service/mruby/src/dump.c +466 -141
  221. data/ext/enterprise_script_service/mruby/src/enum.c +1 -1
  222. data/ext/enterprise_script_service/mruby/src/error.c +36 -13
  223. data/ext/enterprise_script_service/mruby/src/etc.c +43 -34
  224. data/ext/enterprise_script_service/mruby/src/fmt_fp.c +5 -6
  225. data/ext/enterprise_script_service/mruby/src/gc.c +73 -71
  226. data/ext/enterprise_script_service/mruby/src/hash.c +1050 -707
  227. data/ext/enterprise_script_service/mruby/src/kernel.c +75 -220
  228. data/ext/enterprise_script_service/mruby/src/load.c +196 -166
  229. data/ext/enterprise_script_service/mruby/src/numeric.c +352 -314
  230. data/ext/enterprise_script_service/mruby/src/object.c +97 -90
  231. data/ext/enterprise_script_service/mruby/src/print.c +4 -3
  232. data/ext/enterprise_script_service/mruby/src/proc.c +48 -56
  233. data/ext/enterprise_script_service/mruby/src/range.c +45 -21
  234. data/ext/enterprise_script_service/mruby/src/state.c +25 -32
  235. data/ext/enterprise_script_service/mruby/src/string.c +59 -101
  236. data/ext/enterprise_script_service/mruby/src/symbol.c +121 -56
  237. data/ext/enterprise_script_service/mruby/src/value_array.h +1 -0
  238. data/ext/enterprise_script_service/mruby/src/variable.c +158 -158
  239. data/ext/enterprise_script_service/mruby/src/vm.c +617 -602
  240. data/ext/enterprise_script_service/mruby/tasks/benchmark.rake +6 -6
  241. data/ext/enterprise_script_service/mruby/tasks/bin.rake +23 -0
  242. data/ext/enterprise_script_service/mruby/tasks/core.rake +12 -0
  243. data/ext/enterprise_script_service/mruby/tasks/doc.rake +50 -38
  244. data/ext/enterprise_script_service/mruby/tasks/gitlab.rake +83 -77
  245. data/ext/enterprise_script_service/mruby/tasks/libmruby.rake +10 -1
  246. data/ext/enterprise_script_service/mruby/tasks/mrbgems.rake +13 -1
  247. data/ext/enterprise_script_service/mruby/tasks/mrblib.rake +40 -0
  248. data/ext/enterprise_script_service/mruby/tasks/presym.rake +44 -0
  249. data/ext/enterprise_script_service/mruby/tasks/test.rake +68 -0
  250. data/ext/enterprise_script_service/mruby/tasks/toolchains/gcc.rake +6 -5
  251. data/ext/enterprise_script_service/mruby/tasks/toolchains/openwrt.rake +10 -14
  252. data/ext/enterprise_script_service/mruby/tasks/toolchains/visualcpp.rake +17 -21
  253. data/ext/enterprise_script_service/mruby/test/bintest.rb +5 -5
  254. data/ext/enterprise_script_service/mruby/test/t/argumenterror.rb +16 -0
  255. data/ext/enterprise_script_service/mruby/test/t/array.rb +7 -3
  256. data/ext/enterprise_script_service/mruby/test/t/bs_literal.rb +1 -1
  257. data/ext/enterprise_script_service/mruby/test/t/float.rb +18 -8
  258. data/ext/enterprise_script_service/mruby/test/t/hash.rb +903 -281
  259. data/ext/enterprise_script_service/mruby/test/t/integer.rb +10 -38
  260. data/ext/enterprise_script_service/mruby/test/t/kernel.rb +1 -1
  261. data/ext/enterprise_script_service/mruby/test/t/literals.rb +50 -0
  262. data/ext/enterprise_script_service/mruby/test/t/module.rb +2 -2
  263. data/ext/enterprise_script_service/mruby/test/t/numeric.rb +1 -1
  264. data/ext/enterprise_script_service/mruby/test/t/range.rb +83 -1
  265. data/ext/enterprise_script_service/mruby/test/t/string.rb +4 -0
  266. data/ext/enterprise_script_service/mruby/test/t/superclass.rb +10 -10
  267. data/ext/enterprise_script_service/mruby/test/t/syntax.rb +24 -0
  268. data/ext/enterprise_script_service/mruby/test/t/vformat.rb +3 -3
  269. data/ext/enterprise_script_service/mruby_config.rb +2 -5
  270. data/ext/enterprise_script_service/mruby_engine.cpp +1 -1
  271. data/lib/script_core/version.rb +1 -1
  272. data/spec/script_core_spec.rb +13 -0
  273. metadata +61 -23
  274. data/ext/enterprise_script_service/mruby/.github/workflows/main.yml +0 -24
  275. data/ext/enterprise_script_service/mruby/TODO +0 -8
  276. data/ext/enterprise_script_service/mruby/appveyor_config.rb +0 -46
  277. data/ext/enterprise_script_service/mruby/benchmark/build_config_boxing.rb +0 -28
  278. data/ext/enterprise_script_service/mruby/examples/targets/build_config_android_arm64-v8a.rb +0 -26
  279. data/ext/enterprise_script_service/mruby/examples/targets/build_config_android_armeabi.rb +0 -26
  280. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/src/kernel.c +0 -30
  281. data/ext/enterprise_script_service/mruby/mrblib/mrblib.rake +0 -18
  282. data/ext/enterprise_script_service/mruby/src/crc.c +0 -39
  283. data/ext/enterprise_script_service/mruby/src/mruby_core.rake +0 -19
@@ -0,0 +1,68 @@
1
+ desc "build and run all mruby tests"
2
+ task :test => "test:build" do
3
+ Rake::Task["test:run"].invoke
4
+ end
5
+
6
+ namespace :test do |test_ns|
7
+ desc "build and run library tests"
8
+ task :lib => "build:lib" do
9
+ test_ns["run:lib"].invoke
10
+ end
11
+
12
+ desc "build and run command binaries tests"
13
+ task :bin => :all do
14
+ test_ns["run:bin"].invoke
15
+ end
16
+
17
+ desc "build all mruby tests"
18
+ task :build => "build:lib"
19
+
20
+ namespace :build do |test_build_ns|
21
+ desc "build library tests"
22
+ task :lib => :all do
23
+ MRuby.each_target{|build| build.gem(core: 'mruby-test')}
24
+ test_build_ns["lib_without_loading_gem"].invoke
25
+ end
26
+ end
27
+
28
+ desc "run all mruby tests"
29
+ task :run
30
+
31
+ namespace :run do
32
+ desc "run library tests"
33
+ task :lib
34
+
35
+ desc "run command binaries tests"
36
+ task :bin
37
+ end
38
+ end
39
+
40
+ MRuby.each_target do |build|
41
+ if build.test_enabled?
42
+ t = task "test:build:lib_without_loading_gem:#{build.name}" do
43
+ gem = build.gems["mruby-test"]
44
+ gem.setup
45
+ gem.setup_compilers
46
+ Rake::Task[build.define_installer_if_needed("mrbtest")].invoke
47
+ end
48
+ task "test:build:lib_without_loading_gem" => t
49
+
50
+ t = task "test:run:lib:#{build.name}" do
51
+ build.run_test
52
+ end
53
+ task "test:run" => t
54
+ task "test:run:lib" => t
55
+ end
56
+ if build.bintest_enabled?
57
+ t = task "test:run:bin:#{build.name}" do
58
+ build.run_bintest
59
+ end
60
+ task "test:run" => t
61
+ task "test:run:bin" => t
62
+ end
63
+ end
64
+
65
+ task :clean do
66
+ host = MRuby.targets["host"]
67
+ rm_f host.exefile("#{host.class.install_dir}/mrbtest") if host && host.test_enabled?
68
+ end
@@ -2,11 +2,12 @@
2
2
  default_command = params[:default_command] || 'gcc'
3
3
  compiler_flags = %w(-g -O3 -Wall -Wundef)
4
4
  c_mandatory_flags = %w(-std=gnu99)
5
- cxx_invalid_flags = %w(-Wdeclaration-after-statement -Werror-implicit-function-declaration)
5
+ cxx_invalid_flags = %w(-Werror-implicit-function-declaration)
6
+ compile_opt = '%{flags} -o "%{outfile}" "%{infile}"'
6
7
 
7
8
  [conf.cc, conf.objc, conf.asm, conf.cxx].each do |compiler|
8
9
  if compiler == conf.cxx
9
- compiler.command = ENV['CXX'] || default_command.sub(/cc|$/, '++')
10
+ compiler.command = ENV['CXX'] || conf.cc.command.sub(/g\Kcc|$/, '++')
10
11
  compiler.flags = [ENV['CXXFLAGS'] || ENV['CFLAGS'] || compiler_flags]
11
12
  else
12
13
  compiler.command = ENV['CC'] || default_command
@@ -14,7 +15,8 @@
14
15
  end
15
16
  compiler.option_include_path = %q[-I"%s"]
16
17
  compiler.option_define = '-D%s'
17
- compiler.compile_options = %q[%{flags} -MMD -o "%{outfile}" -c "%{infile}"]
18
+ compiler.compile_options = "-MMD -c #{compile_opt}"
19
+ compiler.preprocess_options = "-E -P #{compile_opt}"
18
20
  compiler.cxx_compile_flag = '-x c++ -std=gnu++03'
19
21
  compiler.cxx_exception_flag = '-fexceptions'
20
22
  compiler.cxx_invalid_flags = c_mandatory_flags + cxx_invalid_flags
@@ -35,8 +37,7 @@
35
37
  def cc.header_search_paths
36
38
  if @header_search_command != command
37
39
  result = `echo | #{build.filename command} -x#{@header_search_language} -Wp,-v - -fsyntax-only 2>&1`
38
- result = `echo | #{command} -x#{@header_search_language} -Wp,-v - -fsyntax-only 2>&1` if $?.exitstatus != 0
39
- return include_paths if $?.exitstatus != 0
40
+ return include_paths if $?.exitstatus != 0
40
41
 
41
42
  @frameworks = []
42
43
  @header_search_paths = result.lines.map { |v|
@@ -1,24 +1,20 @@
1
1
  # usage of environmental variables to set the
2
2
  # cross compiling toolchain proper
3
3
  MRuby::Toolchain.new(:openwrt) do |conf|
4
- [conf.cc, conf.objc, conf.asm].each do |cc|
5
- cc.command = ENV['TARGET_CC']
6
- cc.flags = ENV['TARGET_CFLAGS']
7
- cc.include_paths = ["#{MRUBY_ROOT}/include"]
4
+ [conf.cc, conf.cxx, conf.objc, conf.asm].each do |cc|
5
+ if cc == conf.cxx
6
+ cc.command = ENV['TARGET_CXX']
7
+ cc.flags = ENV['TARGET_CXXFLAGS']
8
+ else
9
+ cc.command = ENV['TARGET_CC']
10
+ cc.flags = ENV['TARGET_CFLAGS']
11
+ end
8
12
  cc.option_include_path = %q[-I"%s"]
9
13
  cc.option_define = '-D%s'
10
- cc.compile_options = %q[%{flags} -MMD -o "%{outfile}" -c "%{infile}"]
14
+ cc.compile_options = '%{flags} -MMD -o "%{outfile}" -c "%{infile}"'
15
+ cc.preprocess_options = '%{flags} -o "%{outfile}" -E -P "%{infile}"'
11
16
  end
12
17
 
13
- [conf.cxx].each do |cxx|
14
- cxx.command = ENV['TARGET_CXX']
15
- cxx.flags = ENV['TARGET_CXXFLAGS']
16
- cxx.include_paths = ["#{MRUBY_ROOT}/include"]
17
- cxx.option_include_path = %q[-I"%s"]
18
- cxx.option_define = '-D%s'
19
- cxx.compile_options = %q[%{flags} -MMD -o "%{outfile}" -c "%{infile}"]
20
- end
21
-
22
18
  conf.linker do |linker|
23
19
  linker.command = ENV['TARGET_CC']
24
20
  linker.flags = ENV['TARGET_LDFLAGS']
@@ -1,25 +1,21 @@
1
1
  MRuby::Toolchain.new(:visualcpp) do |conf, _params|
2
- conf.cc do |cc|
3
- cc.command = ENV['CC'] || 'cl.exe'
4
- # C4013: implicit function declaration
5
- cc.flags = [ENV['CFLAGS'] || %w(/c /nologo /W3 /we4013 /Zi /MD /O2 /D_CRT_SECURE_NO_WARNINGS)]
6
- cc.defines = %w(MRB_STACK_EXTEND_DOUBLING)
7
- cc.option_include_path = %q[/I"%s"]
8
- cc.option_define = '/D%s'
9
- cc.compile_options = %Q[%{flags} /Fo"%{outfile}" "%{infile}"]
10
- cc.cxx_compile_flag = '/TP'
11
- cc.cxx_exception_flag = '/EHs'
12
- end
13
-
14
- conf.cxx do |cxx|
15
- cxx.command = ENV['CXX'] || 'cl.exe'
16
- cxx.flags = [ENV['CXXFLAGS'] || ENV['CFLAGS'] || %w(/c /nologo /W3 /Zi /MD /O2 /EHs /D_CRT_SECURE_NO_WARNINGS)]
17
- cxx.defines = %w(MRB_STACK_EXTEND_DOUBLING)
18
- cxx.option_include_path = %q[/I"%s"]
19
- cxx.option_define = '/D%s'
20
- cxx.compile_options = %Q[%{flags} /Fo"%{outfile}" "%{infile}"]
21
- cxx.cxx_compile_flag = '/TP'
22
- cxx.cxx_exception_flag = '/EHs'
2
+ compiler_flags = %w(/nologo /W3 /MD /O2 /D_CRT_SECURE_NO_WARNINGS)
3
+ [conf.cc, conf.cxx].each do |compiler|
4
+ if compiler == conf.cc
5
+ compiler.command = ENV['CC'] || 'cl.exe'
6
+ # C4013: implicit function declaration
7
+ compiler.flags = [*(ENV['CFLAGS'] || compiler_flags + %w(/we4013))]
8
+ else
9
+ compiler.command = ENV['CXX'] || 'cl.exe'
10
+ compiler.flags = [*(ENV['CXXFLAGS'] || ENV['CFLAGS'] || compiler_flags + %w(/EHs))]
11
+ end
12
+ compiler.defines = %w(MRB_STACK_EXTEND_DOUBLING)
13
+ compiler.option_include_path = %q[/I"%s"]
14
+ compiler.option_define = '/D%s'
15
+ compiler.compile_options = %Q[/Zi /c /Fo"%{outfile}" %{flags} "%{infile}"]
16
+ compiler.preprocess_options = %Q[/EP %{flags} "%{infile}" > "%{outfile}"]
17
+ compiler.cxx_compile_flag = '/TP'
18
+ compiler.cxx_exception_flag = '/EHs'
23
19
  end
24
20
 
25
21
  conf.linker do |linker|
@@ -4,12 +4,12 @@
4
4
  GEMNAME = ""
5
5
 
6
6
  def cmd(s)
7
- case RbConfig::CONFIG['host_os']
8
- when /mswin(?!ce)|mingw|bccwin/
9
- "bin\\#{s}.exe"
10
- else
11
- "bin/#{s}"
7
+ path = s == "mrbc" ? ENV['MRBCFILE'] : "#{ENV['BUILD_DIR']}/bin/#{s}"
8
+ path = path.sub(/\.exe\z/, "")
9
+ if /mswin(?!ce)|mingw|bccwin/ =~ RbConfig::CONFIG['host_os']
10
+ path = "#{path}.exe".tr("/", "\\")
12
11
  end
12
+ path
13
13
  end
14
14
 
15
15
  def shellquote(s)
@@ -1,6 +1,13 @@
1
1
  ##
2
2
  # ArgumentError ISO Test
3
3
 
4
+ def assert_argnum_error(given, expected, &block)
5
+ assert("wrong number of arguments") do
6
+ message = "wrong number of arguments (given #{given}, expected #{expected})"
7
+ assert_raise_with_message(ArgumentError, message, &block)
8
+ end
9
+ end
10
+
4
11
  assert('ArgumentError', '15.2.24') do
5
12
  e2 = nil
6
13
  a = []
@@ -14,3 +21,12 @@
14
21
  assert_equal(Class, ArgumentError.class)
15
22
  assert_equal(ArgumentError, e2.class)
16
23
  end
24
+
25
+ assert("'wrong number of arguments' from mrb_get_args") do
26
+ assert_argnum_error(0, "1+"){__send__}
27
+ assert_argnum_error(0, 1..2){Object.const_defined?}
28
+ assert_argnum_error(3, 1..2){Object.const_defined?(:A, true, 2)}
29
+ assert_argnum_error(2, 0..1){{}.default(1, 2)}
30
+ assert_argnum_error(1, 2){Object.const_set(:B)}
31
+ assert_argnum_error(3, 2){Object.const_set(:C, 1, 2)}
32
+ end
@@ -5,7 +5,7 @@
5
5
  assert_equal(Class, Array.class)
6
6
  end
7
7
 
8
- assert('Array inclueded modules', '15.2.12.3') do
8
+ assert('Array included modules', '15.2.12.3') do
9
9
  assert_true(Array.include?(Enumerable))
10
10
  end
11
11
 
@@ -57,6 +57,7 @@ class SubArray < Array
57
57
  a = [ "a", "b", "c", "d", "e" ]
58
58
  assert_equal(["b", "c"], a[1,2])
59
59
  assert_equal(["b", "c", "d"], a[1..-2])
60
+ assert_equal(["b", "c", "d", "e"], a[1..])
60
61
  skip unless Object.const_defined?(:Float)
61
62
  assert_equal("b", a[1.1])
62
63
  end
@@ -92,6 +93,10 @@ class SubArray < Array
92
93
  a[2...4] = 6
93
94
  assert_equal([1,2,6,5], a)
94
95
 
96
+ a = [1,2,3,4,5]
97
+ a[2...] = 6
98
+ assert_equal([1,2,6], a)
99
+
95
100
  # passing self (#3274)
96
101
  a = [1,2,3]
97
102
  a[1,0] = a
@@ -372,8 +377,7 @@ class SubArray < Array
372
377
  assert('Array#hash', '15.2.12.5.35') do
373
378
  a = [ 1, 2, 3 ]
374
379
 
375
- #assert_true(a.hash.is_a? Integer)
376
- assert_true(a.hash.is_a? Integral) # mruby special
380
+ assert_true(a.hash.is_a? Integer)
377
381
  assert_equal([1,2].hash, [1,2].hash)
378
382
  end
379
383
 
@@ -34,5 +34,5 @@
34
34
  end
35
35
 
36
36
  assert('BS Literal 9') do
37
- assert_equal Fixnum, 1234.class
37
+ assert_equal Integer, 1234.class
38
38
  end
@@ -41,6 +41,11 @@
41
41
  assert_float(1.0 , a)
42
42
  assert_float(3.123456789, b)
43
43
  end
44
+ assert('Float#quo') do
45
+ a = 3.123456789.quo(3.123456789)
46
+
47
+ assert_float(1.0 , a)
48
+ end
44
49
 
45
50
  assert('Float#%', '15.2.9.3.5') do
46
51
  a = 3.125 % 3.125
@@ -207,15 +212,15 @@ def check_floats exp, act
207
212
  end
208
213
 
209
214
  assert('Float#to_s') do
210
- uses_float = 4e38.infinite? # enable MRB_USE_FLOAT?
215
+ uses_float = 4e38.infinite? # enable MRB_USE_FLOAT32?
211
216
 
212
217
  assert_equal("Infinity", Float::INFINITY.to_s)
213
218
  assert_equal("-Infinity", (-Float::INFINITY).to_s)
214
219
  assert_equal("NaN", Float::NAN.to_s)
215
- assert_equal("0", 0.0.to_s)
216
- assert_equal("-0", -0.0.to_s)
220
+ assert_equal("0.0", 0.0.to_s)
221
+ assert_equal("-0.0", -0.0.to_s)
217
222
  assert_equal("-3.25", -3.25.to_s)
218
- assert_equal("50", 50.0.to_s)
223
+ assert_equal("50.0", 50.0.to_s)
219
224
  assert_equal("0.0125", 0.0125.to_s)
220
225
  assert_equal("-0.0125", -0.0125.to_s)
221
226
  assert_equal("1.0e-10", 0.0000000001.to_s)
@@ -224,8 +229,8 @@ def check_floats exp, act
224
229
  assert_equal("-1.0e+20", -1e20.to_s)
225
230
  assert_equal("1.0e+16", 10000000000000000.0.to_s)
226
231
  assert_equal("-1.0e+16", -10000000000000000.0.to_s)
227
- assert_equal("100000", 100000.0.to_s)
228
- assert_equal("-100000", -100000.0.to_s)
232
+ assert_equal("100000.0", 100000.0.to_s)
233
+ assert_equal("-100000.0", -100000.0.to_s)
229
234
  if uses_float
230
235
  assert_equal("1.0e+08", 100000000.0.to_s)
231
236
  assert_equal("-1.0e+08", -100000000.0.to_s)
@@ -234,11 +239,16 @@ def check_floats exp, act
234
239
  else
235
240
  assert_equal("1.0e+15", 1000000000000000.0.to_s)
236
241
  assert_equal("-1.0e+15", -1000000000000000.0.to_s)
237
- assert_equal("100000000000000", 100000000000000.0.to_s)
238
- assert_equal("-100000000000000", -100000000000000.0.to_s)
242
+ assert_equal("100000000000000.0", 100000000000000.0.to_s)
243
+ assert_equal("-100000000000000.0", -100000000000000.0.to_s)
239
244
  end
240
245
  end
241
246
 
247
+ assert('Float#inspect') do
248
+ assert_equal("-3.25", -3.25.inspect)
249
+ assert_equal("50.0", 50.0.inspect)
250
+ end
251
+
242
252
  assert('Float#eql?') do
243
253
  assert_operator(5.0, :eql?, 5.0)
244
254
  assert_not_operator(5.0, :eql?, 5)
@@ -1,378 +1,1000 @@
1
1
  ##
2
2
  # Hash ISO Test
3
3
 
4
- assert('Hash', '15.2.13') do
5
- assert_equal Class, Hash.class
6
- end
4
+ class HashKey
5
+ attr_accessor :value, :error, :callback
7
6
 
8
- assert('Hash#==', '15.2.13.4.1') do
9
- assert_true({ 'abc' => 'abc' } == { 'abc' => 'abc' })
10
- assert_false({ 'abc' => 'abc' } == { 'cba' => 'cba' })
11
- assert_false({ :a => 1 } == true)
12
- skip unless Object.const_defined?(:Float)
13
- assert_true({ :equal => 1 } == { :equal => 1.0 })
14
- end
7
+ self.class.alias_method :[], :new
15
8
 
16
- assert('Hash#[]', '15.2.13.4.2') do
17
- a = { 'abc' => 'abc' }
9
+ def initialize(value, error: nil, callback: nil)
10
+ @value = value
11
+ @error = error
12
+ @callback = callback
13
+ end
18
14
 
19
- assert_equal 'abc', a['abc']
15
+ def ==(other)
16
+ @callback.(:==, self, other) if @callback
17
+ return raise_error(:==) if @error == true || @error == :==
18
+ other.kind_of?(self.class) && @value == other.value
19
+ end
20
20
 
21
- # Hash#[] should call #default (#3272)
22
- hash = {}
23
- def hash.default(k); self[k] = 1; end
24
- hash[:foo] += 1
21
+ def eql?(other)
22
+ @callback.(:eql?, self, other) if @callback
23
+ return raise_error(:eql?) if @error == true || @error == :eql?
24
+ other.kind_of?(self.class) && @value.eql?(other.value)
25
+ end
25
26
 
26
- assert_equal 2, hash[:foo]
27
- end
27
+ def hash
28
+ @callback.(:hash, self) if @callback
29
+ return raise_error(:hash) if @error == true || @error == :hash
30
+ @value % 3
31
+ end
28
32
 
29
- assert('Hash#[]=', '15.2.13.4.3') do
30
- a = Hash.new
31
- a['abc'] = 'abc'
33
+ def to_s
34
+ "#{self.class}[#{@value}]"
35
+ end
36
+ alias inspect to_s
32
37
 
33
- assert_equal 'abc', a['abc']
38
+ def raise_error(name)
39
+ raise "##{self}: #{name} error"
40
+ end
34
41
  end
35
42
 
36
- assert('Hash#clear', '15.2.13.4.4') do
37
- a = { 'abc' => 'abc' }
38
- a.clear
39
-
40
- assert_equal({ }, a)
43
+ class HashEntries < Array
44
+ self.class.alias_method :[], :new
45
+
46
+ def initialize(entries) self.replace(entries) end
47
+ def key(index, k=get=true) get ? self[index][0] : (self[index][0] = k) end
48
+ def value(index, v=get=true) get ? self[index][1] : (self[index][1] = v) end
49
+ def keys; map{|k, v| k} end
50
+ def values; map{|k, v| v} end
51
+ def each_key(&block) each{|k, v| block.(k)} end
52
+ def each_value(&block) each{|k, v| block.(v)} end
53
+ def dup2; self.class[*map{|k, v| [k.dup, v.dup]}] end
54
+ def to_s; "#{self.class}#{super}" end
55
+ alias inspect to_s
56
+
57
+ def hash_for(hash={}, &block)
58
+ each{|k, v| hash[k] = v}
59
+ block.(hash) if block
60
+ hash
61
+ end
41
62
  end
42
63
 
43
- assert('Hash#dup') do
44
- a = { 'a' => 1 }
45
- b = a.dup
46
- a['a'] = 2
47
- assert_equal({'a' => 1}, b)
48
-
49
- c = Hash.new { |h, k| h[k] = k.upcase }
50
- d = c.dup
51
- assert_equal("FOO", d["foo"])
64
+ def ar_entries
65
+ HashEntries[
66
+ [1, "one"],
67
+ [HashKey[2], :two],
68
+ [nil, :two],
69
+ [:one, 1],
70
+ ["&", "&amp;"],
71
+ [HashKey[6], :six],
72
+ [HashKey[5], :five], # same hash code as HashKey[2]
73
+ ]
74
+ end
75
+
76
+ def ht_entries
77
+ ar_entries.dup.push(
78
+ ["id", 32],
79
+ [:date, "2020-05-02"],
80
+ [200, "OK"],
81
+ ["modifiers", ["left_shift", "control"]],
82
+ [:banana, :yellow],
83
+ ["JSON", "JavaScript Object Notation"],
84
+ [:size, :large],
85
+ ["key_code", "h"],
86
+ ["h", 0x04],
87
+ [[3, 2, 1], "three, two, one"],
88
+ [:auto, true],
89
+ [HashKey[12], "December"],
90
+ [:path, "/path/to/file"],
91
+ [:name, "Ruby"],
92
+ )
93
+ end
94
+
95
+ def merge_entries!(entries1, entries2)
96
+ entries2.each do |k2, v2|
97
+ entry1 = entries1.find{|k1, _| k1.eql?(k2)}
98
+ entry1 ? (entry1[1] = v2) : (entries1 << [k2, v2])
99
+ end
100
+ entries1
101
+ end
102
+
103
+ def product(*arrays, &block)
104
+ sizes = Array.new(arrays.size+1, 1)
105
+ (arrays.size-1).downto(0){|i| sizes[i] = arrays[i].size * sizes[i+1]}
106
+ size = sizes[0]
107
+ results = Array.new(size){[]}
108
+ arrays.each_with_index do |array, arrays_i|
109
+ results_i = -1
110
+ (size / sizes[arrays_i]).times do
111
+ array.each do |v|
112
+ sizes[arrays_i+1].times{results[results_i+=1] << v}
113
+ end
114
+ end
115
+ end
116
+ results.each{block.(_1)}
52
117
  end
53
118
 
54
- assert('Hash#default', '15.2.13.4.5') do
55
- a = Hash.new
56
- b = Hash.new('abc')
57
- c = Hash.new {|s,k| s[k] = k}
58
-
59
- assert_nil a.default
60
- assert_equal 'abc', b.default
61
- assert_nil c.default
62
- assert_equal 'abc', c.default('abc')
119
+ def assert_iterator(exp, obj, meth)
120
+ params = []
121
+ obj.__send__(meth) {|param| params << param}
122
+ assert_equal(exp, params)
63
123
  end
64
124
 
65
- assert('Hash#default=', '15.2.13.4.6') do
66
- a = { 'abc' => 'abc' }
67
- a.default = 'cba'
68
-
69
- assert_equal 'abc', a['abc']
70
- assert_equal 'cba', a['notexist']
125
+ def assert_nothing_crashed(&block)
126
+ block.call rescue nil
127
+ pass
71
128
  end
72
129
 
73
- assert('Hash#default_proc', '15.2.13.4.7') do
74
- a = Hash.new
75
- b = Hash.new {|s,k| s[k] = k + k}
76
- c = b[2]
77
- d = b['cat']
78
-
79
- assert_nil a.default_proc
80
- assert_equal Proc, b.default_proc.class
81
- assert_equal 4, c
82
- assert_equal 'catcat', d
130
+ assert('Hash', '15.2.13') do
131
+ assert_equal(Class, Hash.class)
132
+ end
133
+
134
+ [[:==, '15.2.13.4.1'], [:eql?, '']].each do |meth, iso|
135
+ assert("Hash##{meth}", iso) do
136
+ cls = Class.new(Hash){attr_accessor :foo}
137
+ [ar_entries, ht_entries].each do |entries|
138
+ h1 = entries.hash_for
139
+ h2 = entries.dup.reverse!.hash_for
140
+ assert_operator(h1, meth, h2)
141
+ assert_operator(h1, meth, h1)
142
+ assert_not_operator(h1, meth, true)
143
+ assert_operator({}, meth, Hash.new)
144
+
145
+ h1 = entries.hash_for(cls.new(1)) {|h| h.foo = 1}
146
+ h2 = entries.hash_for(cls.new(2)) {|h| h.foo = 2}
147
+ assert_operator(h1, meth, h2)
148
+
149
+ h1 = entries.hash_for
150
+ h2 = entries.hash_for(cls.new)
151
+ assert_operator(h1, meth, h2)
152
+
153
+ h1 = (entries.dup << [:_k, 1]).hash_for
154
+ h2 = (entries.dup << [:_k, 2]).hash_for
155
+ assert_not_operator(h1, meth, h2)
156
+
157
+ h1 = (entries.dup << [:_k1, 0]).hash_for
158
+ h2 = (entries.dup << [:_k2, 0]).hash_for
159
+ assert_not_operator(h1, meth, h2)
160
+
161
+ h1 = entries.hash_for
162
+ h2 = (entries.dup << [:_k, 2]).hash_for
163
+ assert_not_operator(h1, meth, h2)
164
+
165
+ k1, v1 = HashKey[-1], HashKey[-2]
166
+ k2, v2 = HashKey[-1], HashKey[-2]
167
+ h1 = (entries.dup << [k1, v1]).hash_for
168
+ h2 = (entries.dup << [k2, v2]).hash_for
169
+ product([h1, h2], [k1, k2], %i[eql? hash]) do |h, k, m|
170
+ [k1, k2].each{_1.callback = nil}
171
+ k.callback = ->(name, *){h.clear if name == m}
172
+ assert_nothing_crashed{h1.__send__(meth, h2)}
173
+ end
174
+ product([h1, h2], [v1, v2]) do |h, v|
175
+ [v1, v2].each{_1.callback = nil}
176
+ v.callback = ->(name, *){h.clear if name == meth}
177
+ assert_nothing_crashed{h1.__send__(meth, h2)}
178
+ end
179
+
180
+ if Object.const_defined?(:Float)
181
+ h1 = (entries.dup << [-1, true]).hash_for
182
+ h2 = (entries.dup << [-1.0, true]).hash_for
183
+ assert_not_operator(h1, meth, h2)
184
+ h1 = (entries.dup << [-1.0, true]).hash_for
185
+ h2 = (entries.dup << [-1, true]).hash_for
186
+ assert_not_operator(h1, meth, h2)
187
+
188
+ h1 = (entries.dup << [:_k, 1]).hash_for
189
+ h2 = (entries.dup << [:_k, 1.0]).hash_for
190
+ if meth == :==
191
+ assert_operator(h1, meth, h2)
192
+ else
193
+ assert_not_operator(h1, meth, h2)
194
+ end
195
+ end
196
+ end
197
+ end
83
198
  end
84
199
 
85
- assert('Hash#delete', '15.2.13.4.8') do
86
- a = { 'abc' => 'ABC' }
87
- b = { 'abc' => 'ABC' }
88
- b_tmp_1 = false
89
- b_tmp_2 = false
90
-
91
- assert_equal 'ABC', a.delete('abc')
92
- b.delete('abc') do |k|
93
- b_tmp_1 = true
94
- end
95
- b.delete('abc') do |k|
96
- b_tmp_2 = true
200
+ assert('Hash#[]', '15.2.13.4.2') do
201
+ [ar_entries, ht_entries].each do |entries|
202
+ h = entries.hash_for
203
+ assert_equal(entries.size, h.size)
204
+ entries.each{|k, v| assert_equal(v, h[k])}
205
+ assert_equal(nil, h["_not_found_"])
206
+ assert_equal(nil, h[:_not_dound_])
207
+ assert_equal(nil, h[-2])
208
+
209
+ k = HashKey[-4]
210
+ h[HashKey[-1]] = -1
211
+ h[k] = -4
212
+ h.delete(k)
213
+ assert_equal(nil, h[k])
214
+
215
+ if Object.const_defined?(:Float)
216
+ h[-2] = 22
217
+ assert_equal(nil, h[-2.0])
218
+ h[-3.0] = 33
219
+ assert_equal(nil, h[-3])
220
+ assert_equal(33, h[-3.0])
221
+ end
222
+
223
+ k = HashKey[-2]
224
+ k.callback = ->(name, *){h.clear if name == :eql?}
225
+ assert_nothing_crashed{h[k]}
226
+ k.callback = ->(name, *){h.clear if name == :hash}
227
+ assert_nothing_crashed{h[k]}
97
228
  end
98
229
 
99
- assert_nil a.delete('cba')
100
- assert_false a.has_key?('abc')
101
- assert_false b_tmp_1
102
- assert_true b_tmp_2
230
+ # Hash#[] should call #default (#3272)
231
+ h = {}
232
+ def h.default(k); self[k] = 1; end
233
+ h[:foo] += 1
234
+ assert_equal(2, h[:foo])
235
+ end
236
+
237
+ [%w[[]= 3], %w[store 26]].each do |meth, no|
238
+ assert("Hash##{meth}", "15.2.13.4.#{no}") do
239
+ [{}, ht_entries.hash_for].each do |h|
240
+ # duplicated key
241
+ k = :_dup_key
242
+ h.__send__(meth, k, 1)
243
+ size = h.size
244
+ h.__send__(meth, k, 2)
245
+ assert_equal(size, h.size)
246
+ assert_equal(2, h[k])
247
+
248
+ # freeze string key
249
+ k = "_mutable"
250
+ h.__send__(meth, k, 1)
251
+ h_k = h.keys[-1]
252
+ assert_not_same(k, h_k)
253
+ assert_predicate(h_k, :frozen?)
254
+ assert_not_predicate(k, :frozen?)
255
+
256
+ # frozen string key
257
+ k = "_immutable".freeze
258
+ h.__send__(meth, k, 2)
259
+ h_k = h.keys[-1]
260
+ assert_same(k, h_k)
261
+ assert_predicate(h_k, :frozen?)
262
+
263
+ # numeric key
264
+ if Object.const_defined?(:Float)
265
+ h.__send__(meth, 3, :fixnum)
266
+ h.__send__(meth, 3.0, :float)
267
+ assert_equal(:fixnum, h[3])
268
+ assert_equal(:float, h[3.0])
269
+ h.__send__(meth, 4.0, :float)
270
+ h.__send__(meth, 4, :fixnum)
271
+ assert_equal(:fixnum, h[4])
272
+ assert_equal(:float, h[4.0])
273
+ end
274
+
275
+ # other key
276
+ k = [:_array]
277
+ h.__send__(meth, k, :_array)
278
+ h_k = h.keys[-1]
279
+ assert_same(k, h_k)
280
+ assert_not_predicate(h_k, :frozen?)
281
+ assert_not_predicate(k, :frozen?)
282
+
283
+ # deleted key
284
+ k1, k2, k3 = HashKey[-1], HashKey[-4], HashKey[-7] # same hash code
285
+ h.__send__(meth, k1, 1)
286
+ h.__send__(meth, k2, -4)
287
+ h.__send__(meth, k3, 73)
288
+ size = h.size
289
+ h.delete(k1)
290
+ h.delete(k2)
291
+ h.__send__(meth, k2, 40)
292
+ assert_equal(nil, h[k1])
293
+ assert_equal(40, h[k2])
294
+ assert_equal(73, h[k3])
295
+ assert_equal(size - 1, h.size)
296
+
297
+ # frozen
298
+ h.freeze
299
+ assert_raise(FrozenError){h.__send__(meth, -100, 1)}
300
+ end
301
+
302
+ [ar_entries.hash_for, ht_entries.hash_for].each do |h|
303
+ k = HashKey[-2]
304
+ k.callback = ->(name, *){h.clear if name == :eql?}
305
+ assert_nothing_crashed{h.__send__(meth, k, 2)}
306
+ k.callback = ->(name, *){h.clear if name == :hash}
307
+ assert_nothing_crashed{h.__send__(meth, k, 2)}
308
+ end
309
+ end
103
310
  end
104
311
 
105
- assert('Hash#each', '15.2.13.4.9') do
106
- a = { 'abc_key' => 'abc_value' }
107
- key = nil
108
- value = nil
109
-
110
- a.each do |k,v|
111
- key = k
112
- value = v
312
+ assert('Hash#clear', '15.2.13.4.4') do
313
+ [ar_entries, ht_entries].each do |entries|
314
+ h = entries.hash_for
315
+ assert_same(h, h.clear)
316
+ assert_equal(0, h.size)
317
+ assert_nil(h[entries.key(3)])
318
+
319
+ h.freeze
320
+ assert_raise(FrozenError){h.clear}
113
321
  end
114
322
 
115
- assert_equal 'abc_key', key
116
- assert_equal 'abc_value', value
323
+ h = {}.freeze
324
+ assert_raise(FrozenError){h.clear}
117
325
  end
118
326
 
119
- assert('Hash#each_key', '15.2.13.4.10') do
120
- a = { 'abc_key' => 'abc_value' }
121
- key = nil
122
-
123
- a.each_key do |k|
124
- key = k
327
+ assert('Hash#dup') do
328
+ cls = Class.new(Hash){attr_accessor :foo}
329
+ [ar_entries, ht_entries].each do |entries|
330
+ h1 = entries.hash_for(cls.new(61)){|h| h.foo = 23}.freeze
331
+ h2 = h1.dup
332
+ assert_not_predicate(h2, :frozen?)
333
+ assert_equal(h1.class, h2.class)
334
+ assert_equal(entries, h2.to_a)
335
+ assert_equal(23, h2.foo)
336
+ assert_equal(61, h2["_not_found_"])
337
+ h2[-10] = 10
338
+ assert_equal(10, h2[-10])
339
+ assert_not_operator(h1, :key?, -10)
340
+
341
+ h = entries.hash_for
342
+ k = HashKey[-1]
343
+ h[k] = 1
344
+ k.callback = ->(*){h.clear}
345
+ assert_nothing_crashed{h.dup}
125
346
  end
126
-
127
- assert_equal 'abc_key', key
128
347
  end
129
348
 
130
- assert('Hash#each_value', '15.2.13.4.11') do
131
- a = { 'abc_key' => 'abc_value' }
132
- value = nil
133
-
134
- a.each_value do |v|
135
- value = v
349
+ assert('Hash#default', '15.2.13.4.5') do
350
+ [ar_entries, ht_entries].each do |entries|
351
+ h = entries.hash_for(Hash.new)
352
+ assert_equal(nil, h.default)
353
+ assert_equal(nil, h.default(-2))
354
+
355
+ h = entries.hash_for(Hash.new(-88))
356
+ assert_equal(-88, h.default)
357
+ assert_equal(-88, h.default(-2))
358
+ assert_not_operator(h, :key?, -2)
359
+ assert_raise(ArgumentError){h.default(-2,-2)}
360
+
361
+ proc = ->(h, k){h[k] = k * 3}
362
+ h = entries.hash_for(Hash.new(proc))
363
+ assert_equal(proc, h.default(-2))
364
+
365
+ h = entries.hash_for(Hash.new(&proc))
366
+ assert_equal(nil, h.default)
367
+ assert_not_operator(h, :key?, -2)
368
+ assert_equal(-6, h.default(-2))
369
+ assert_equal(-6, h[-2])
370
+ h[-2] = -5
371
+ assert_equal(-6, h.default(-2))
372
+ assert_equal(-6, h[-2])
136
373
  end
137
-
138
- assert_equal 'abc_value', value
139
374
  end
140
375
 
141
- assert('Hash#empty?', '15.2.13.4.12') do
142
- a = { 'abc_key' => 'abc_value' }
143
- b = Hash.new
144
-
145
- assert_false a.empty?
146
- assert_true b.empty?
147
- end
376
+ assert('Hash#default=', '15.2.13.4.6') do
377
+ [ar_entries, ht_entries].each do |entries|
378
+ h = entries.hash_for(Hash.new)
379
+ h.default = 3
380
+ assert_equal(3, h[-2])
381
+ assert_equal(entries.value(0), h[entries.key(0)])
148
382
 
149
- assert('Hash#has_key?', '15.2.13.4.13') do
150
- a = { 'abc_key' => 'abc_value' }
151
- b = Hash.new
383
+ h.default = 4
384
+ assert_equal(4, h[-2])
152
385
 
153
- assert_true a.has_key?('abc_key')
154
- assert_false b.has_key?('cba')
155
- end
386
+ h.default = nil
387
+ assert_equal(nil, h[-2])
156
388
 
157
- assert('Hash#has_value?', '15.2.13.4.14') do
158
- a = { 'abc_key' => 'abc_value' }
159
- b = Hash.new
389
+ h.default = [5]
390
+ assert_same(h[-2], h[-3])
160
391
 
161
- assert_true a.has_value?('abc_value')
162
- assert_false b.has_value?('cba')
392
+ h.freeze
393
+ assert_raise(FrozenError){h.default = 3}
394
+ end
163
395
  end
164
396
 
165
- assert('Hash#include?', '15.2.13.4.15') do
166
- a = { 'abc_key' => 'abc_value' }
167
- b = Hash.new
168
-
169
- assert_true a.include?('abc_key')
170
- assert_false b.include?('cba')
397
+ assert('Hash#default_proc', '15.2.13.4.7') do
398
+ [ar_entries, ht_entries].each do |entries|
399
+ h = entries.hash_for({})
400
+ assert_nil(h.default_proc)
401
+
402
+ h = entries.hash_for(Hash.new(34))
403
+ assert_nil(h.default_proc)
404
+
405
+ h = entries.hash_for(Hash.new{|h, k| h[k] = k * 3})
406
+ proc = h.default_proc
407
+ assert_equal(Proc, proc.class)
408
+ assert_equal(6, proc.(h, 2))
409
+ assert_equal([2, 6], h.to_a[-1])
410
+ end
171
411
  end
172
412
 
173
- assert('Hash#initialize', '15.2.13.4.16') do
174
- # Testing initialize by new.
175
- h = Hash.new
176
- h2 = Hash.new(:not_found)
177
-
178
- assert_true h.is_a? Hash
179
- assert_equal({ }, h)
180
- assert_nil h["hello"]
181
- assert_equal :not_found, h2["hello"]
182
- end
413
+ assert('Hash#delete', '15.2.13.4.8') do
414
+ [ar_entries, ht_entries].each do |entries|
415
+ h = entries.hash_for
416
+ pairs = entries.dup
417
+ [0, 2, -1].each do |i|
418
+ k, v = pairs.delete_at(i)
419
+ assert_equal(v, h.delete(k))
420
+ assert_equal(nil, h[k])
421
+ assert_equal(false, h.key?(k))
422
+ end
423
+ [entries.key(0), "_not_found_"].each {|k|assert_equal(nil, h.delete(k))}
424
+ assert_equal(pairs.size, h.size)
425
+ assert_equal(pairs, h.to_a)
426
+ pairs.each {|k, v| assert_equal(v, h[k])}
427
+
428
+ h = entries.hash_for
429
+ pairs = entries.dup
430
+ [pairs.delete_at(1), ["_not_found_", "_default"]].each do |k, v|
431
+ assert_equal(v, h.delete(k){"_default"})
432
+ assert_equal(nil, h[k])
433
+ assert_equal(false, h.key?(k))
434
+ end
435
+ assert_equal(pairs.size, h.size)
436
+ assert_equal(pairs, h.to_a)
437
+ pairs.each {|k, v| assert_equal(v, h[k])}
438
+
439
+ if Object.const_defined?(:Float)
440
+ h = entries.dup.push([-5, 1], [-5.0, 2], [-6.0, 3], [-6, 4]).hash_for
441
+ assert_equal(1, h.delete(-5))
442
+ assert_equal(3, h.delete(-6.0))
443
+ end
444
+
445
+ # nil value with block
446
+ h = entries.hash_for
447
+ k = "_nil"
448
+ h[k] = nil
449
+ assert_equal(nil, h.delete(k){"blk"})
450
+ assert_equal(false, h.key?(k))
451
+
452
+ k = HashKey[-31, callback: ->(*){h.clear}]
453
+ assert_nothing_crashed{h.delete(k)}
454
+ end
183
455
 
184
- assert('Hash#initialize_copy', '15.2.13.4.17') do
185
- a = { 'abc_key' => 'abc_value' }
186
- b = Hash.new.initialize_copy(a)
456
+ assert_raise(ArgumentError){{}.delete}
457
+ assert_raise(ArgumentError){{}.delete(1,2)}
187
458
 
188
- assert_equal({ 'abc_key' => 'abc_value' }, b)
459
+ h = {}.freeze
460
+ assert_raise(FrozenError){h.delete(1)}
461
+ end
462
+
463
+ [%w[each 9], %w[each_key 10], %w[each_value 11]].each do |meth, no|
464
+ assert("Hash##{meth}", "15.2.13.4.#{no}") do
465
+ [ar_entries, ht_entries].each do |entries|
466
+ exp = []
467
+ entries.__send__(meth){|param| exp << param}
468
+ assert_iterator(exp, entries.hash_for, meth)
469
+
470
+ h = entries.hash_for
471
+ entries.shift
472
+ h.shift
473
+ entry = entries.delete_at(1)
474
+ h.delete(entry[0])
475
+ h.delete(entries.delete_at(-4)[0])
476
+ entries << entry
477
+ h.store(*entry)
478
+ exp = []
479
+ entries.__send__(meth){|param| exp << param}
480
+ assert_iterator(exp, h, meth)
481
+ end
482
+
483
+ assert_iterator([], {}, meth)
484
+ end
189
485
  end
190
486
 
191
- assert('Hash#key?', '15.2.13.4.18') do
192
- a = { 'abc_key' => 'abc_value' }
193
- b = Hash.new
487
+ assert('Hash#empty?', '15.2.13.4.12') do
488
+ [ar_entries, ht_entries].each do |entries|
489
+ assert_not_predicate entries.hash_for, :empty?
194
490
 
195
- assert_true a.key?('abc_key')
196
- assert_false b.key?('cba')
197
- end
491
+ h = entries.hash_for
492
+ h.shift
493
+ h.delete(entries.key(-1))
494
+ assert_not_predicate h, :empty?
198
495
 
199
- assert('Hash#keys', '15.2.13.4.19') do
200
- a = { 'abc_key' => 'abc_value' }
496
+ h = entries.hash_for
497
+ entries.size.times{h.shift}
498
+ assert_predicate(h, :empty?)
201
499
 
202
- assert_equal ['abc_key'], a.keys
203
- end
204
-
205
- assert('Hash#length', '15.2.13.4.20') do
206
- a = { 'abc_key' => 'abc_value' }
207
- b = Hash.new
500
+ h = entries.hash_for
501
+ entries.each {|k, v| h.delete(k)}
502
+ assert_predicate(h, :empty?)
503
+ end
208
504
 
209
- assert_equal 1, a.length
210
- assert_equal 0, b.length
505
+ assert_predicate(Hash.new, :empty?)
506
+ assert_predicate(Hash.new(1), :empty?)
507
+ assert_predicate(Hash.new{|h, k| h[k] = 2}, :empty?)
211
508
  end
212
509
 
213
- assert('Hash#member?', '15.2.13.4.21') do
214
- a = { 'abc_key' => 'abc_value' }
215
- b = Hash.new
216
-
217
- assert_true a.member?('abc_key')
218
- assert_false b.member?('cba')
219
- end
510
+ [%w[has_key? 13], %w[include? 15], %w[key? 18], %w[member? 21]].each do |meth,no|
511
+ assert("Hash##{meth}", "15.2.13.4.#{no}") do
512
+ [ar_entries, ht_entries].each do |entries|
513
+ pairs = entries.dup.push([HashKey[-3], 3], [nil, "NIL"])
514
+ h = pairs.hash_for
515
+ pairs.each{|k, v| assert_operator(h, meth, k)}
516
+ assert_not_operator(h, meth, HashKey[-6])
517
+ assert_not_operator(h, meth, 3)
220
518
 
221
- assert('Hash#merge', '15.2.13.4.22') do
222
- a = { 'abc_key' => 'abc_value', 'cba_key' => 'cba_value' }
223
- b = { 'cba_key' => 'XXX', 'xyz_key' => 'xyz_value' }
519
+ if Object.const_defined?(:Float)
520
+ hh = entries.push([-7, :i], [-8.0, :f]).hash_for
521
+ assert_not_operator(hh, meth, -7.0)
522
+ assert_not_operator(hh, meth, -8)
523
+ assert_operator(hh, meth, -8.0)
524
+ end
224
525
 
225
- result_1 = a.merge b
226
- result_2 = a.merge(b) do |key, original, new|
227
- original
228
- end
526
+ h.shift
527
+ assert_not_operator(h, meth, pairs.key(0))
229
528
 
230
- assert_equal({'abc_key' => 'abc_value', 'cba_key' => 'XXX',
231
- 'xyz_key' => 'xyz_value' }, result_1)
232
- assert_equal({'abc_key' => 'abc_value', 'cba_key' => 'cba_value',
233
- 'xyz_key' => 'xyz_value' }, result_2)
529
+ h.delete(pairs.key(3))
530
+ assert_not_operator(h, meth, pairs.key(3))
234
531
 
235
- assert_raise(TypeError) do
236
- { 'abc_key' => 'abc_value' }.merge "a"
532
+ k = HashKey[-31, callback: ->(*){h.clear}]
533
+ assert_nothing_crashed{h.__send__(meth, k)}
534
+ end
237
535
  end
238
- end
239
536
 
240
- assert('Hash#replace', '15.2.13.4.23') do
241
- a = { 'abc_key' => 'abc_value' }
242
- b = Hash.new.replace(a)
537
+ h = Hash.new{|h, k| h[1] = 1}
538
+ assert_not_operator(h, meth, 1)
539
+ end
243
540
 
244
- assert_equal({ 'abc_key' => 'abc_value' }, b)
541
+ [%w[has_value? 14], %w[value? 24]].each do |meth, no|
542
+ assert("Hash##{meth}", "15.2.13.4.#{no}") do
543
+ [ar_entries, ht_entries].each do |entries|
544
+ entries.push([HashKey[-5], -8], ["NIL", nil])
545
+ h = entries.hash_for
546
+ entries.each{|k, v| assert_operator(h, meth, v)}
547
+ assert_operator(h, meth, -8.0) if Object.const_defined?(:Float)
548
+ assert_not_operator(h, meth, "-8")
245
549
 
246
- a = Hash.new(42)
247
- b = {}
248
- b.replace(a)
249
- assert_equal(42, b[1])
550
+ h.shift
551
+ assert_not_operator(h, meth, entries.value(0))
250
552
 
251
- a = Hash.new{|h,x| x}
252
- b.replace(a)
253
- assert_equal(127, b[127])
553
+ h.delete(entries.key(3))
554
+ assert_not_operator(h, meth, entries.value(3))
254
555
 
255
- assert_raise(TypeError) do
256
- { 'abc_key' => 'abc_value' }.replace "a"
556
+ v = HashKey[-31, callback: ->(*){h.clear}]
557
+ assert_nothing_crashed{h.__send__(meth, v)}
558
+ end
257
559
  end
258
- end
259
-
260
- assert('Hash#shift', '15.2.13.4.24') do
261
- a = { 'abc_key' => 'abc_value', 'cba_key' => 'cba_value' }
262
- b = a.shift
263
-
264
- assert_equal Array, b.class
265
- assert_equal 2, b.size
266
- assert_equal 1, a.size
267
560
 
268
- b = a.shift
269
-
270
- assert_equal Array, b.class
271
- assert_equal 2, b.size
272
- assert_equal 0, a.size
561
+ h = Hash.new{|h, k| h[1] = 1}
562
+ assert_not_operator(h, meth, 1)
273
563
  end
274
564
 
275
- assert('Hash#size', '15.2.13.4.25') do
276
- a = { 'abc_key' => 'abc_value' }
277
- b = Hash.new
278
-
279
- assert_equal 1, a.size
280
- assert_equal 0, b.size
565
+ assert('Hash#initialize', '15.2.13.4.16') do
566
+ h = Hash.new
567
+ assert_equal(Hash, h.class)
568
+ assert_not_operator(h, :key?, 1)
569
+ assert_equal(nil, h[1])
570
+
571
+ h = Hash.new([8])
572
+ assert_not_operator(h, :key?, 1)
573
+ assert_equal([8], h[1])
574
+ assert_same(h[1], h[2])
575
+
576
+ k = "key"
577
+ h = Hash.new{|hash, key| [hash, key]}
578
+ assert_not_operator(h, :key?, k)
579
+ assert_equal([h, k], h[k])
580
+ assert_same(h, h[k][0])
581
+ assert_same(k, h[k][1])
582
+
583
+ assert_raise(ArgumentError){Hash.new(1,2)}
584
+ assert_raise(ArgumentError){Hash.new(1){}}
585
+ end
586
+
587
+ [%w[keys 19], %w[values 28]].each do |meth, no|
588
+ assert("Hash##{meth}", "15.2.13.4.#{no}") do
589
+ [ar_entries, ht_entries].each do |entries|
590
+ h = entries.hash_for
591
+ assert_equal(entries.__send__(meth), h.__send__(meth))
592
+
593
+ h.shift
594
+ entries.shift
595
+ h.delete(entries.delete_at(3)[0])
596
+ assert_equal(entries.__send__(meth), h.__send__(meth))
597
+ end
598
+
599
+ assert_equal([], {}.__send__(meth))
600
+ end
281
601
  end
282
602
 
283
- assert('Hash#store', '15.2.13.4.26') do
284
- a = Hash.new
285
- a.store('abc', 'abc')
603
+ [%w[length 20], %w[size 25]].each do |meth, no|
604
+ assert("Hash##{meth}", "15.2.13.4.#{no}") do
605
+ [ar_entries, ht_entries].each do |entries|
606
+ h = entries.hash_for
607
+ assert_equal(entries.size, h.__send__(meth))
608
+
609
+ h.shift
610
+ entries.shift
611
+ h.delete(entries.delete_at(3)[0])
612
+ assert_equal(entries.size, h.__send__(meth))
613
+ end
286
614
 
287
- assert_equal 'abc', a['abc']
615
+ assert_equal(0, Hash.new.__send__(meth))
616
+ end
288
617
  end
289
618
 
290
- assert('Hash#value?', '15.2.13.4.27') do
291
- a = { 'abc_key' => 'abc_value' }
292
- b = Hash.new
619
+ assert('Hash#merge', '15.2.13.4.22') do
620
+ cls = Class.new(Hash){attr_accessor :foo}
621
+ ar_pairs = HashEntries[
622
+ ["id", 32],
623
+ [nil, :two],
624
+ ["&", "&amp;"],
625
+ [:same_key, :AR],
626
+ [HashKey[2], 20],
627
+ ]
628
+ ht_pairs = HashEntries[
629
+ *(1..20).map{[_1, _1.to_s]},
630
+ [:same_key, :HT],
631
+ [:age, 32],
632
+ [HashKey[5], 500],
633
+ ]
634
+
635
+ [[ar_pairs, ht_pairs], [ht_pairs, ar_pairs]].each do |entries1, entries2|
636
+ h1 = entries1.hash_for(cls.new(:dv1)){|h| h.foo = :iv1}.freeze
637
+ h2 = entries2.hash_for(Hash.new(:dv2)).freeze
638
+ h3 = h1.merge(h2)
639
+ assert_equal(entries1, h1.to_a)
640
+ assert_equal(merge_entries!(entries1.dup2, entries2), h3.to_a)
641
+ assert_equal(cls, h3.class)
642
+ assert_equal(:dv1, h3.default)
643
+ assert_equal(:iv1, h3.foo)
644
+
645
+ h3 = {}.merge(entries2.hash_for(cls.new))
646
+ assert_equal(merge_entries!([], entries2), h3.to_a)
647
+ assert_equal(Hash, h3.class)
648
+
649
+ h3 = entries1.hash_for.merge({})
650
+ assert_equal(merge_entries!(entries1.dup2, []), h3.to_a)
651
+
652
+ h1 = entries1.hash_for
653
+ h2 = entries2.hash_for
654
+ h3 = h1.merge(h2){|k, v1, v2| [k, v1, v2]}
655
+ exp = merge_entries!(entries1.dup2, entries2)
656
+ exp.find{|k, _| k == :same_key}[1] = [
657
+ :same_key,
658
+ entries1.find{|k, _| k == :same_key}[1],
659
+ entries2.find{|k, _| k == :same_key}[1],
660
+ ]
661
+ assert_equal(exp, h3.to_a)
662
+
663
+ assert_raise(TypeError){entries1.hash_for.merge("str")}
664
+
665
+ k2 = HashKey[-2]
666
+ entries2 << [k2, 234]
667
+ h1, h2 = entries1.hash_for, entries2.hash_for
668
+ k2.callback = ->(name, *){h1.clear if name == :eql?}
669
+ assert_nothing_crashed{h1.merge(h2)}
670
+ h1, h2 = entries1.hash_for, entries2.hash_for
671
+ k2.callback = ->(name, *){h2.clear if name == :eql?}
672
+ assert_nothing_crashed{h1.merge(h2)}
673
+ h1, h2 = entries1.hash_for, entries2.hash_for
674
+ k2.callback = ->(name, *){h1.clear if name == :hash}
675
+ assert_nothing_crashed{h1.merge(h2)}
676
+ h1, h2 = entries1.hash_for, entries2.hash_for
677
+ k2.callback = ->(name, *){h2.clear if name == :hash}
678
+ assert_nothing_crashed{h1.merge(h2)}
679
+ end
680
+ end
293
681
 
294
- assert_true a.value?('abc_value')
295
- assert_false b.value?('cba')
682
+ assert("Hash#replace", "15.2.13.4.23") do
683
+ cls = Class.new(Hash){attr_accessor :foo}
684
+ e = [ar_entries, ht_entries]
685
+ [e, e.reverse].each do |entries1, entries2|
686
+ h1 = entries1.hash_for
687
+ assert_same(h1, h1.replace(h1))
688
+ assert_equal(entries1, h1.to_a)
689
+
690
+ h1 = {}
691
+ assert_same(h1, h1.replace(entries2.hash_for))
692
+ assert_equal(entries2, h1.to_a)
693
+
694
+ h1 = entries1.hash_for
695
+ assert_same(h1, h1.replace({}))
696
+ assert_predicate(h1, :empty?)
697
+
698
+ pairs2 = entries2.dup
699
+ h2 = pairs2.hash_for
700
+ pairs2.shift
701
+ h2.shift
702
+ h2.delete(pairs2.delete_at(2)[0])
703
+ h2.delete(pairs2.delete_at(4)[0])
704
+ h1 = entries1.hash_for
705
+ assert_same(h1, h1.replace(h2))
706
+ assert_equal(pairs2, h1.to_a)
707
+
708
+ h1 = entries1.hash_for(Hash.new(10))
709
+ h2 = entries2.hash_for(Hash.new(20))
710
+ assert_same(h1, h1.replace(h2))
711
+ assert_equal(entries2, h1.to_a)
712
+ assert_equal(20, h1.default)
713
+
714
+ h1 = entries1.hash_for(Hash.new{_2})
715
+ h2 = entries2.hash_for(Hash.new{_2.to_s})
716
+ assert_same(h1, h1.replace(h2))
717
+ assert_equal(entries2, h1.to_a)
718
+ assert_equal("-11", h1[-11])
719
+
720
+ h1 = entries1.hash_for(Hash.new(10))
721
+ h2 = entries2.hash_for(Hash.new{_2.to_s})
722
+ assert_same(h1, h1.replace(h2))
723
+ assert_equal(entries2, h1.to_a)
724
+ assert_equal("-11", h1[-11])
725
+
726
+ h1 = entries1.hash_for(Hash.new{_2})
727
+ h2 = entries2.hash_for(Hash.new(20))
728
+ assert_same(h1, h1.replace(h2))
729
+ assert_equal(entries2, h1.to_a)
730
+ assert_equal(20, h1[-1])
731
+
732
+ h1 = entries1.hash_for(cls.new(10)){|h| h.foo = 41}
733
+ h2 = entries2.hash_for(cls.new(20)){|h| h.foo = 42}.freeze
734
+ assert_same(h1, h1.replace(h2))
735
+ assert_equal(entries2, h1.to_a)
736
+ assert_equal(20, h1.default)
737
+ assert_equal(41, h1.foo)
738
+
739
+ h1 = entries1.hash_for
740
+ h2 = entries2.hash_for(cls.new)
741
+ assert_same(h1, h1.replace(h2))
742
+ assert_equal(entries2, h1.to_a)
743
+
744
+ assert_raise(TypeError){entries1.hash_for.replace([])}
745
+
746
+ k2 = HashKey[-2]
747
+ pairs2 = entries2.dup
748
+ pairs2 << [k2, 23]
749
+ h1 = entries1.hash_for
750
+ h2 = pairs2.hash_for
751
+ k2.callback = ->(*){h1.clear; h2.clear}
752
+ assert_nothing_crashed{h1.replace(h2)}
753
+
754
+ assert_raise(FrozenError){h1.freeze.replace(h1)}
755
+ assert_raise(FrozenError){{}.freeze.replace({})}
756
+ end
296
757
  end
297
758
 
298
- assert('Hash#values', '15.2.13.4.28') do
299
- a = { 'abc_key' => 'abc_value' }
759
+ assert('Hash#shift', '15.2.13.4.24') do
760
+ [ar_entries, ht_entries].each do |entries|
761
+ pairs = entries.dup
762
+ h = pairs.hash_for
763
+ h.delete(pairs.delete_at(0)[0])
764
+ h.delete(pairs.delete_at(3)[0])
765
+ until pairs.empty?
766
+ exp = pairs.shift
767
+ act = h.shift
768
+ assert_equal(Array, act.class)
769
+ assert_equal(exp, act)
770
+ assert_equal(exp.size, act.size)
771
+ assert_not_operator(h, :key?, exp[0])
772
+ end
773
+
774
+ assert_equal(nil, h.shift)
775
+ assert_equal(0, h.size)
776
+
777
+ h.default = -456
778
+ assert_equal(-456, h.shift)
779
+ assert_equal(0, h.size)
780
+
781
+ h.freeze
782
+ assert_raise(FrozenError){h.shift}
783
+ end
300
784
 
301
- assert_equal ['abc_value'], a.values
785
+ h = Hash.new{|h, k| [h, k]}
786
+ assert_operator(h.shift, :eql?, [h, nil])
787
+ assert_equal(0, h.size)
302
788
  end
303
789
 
304
790
  # Not ISO specified
305
791
 
306
- assert('Hash#eql?') do
307
- a = { 'a' => 1, 'b' => 2, 'c' => 3 }
308
- b = { 'a' => 1, 'b' => 2, 'c' => 3 }
309
- c = { 'a' => 1.0, 'b' => 2, 'c' => 3 }
310
- assert_true(a.eql?(b))
311
- assert_false(a.eql?(c))
312
- assert_false(a.eql?(true))
313
- end
314
-
315
- assert('Hash#reject') do
316
- h = {:one => 1, :two => 2, :three => 3, :four => 4}
317
- ret = h.reject do |k,v|
318
- v % 2 == 0
792
+ %i[reject select].each do |meth|
793
+ assert("Hash##{meth}") do
794
+ cls = Class.new(Hash){attr_accessor :foo}
795
+ [ar_entries, ht_entries].each do |entries|
796
+ params = nil
797
+ filter = ->((k, v)) do
798
+ params << [k, v]
799
+ String === k
800
+ end
801
+
802
+ h = entries.hash_for(cls.new(1))
803
+ params = []
804
+ ret = h.__send__(meth, &filter)
805
+ assert_equal(entries, params)
806
+ assert_equal(entries, h.to_a)
807
+ assert_equal(1, h.default)
808
+ assert_equal(entries.__send__(meth, &filter), ret.to_a)
809
+ assert_equal(Hash, ret.class)
810
+ assert_equal(nil, ret.default)
811
+
812
+ params = []
813
+ assert_predicate({}.__send__(meth, &filter), :empty?)
814
+ assert_predicate(params, :empty?)
815
+ end
319
816
  end
320
- assert_equal({:one => 1, :three => 3}, ret)
321
- assert_equal({:one => 1, :two => 2, :three => 3, :four => 4}, h)
322
817
  end
323
818
 
324
- assert('Hash#reject!') do
325
- h = {:one => 1, :two => 2, :three => 3, :four => 4}
326
- ret = h.reject! do |k,v|
327
- v % 2 == 0
819
+ %i[reject! select!].each do |meth|
820
+ assert("Hash##{meth}") do
821
+ [ar_entries, ht_entries].each do |entries|
822
+ params = nil
823
+ filter = ->((k, v)) do
824
+ params << [k, v]
825
+ String === k
826
+ end
827
+
828
+ pairs = entries.dup << ["_str", 5]
829
+ h = pairs.hash_for(Hash.new(1))
830
+ params = []
831
+ ret = h.__send__(meth, &filter)
832
+ assert_same(h, ret)
833
+ assert_equal(pairs, params)
834
+ assert_equal(pairs.__send__(meth.to_s[0..-2], &filter), h.to_a)
835
+ assert_equal(1, h.default)
836
+
837
+ h = pairs.hash_for
838
+ ret = h.__send__(meth){meth == :select!}
839
+ assert_nil(ret)
840
+ assert_equal(pairs, h.to_a)
841
+
842
+ assert_raise(FrozenError){h.freeze.__send__(meth, &filter)}
843
+ end
844
+
845
+ h = {}
846
+ assert_nil(h.__send__(meth){})
847
+ assert_predicate(h, :empty?)
328
848
  end
329
- assert_equal({:one => 1, :three => 3}, ret)
330
- assert_equal({:one => 1, :three => 3}, h)
331
849
  end
332
850
 
333
- assert('Hash#select') do
334
- h = {:one => 1, :two => 2, :three => 3, :four => 4}
335
- ret = h.select do |k,v|
336
- v % 2 == 0
851
+ %i[inspect to_s].each do |meth|
852
+ assert("Hash##{meth}") do
853
+ assert_equal('{}', Hash.new.__send__(meth))
854
+
855
+ h1 = {:s => 0, :a => [1,2], 37 => :b, :d => "del", "c" => nil}
856
+ h1.shift
857
+ h1.delete(:d)
858
+ s1 = ':a=>[1, 2], 37=>:b, "c"=>nil'
859
+ h2 = Hash.new(100)
860
+
861
+ (1..14).each{h2[_1] = _1 * 2}
862
+ h2 = {**h2, **h1}
863
+ s2 = "1=>2, 2=>4, 3=>6, 4=>8, 5=>10, 6=>12, 7=>14, 8=>16, " \
864
+ "9=>18, 10=>20, 11=>22, 12=>24, 13=>26, 14=>28, #{s1}"
865
+
866
+ [[h1, s1], [h2, s2]].each do |h, s|
867
+ assert_equal("{#{s}}", h.__send__(meth))
868
+
869
+ hh = {}
870
+ hh[:recur] = hh
871
+ h.each{|k, v| hh[k] = v}
872
+ assert_equal("{:recur=>{...}, #{s}}", hh.__send__(meth))
873
+
874
+ hh = h.dup
875
+ hh[hh] = :recur
876
+ assert_equal("{#{s}, {...}=>:recur}", hh.__send__(meth))
877
+ end
878
+
879
+ [ar_entries, ht_entries].each do |entries|
880
+ cls = Class.new do
881
+ attr_accessor :h
882
+ def inspect; @h.replace(@h.dup); to_s; end
883
+ end
884
+ v = cls.new
885
+ h = entries.hash_for({_k: v})
886
+ v.h = h
887
+ assert_nothing_raised{h.__send__(meth)}
888
+ end
337
889
  end
338
- assert_equal({:two => 2, :four => 4}, ret)
339
- assert_equal({:one => 1, :two => 2, :three => 3, :four => 4}, h)
340
890
  end
341
891
 
342
- assert('Hash#select!') do
343
- h = {:one => 1, :two => 2, :three => 3, :four => 4}
344
- ret = h.select! do |k,v|
345
- v % 2 == 0
892
+ assert('Hash#rehash') do
893
+ cls = Class.new(Hash){attr_accessor :foo}
894
+ [ar_entries, ht_entries].each do |entries|
895
+ k1, k2, k3 = HashKey[-1], HashKey[-2], HashKey[-3]
896
+ pairs = entries.dup.push(
897
+ [-4, -40],
898
+ [HashKey[-11], -5],
899
+ [:_del, "_del"],
900
+ [k1, :_k1],
901
+ ["_a", "_b"],
902
+ [k2, :_k2],
903
+ ["_c", "_d"],
904
+ [HashKey[-22], -21],
905
+ [k3, :_k3],
906
+ )
907
+ h = pairs.hash_for(cls.new(:defvar)){|h| h.foo = "f"}
908
+ k1.value, k2.value, k3.value = -11, -11, -22
909
+ pairs1 = pairs.dup
910
+ pairs1.delete([:_del, h.delete(:_del)])
911
+ exp_pairs1 = pairs1.hash_for.to_a
912
+ h.freeze
913
+ assert_same(h, h.rehash)
914
+ assert_equal(exp_pairs1, h.to_a)
915
+ assert_equal(exp_pairs1.size, h.size)
916
+ assert_equal(:defvar, h.default)
917
+ assert_equal("f", h.foo)
918
+ exp_pairs1.each {|k, v| assert_equal(v, h[k])}
919
+
920
+ # If an error occurs during rehash, at least the entry list is not broken.
921
+ k1.value, k2.value, k3.value = -1, -2, -3
922
+ h = pairs.hash_for
923
+ k1.value = -11
924
+ pairs2 = pairs.dup
925
+ pairs2.delete([:_del, h.delete(:_del)])
926
+ exp_pairs2 = pairs2.hash_for.to_a
927
+ k2.error = :eql?
928
+ assert_raise{h.rehash}
929
+ act_pairs2 = h.to_a
930
+ unless pairs2 == act_pairs2 && pairs2.size == h.size
931
+ assert_equal(exp_pairs2, act_pairs2)
932
+ assert_equal(exp_pairs2.size, h.size)
933
+ end
934
+
935
+ k1.value = -1
936
+ k2.error = false
937
+ h = pairs.hash_for
938
+ k1.callback = ->(name, *){h.clear if name == :eql?}
939
+ assert_nothing_crashed{h.rehash}
940
+ k1.callback = ->(name, *){h.clear if name == :hash}
941
+ assert_nothing_crashed{h.rehash}
346
942
  end
347
- assert_equal({:two => 2, :four => 4}, ret)
348
- assert_equal({:two => 2, :four => 4}, h)
349
- end
350
-
351
- # Not ISO specified
352
-
353
- assert('Hash#inspect') do
354
- h = { "c" => 300, "a" => 100, "d" => 400, "c" => 300 }
355
- h["recur"] = h
356
- ret = h.to_s
357
943
 
358
- assert_include ret, '"c"=>300'
359
- assert_include ret, '"a"=>100'
360
- assert_include ret, '"d"=>400'
361
- assert_include ret, '"recur"=>{...}'
944
+ h = {}
945
+ assert_same(h, h.rehash)
946
+ assert_predicate(h, :empty?)
947
+ end
948
+
949
+ assert('#eql? receiver should be specified key') do
950
+ [ar_entries, ht_entries].each do |entries|
951
+ h = entries.hash_for
952
+ k0 = HashKey[-99]
953
+ h[k0] = 1
954
+
955
+ k1 = HashKey[-3, error: :eql?]
956
+ assert_raise{h[k1]}
957
+ k0.error = :eql?
958
+ k1.error = false
959
+ assert_nothing_raised{h[k1]}
960
+
961
+ k0.error = false
962
+ k1.error = :eql?
963
+ assert_raise{h[k1] = 1}
964
+ k0.error = :eql?
965
+ k1.error = false
966
+ assert_nothing_raised{h[k1] = 1}
967
+
968
+ k0.error = false
969
+ k2 = HashKey[-6, error: :eql?]
970
+ assert_raise{h.delete(k2)}
971
+ k0.error = :eql?
972
+ k2.error = false
973
+ assert_nothing_raised{h.delete(k2)}
974
+
975
+ k0.error = false
976
+ k3 = HashKey[-9, error: :eql?]
977
+ %i[has_key? include? key? member?].each do |m|
978
+ assert_raise{h.__send__(m, k3)}
979
+ end
980
+ k0.error = :eql?
981
+ k3.error = false
982
+ %i[has_key? include? key? member?].each do |m|
983
+ assert_nothing_raised{h.__send__(m, k3)}
984
+ end
985
+ end
362
986
  end
363
987
 
364
- assert('Hash#rehash') do
365
- h = {[:a] => "b"}
366
- # hash key modified
367
- h.keys[0][0] = :b
368
- # h[[:b]] => nil
369
- h.rehash
370
- assert_equal("b", h[[:b]])
371
- end
988
+ assert('#== receiver should be specified value') do
989
+ [ar_entries, ht_entries].each do |entries|
990
+ h = entries.hash_for
991
+ v0 = HashKey[-99]
992
+ h[-99] = v0
372
993
 
373
- assert('Hash#freeze') do
374
- h = {}.freeze
375
- assert_raise(FrozenError) do
376
- h[:a] = 'b'
994
+ v1 = HashKey[-3, error: :==]
995
+ %i[has_value? value?].each{|m| assert_raise{h.__send__(m, v1)}}
996
+ v0.error = :==
997
+ v1.error = false
998
+ %i[has_value? value?].each{|m| assert_nothing_raised{h.__send__(m, v1)}}
377
999
  end
378
1000
  end