script_core 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (381) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +8 -6
  4. data/.ruby-version +1 -1
  5. data/Gemfile +2 -1
  6. data/bin/sandbox +1 -1
  7. data/ext/enterprise_script_service/Rakefile +1 -1
  8. data/ext/enterprise_script_service/flags.rb +5 -0
  9. data/ext/enterprise_script_service/libseccomp/CHANGELOG +15 -0
  10. data/ext/enterprise_script_service/libseccomp/CREDITS +3 -0
  11. data/ext/enterprise_script_service/libseccomp/Makefile.am +1 -1
  12. data/ext/enterprise_script_service/libseccomp/README.md +1 -1
  13. data/ext/enterprise_script_service/libseccomp/SECURITY.md +45 -0
  14. data/ext/enterprise_script_service/libseccomp/configure.ac +3 -3
  15. data/ext/enterprise_script_service/libseccomp/doc/admin/MAINTAINER_PROCESS.md +95 -0
  16. data/ext/enterprise_script_service/libseccomp/{RELEASE_PROCESS.md → doc/admin/RELEASE_PROCESS.md} +9 -1
  17. data/ext/enterprise_script_service/libseccomp/include/Makefile.am +1 -1
  18. data/ext/enterprise_script_service/libseccomp/include/seccomp-syscalls.h +2292 -0
  19. data/ext/enterprise_script_service/libseccomp/include/seccomp.h.in +3 -1065
  20. data/ext/enterprise_script_service/libseccomp/src/arch-aarch64-syscalls.c +35 -3
  21. data/ext/enterprise_script_service/libseccomp/src/arch-arm-syscalls.c +35 -3
  22. data/ext/enterprise_script_service/libseccomp/src/arch-mips-syscalls.c +43 -11
  23. data/ext/enterprise_script_service/libseccomp/src/arch-mips64-syscalls.c +33 -1
  24. data/ext/enterprise_script_service/libseccomp/src/arch-mips64n32-syscalls.c +33 -1
  25. data/ext/enterprise_script_service/libseccomp/src/arch-parisc-syscalls.c +34 -2
  26. data/ext/enterprise_script_service/libseccomp/src/arch-ppc-syscalls.c +43 -11
  27. data/ext/enterprise_script_service/libseccomp/src/arch-ppc64-syscalls.c +44 -12
  28. data/ext/enterprise_script_service/libseccomp/src/arch-s390-syscalls.c +46 -14
  29. data/ext/enterprise_script_service/libseccomp/src/arch-s390.c +142 -18
  30. data/ext/enterprise_script_service/libseccomp/src/arch-s390x-syscalls.c +47 -15
  31. data/ext/enterprise_script_service/libseccomp/src/arch-s390x.c +143 -17
  32. data/ext/enterprise_script_service/libseccomp/src/arch-x32-syscalls.c +33 -1
  33. data/ext/enterprise_script_service/libseccomp/src/arch-x86-syscalls.c +94 -12
  34. data/ext/enterprise_script_service/libseccomp/src/arch-x86.c +142 -19
  35. data/ext/enterprise_script_service/libseccomp/src/arch-x86_64-syscalls.c +33 -1
  36. data/ext/enterprise_script_service/libseccomp/src/db.c +1 -0
  37. data/ext/enterprise_script_service/libseccomp/src/gen_bpf.c +10 -3
  38. data/ext/enterprise_script_service/libseccomp/src/python/Makefile.am +4 -4
  39. data/ext/enterprise_script_service/libseccomp/src/python/seccomp.pyx +2 -0
  40. data/ext/enterprise_script_service/libseccomp/tests/.gitignore +1 -0
  41. data/ext/enterprise_script_service/libseccomp/tests/50-sim-hash_collision.c +98 -0
  42. data/ext/enterprise_script_service/libseccomp/tests/50-sim-hash_collision.py +61 -0
  43. data/ext/enterprise_script_service/libseccomp/tests/50-sim-hash_collision.tests +18 -0
  44. data/ext/enterprise_script_service/libseccomp/tests/Makefile.am +6 -3
  45. data/ext/enterprise_script_service/libseccomp/tools/Makefile.am +0 -2
  46. data/ext/enterprise_script_service/libseccomp/tools/check-syntax +1 -0
  47. data/ext/enterprise_script_service/libseccomp/tools/scmp_bpf_sim.c +2 -0
  48. data/ext/enterprise_script_service/mruby-mpdecimal/src/ext.c +1 -1
  49. data/ext/enterprise_script_service/mruby/.gitignore +2 -2
  50. data/ext/enterprise_script_service/mruby/CONTRIBUTING.md +10 -3
  51. data/ext/enterprise_script_service/mruby/Doxyfile +2408 -0
  52. data/ext/enterprise_script_service/mruby/README.md +21 -8
  53. data/ext/enterprise_script_service/mruby/Rakefile +4 -13
  54. data/ext/enterprise_script_service/mruby/appveyor_config.rb +1 -1
  55. data/ext/enterprise_script_service/mruby/build_config.rb +3 -3
  56. data/ext/enterprise_script_service/mruby/doc/guides/compile.md +42 -42
  57. data/ext/enterprise_script_service/mruby/doc/guides/debugger.md +1 -1
  58. data/ext/enterprise_script_service/mruby/doc/guides/mrbconf.md +45 -6
  59. data/ext/enterprise_script_service/mruby/doc/guides/mrbgems.md +5 -0
  60. data/ext/enterprise_script_service/mruby/doc/limitations.md +88 -38
  61. data/ext/enterprise_script_service/mruby/doc/mruby_logo_red_icon.png +0 -0
  62. data/ext/enterprise_script_service/mruby/doc/opcode.md +94 -94
  63. data/ext/enterprise_script_service/mruby/include/mrbconf.h +74 -11
  64. data/ext/enterprise_script_service/mruby/include/mruby.h +242 -146
  65. data/ext/enterprise_script_service/mruby/include/mruby/array.h +7 -7
  66. data/ext/enterprise_script_service/mruby/include/mruby/boxing_nan.h +2 -9
  67. data/ext/enterprise_script_service/mruby/include/mruby/boxing_no.h +11 -10
  68. data/ext/enterprise_script_service/mruby/include/mruby/boxing_word.h +104 -69
  69. data/ext/enterprise_script_service/mruby/include/mruby/class.h +7 -5
  70. data/ext/enterprise_script_service/mruby/include/mruby/common.h +9 -7
  71. data/ext/enterprise_script_service/mruby/include/mruby/compile.h +6 -6
  72. data/ext/enterprise_script_service/mruby/include/mruby/data.h +5 -5
  73. data/ext/enterprise_script_service/mruby/include/mruby/debug.h +2 -2
  74. data/ext/enterprise_script_service/mruby/include/mruby/dump.h +3 -7
  75. data/ext/enterprise_script_service/mruby/include/mruby/error.h +34 -6
  76. data/ext/enterprise_script_service/mruby/include/mruby/gc.h +2 -2
  77. data/ext/enterprise_script_service/mruby/include/mruby/hash.h +4 -11
  78. data/ext/enterprise_script_service/mruby/include/mruby/irep.h +16 -4
  79. data/ext/enterprise_script_service/mruby/include/mruby/istruct.h +4 -4
  80. data/ext/enterprise_script_service/mruby/include/mruby/khash.h +2 -2
  81. data/ext/enterprise_script_service/mruby/include/mruby/numeric.h +41 -7
  82. data/ext/enterprise_script_service/mruby/include/mruby/object.h +8 -9
  83. data/ext/enterprise_script_service/mruby/include/mruby/opcode.h +2 -2
  84. data/ext/enterprise_script_service/mruby/include/mruby/ops.h +6 -6
  85. data/ext/enterprise_script_service/mruby/include/mruby/proc.h +19 -13
  86. data/ext/enterprise_script_service/mruby/include/mruby/range.h +10 -4
  87. data/ext/enterprise_script_service/mruby/include/mruby/re.h +2 -2
  88. data/ext/enterprise_script_service/mruby/include/mruby/string.h +130 -107
  89. data/ext/enterprise_script_service/mruby/include/mruby/throw.h +2 -2
  90. data/ext/enterprise_script_service/mruby/include/mruby/value.h +137 -49
  91. data/ext/enterprise_script_service/mruby/include/mruby/variable.h +3 -5
  92. data/ext/enterprise_script_service/mruby/include/mruby/version.h +24 -10
  93. data/ext/enterprise_script_service/mruby/lib/mruby-core-ext.rb +2 -39
  94. data/ext/enterprise_script_service/mruby/lib/mruby/build.rb +32 -15
  95. data/ext/enterprise_script_service/mruby/lib/mruby/build/command.rb +63 -17
  96. data/ext/enterprise_script_service/mruby/lib/mruby/build/load_gems.rb +24 -10
  97. data/ext/enterprise_script_service/mruby/lib/mruby/gem.rb +11 -7
  98. data/ext/enterprise_script_service/mruby/lib/mruby/lockfile.rb +81 -0
  99. data/ext/enterprise_script_service/mruby/minirake +27 -11
  100. data/ext/enterprise_script_service/mruby/mrbgems/default.gembox +3 -0
  101. data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/mrbgem.rake +0 -1
  102. data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/mrblib/array.rb +47 -9
  103. data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/src/array.c +3 -3
  104. data/ext/enterprise_script_service/mruby/mrbgems/mruby-array-ext/test/array.rb +50 -29
  105. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c +3 -3
  106. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apiprint.c +2 -2
  107. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/cmdprint.c +3 -3
  108. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.c +2 -2
  109. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.h +1 -1
  110. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdbconf.h +4 -0
  111. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +28 -1
  112. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mrbc/tools/mrbc/mrbc.c +1 -2
  113. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/bintest/mruby.rb +75 -8
  114. data/ext/enterprise_script_service/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c +134 -90
  115. data/ext/enterprise_script_service/mruby/mrbgems/mruby-class-ext/src/class.c +7 -8
  116. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/codegen.c +69 -46
  117. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/keywords +0 -3
  118. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/lex.def +51 -59
  119. data/ext/enterprise_script_service/mruby/mrbgems/mruby-compiler/core/parse.y +430 -241
  120. data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/mrbgem.rake +10 -0
  121. data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/mrblib/complex.rb +122 -0
  122. data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/src/complex.c +249 -0
  123. data/ext/enterprise_script_service/mruby/mrbgems/mruby-complex/test/complex.rb +153 -0
  124. data/ext/enterprise_script_service/mruby/mrbgems/mruby-enum-chain/mrblib/chain.rb +19 -17
  125. data/ext/enterprise_script_service/mruby/mrbgems/mruby-enum-chain/test/enum_chain.rb +41 -9
  126. data/ext/enterprise_script_service/mruby/mrbgems/mruby-enum-ext/mrblib/enum.rb +30 -4
  127. data/ext/enterprise_script_service/mruby/mrbgems/mruby-enum-ext/test/enum.rb +8 -3
  128. data/ext/enterprise_script_service/mruby/mrbgems/mruby-enumerator/mrbgem.rake +0 -1
  129. data/ext/enterprise_script_service/mruby/mrbgems/mruby-enumerator/mrblib/enumerator.rb +46 -14
  130. data/ext/enterprise_script_service/mruby/mrbgems/mruby-enumerator/test/enumerator.rb +51 -2
  131. data/ext/enterprise_script_service/mruby/mrbgems/mruby-error/src/exception.c +10 -0
  132. data/ext/enterprise_script_service/mruby/mrbgems/mruby-eval/src/eval.c +47 -44
  133. data/ext/enterprise_script_service/mruby/mrbgems/mruby-eval/test/eval.rb +2 -2
  134. data/ext/enterprise_script_service/mruby/mrbgems/mruby-exit/src/mruby-exit.c +9 -4
  135. data/ext/enterprise_script_service/mruby/mrbgems/mruby-fiber/src/fiber.c +16 -12
  136. data/ext/enterprise_script_service/mruby/mrbgems/mruby-fiber/test/fiber.rb +1 -1
  137. data/ext/enterprise_script_service/mruby/mrbgems/mruby-hash-ext/mrbgem.rake +0 -2
  138. data/ext/enterprise_script_service/mruby/mrbgems/mruby-hash-ext/mrblib/hash.rb +3 -0
  139. data/ext/enterprise_script_service/mruby/mrbgems/mruby-hash-ext/test/hash.rb +3 -7
  140. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/README.md +1 -3
  141. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrbgem.rake +1 -1
  142. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/file.rb +0 -5
  143. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/io.rb +24 -38
  144. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/mrblib/kernel.rb +16 -0
  145. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/file.c +19 -18
  146. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/file_test.c +5 -16
  147. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/src/io.c +54 -42
  148. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/file.rb +24 -20
  149. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/file_test.rb +4 -9
  150. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/io.rb +41 -35
  151. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/test/mruby_io_test.c +9 -36
  152. data/ext/enterprise_script_service/mruby/mrbgems/mruby-kernel-ext/mrbgem.rake +1 -1
  153. data/ext/enterprise_script_service/mruby/mrbgems/mruby-kernel-ext/src/kernel.c +9 -27
  154. data/ext/enterprise_script_service/mruby/mrbgems/mruby-kernel-ext/test/kernel.rb +2 -0
  155. data/ext/enterprise_script_service/mruby/mrbgems/mruby-math/src/math.c +5 -2
  156. data/ext/enterprise_script_service/mruby/mrbgems/mruby-metaprog/src/metaprog.c +39 -24
  157. data/ext/enterprise_script_service/mruby/mrbgems/mruby-metaprog/test/metaprog.rb +48 -17
  158. data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/mrblib/method.rb +0 -12
  159. data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/src/method.c +134 -101
  160. data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/test/method.rb +9 -1
  161. data/ext/enterprise_script_service/mruby/mrbgems/mruby-numeric-ext/mrblib/numeric_ext.rb +1 -5
  162. data/ext/enterprise_script_service/mruby/mrbgems/mruby-numeric-ext/src/numeric_ext.c +17 -37
  163. data/ext/enterprise_script_service/mruby/mrbgems/mruby-numeric-ext/test/numeric.rb +0 -8
  164. data/ext/enterprise_script_service/mruby/mrbgems/mruby-object-ext/mrbgem.rake +1 -1
  165. data/ext/enterprise_script_service/mruby/mrbgems/mruby-object-ext/mrblib/object.rb +15 -1
  166. data/ext/enterprise_script_service/mruby/mrbgems/mruby-object-ext/src/object.c +35 -6
  167. data/ext/enterprise_script_service/mruby/mrbgems/mruby-object-ext/test/nil.rb +4 -0
  168. data/ext/enterprise_script_service/mruby/mrbgems/mruby-objectspace/src/mruby_objectspace.c +1 -5
  169. data/ext/enterprise_script_service/mruby/mrbgems/mruby-objectspace/test/objectspace.rb +1 -1
  170. data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/src/pack.c +28 -23
  171. data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/test/pack.rb +43 -49
  172. data/ext/enterprise_script_service/mruby/mrbgems/mruby-print/mrblib/print.rb +3 -9
  173. data/ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/src/proc.c +6 -9
  174. data/ext/enterprise_script_service/mruby/mrbgems/mruby-proc-ext/test/proc.rb +21 -5
  175. data/ext/enterprise_script_service/mruby/mrbgems/mruby-random/src/random.c +157 -124
  176. data/ext/enterprise_script_service/mruby/mrbgems/mruby-random/test/random.rb +72 -26
  177. data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/mrblib/range.rb +38 -0
  178. data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/src/range.c +26 -11
  179. data/ext/enterprise_script_service/mruby/mrbgems/mruby-range-ext/test/range.rb +111 -1
  180. data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/mrbgem.rake +5 -0
  181. data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/mrblib/rational.rb +117 -0
  182. data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/src/rational.c +209 -0
  183. data/ext/enterprise_script_service/mruby/mrbgems/mruby-rational/test/rational.rb +308 -0
  184. data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/README.md +1 -1
  185. data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/src/socket.c +10 -9
  186. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/src/kernel.c +2 -2
  187. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sprintf/src/sprintf.c +22 -24
  188. data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/mrbgem.rake +0 -1
  189. data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/mrblib/string.rb +8 -4
  190. data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/src/string.c +116 -117
  191. data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/test/numeric.rb +29 -0
  192. data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/test/range.rb +26 -0
  193. data/ext/enterprise_script_service/mruby/mrbgems/mruby-string-ext/test/string.rb +32 -50
  194. data/ext/enterprise_script_service/mruby/mrbgems/mruby-struct/mrblib/struct.rb +5 -7
  195. data/ext/enterprise_script_service/mruby/mrbgems/mruby-struct/src/struct.c +43 -57
  196. data/ext/enterprise_script_service/mruby/mrbgems/mruby-struct/test/struct.rb +16 -11
  197. data/ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/src/symbol.c +2 -2
  198. data/ext/enterprise_script_service/mruby/mrbgems/mruby-symbol-ext/test/symbol.rb +1 -1
  199. data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/driver.c +152 -1
  200. data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/mrbgem.rake +4 -3
  201. data/ext/enterprise_script_service/mruby/mrbgems/mruby-test/vformat.c +200 -0
  202. data/ext/enterprise_script_service/mruby/mrbgems/mruby-time/include/mruby/time.h +2 -1
  203. data/ext/enterprise_script_service/mruby/mrbgems/mruby-time/src/time.c +199 -68
  204. data/ext/enterprise_script_service/mruby/mrbgems/mruby-time/test/time.rb +81 -46
  205. data/ext/enterprise_script_service/mruby/mrblib/array.rb +14 -16
  206. data/ext/enterprise_script_service/mruby/mrblib/enum.rb +13 -9
  207. data/ext/enterprise_script_service/mruby/mrblib/hash.rb +5 -7
  208. data/ext/enterprise_script_service/mruby/mrblib/kernel.rb +1 -1
  209. data/ext/enterprise_script_service/mruby/mrblib/numeric.rb +4 -4
  210. data/ext/enterprise_script_service/mruby/mrblib/range.rb +1 -1
  211. data/ext/enterprise_script_service/mruby/mrblib/string.rb +55 -112
  212. data/ext/enterprise_script_service/mruby/mruby-source.gemspec +1 -1
  213. data/ext/enterprise_script_service/mruby/oss-fuzz/config/mruby.dict +105 -0
  214. data/ext/enterprise_script_service/mruby/oss-fuzz/config/mruby_fuzzer.options +5 -0
  215. data/ext/enterprise_script_service/mruby/oss-fuzz/config/mruby_proto_fuzzer.options +4 -0
  216. data/ext/enterprise_script_service/mruby/oss-fuzz/mruby_fuzzer.c +18 -0
  217. data/ext/enterprise_script_service/mruby/oss-fuzz/mruby_proto_fuzzer.cpp +44 -0
  218. data/ext/enterprise_script_service/mruby/oss-fuzz/proto_to_ruby.cpp +455 -0
  219. data/ext/enterprise_script_service/mruby/oss-fuzz/proto_to_ruby.h +55 -0
  220. data/ext/enterprise_script_service/mruby/oss-fuzz/ruby.proto +201 -0
  221. data/ext/enterprise_script_service/mruby/src/array.c +95 -46
  222. data/ext/enterprise_script_service/mruby/src/backtrace.c +6 -8
  223. data/ext/enterprise_script_service/mruby/src/class.c +370 -278
  224. data/ext/enterprise_script_service/mruby/src/codedump.c +34 -34
  225. data/ext/enterprise_script_service/mruby/src/debug.c +2 -2
  226. data/ext/enterprise_script_service/mruby/src/dump.c +8 -6
  227. data/ext/enterprise_script_service/mruby/src/enum.c +1 -1
  228. data/ext/enterprise_script_service/mruby/src/error.c +157 -55
  229. data/ext/enterprise_script_service/mruby/src/etc.c +13 -46
  230. data/ext/enterprise_script_service/mruby/src/fmt_fp.c +2 -2
  231. data/ext/enterprise_script_service/mruby/src/gc.c +30 -11
  232. data/ext/enterprise_script_service/mruby/src/hash.c +23 -14
  233. data/ext/enterprise_script_service/mruby/src/kernel.c +16 -54
  234. data/ext/enterprise_script_service/mruby/src/load.c +40 -76
  235. data/ext/enterprise_script_service/mruby/src/numeric.c +164 -94
  236. data/ext/enterprise_script_service/mruby/src/object.c +16 -39
  237. data/ext/enterprise_script_service/mruby/src/pool.c +0 -2
  238. data/ext/enterprise_script_service/mruby/src/proc.c +47 -48
  239. data/ext/enterprise_script_service/mruby/src/range.c +22 -35
  240. data/ext/enterprise_script_service/mruby/src/state.c +5 -94
  241. data/ext/enterprise_script_service/mruby/src/string.c +874 -710
  242. data/ext/enterprise_script_service/mruby/src/symbol.c +73 -48
  243. data/ext/enterprise_script_service/mruby/src/variable.c +58 -38
  244. data/ext/enterprise_script_service/mruby/src/vm.c +133 -304
  245. data/ext/enterprise_script_service/mruby/tasks/doc.rake +48 -0
  246. data/ext/enterprise_script_service/mruby/tasks/toolchains/clang.rake +3 -4
  247. data/ext/enterprise_script_service/mruby/tasks/toolchains/gcc.rake +20 -19
  248. data/ext/enterprise_script_service/mruby/tasks/toolchains/visualcpp.rake +0 -12
  249. data/ext/enterprise_script_service/mruby/test/assert.rb +186 -25
  250. data/ext/enterprise_script_service/mruby/test/t/array.rb +34 -6
  251. data/ext/enterprise_script_service/mruby/test/t/class.rb +26 -0
  252. data/ext/enterprise_script_service/mruby/test/t/enumerable.rb +2 -2
  253. data/ext/enterprise_script_service/mruby/test/t/float.rb +17 -17
  254. data/ext/enterprise_script_service/mruby/test/t/hash.rb +2 -0
  255. data/ext/enterprise_script_service/mruby/test/t/integer.rb +14 -6
  256. data/ext/enterprise_script_service/mruby/test/t/kernel.rb +38 -19
  257. data/ext/enterprise_script_service/mruby/test/t/module.rb +87 -14
  258. data/ext/enterprise_script_service/mruby/test/t/numeric.rb +65 -23
  259. data/ext/enterprise_script_service/mruby/test/t/range.rb +4 -4
  260. data/ext/enterprise_script_service/mruby/test/t/string.rb +211 -49
  261. data/ext/enterprise_script_service/mruby/test/t/syntax.rb +19 -2
  262. data/ext/enterprise_script_service/mruby/test/t/vformat.rb +92 -0
  263. data/ext/enterprise_script_service/mruby/travis_config.rb +2 -2
  264. data/ext/enterprise_script_service/mruby_config.rb +10 -0
  265. data/ext/enterprise_script_service/mruby_engine.cpp +2 -2
  266. data/ext/enterprise_script_service/mruby_engine.gembox +1 -0
  267. data/ext/enterprise_script_service/msgpack/CHANGELOG.md +14 -0
  268. data/ext/enterprise_script_service/msgpack/Files.cmake +4 -0
  269. data/ext/enterprise_script_service/msgpack/README.md +1 -1
  270. data/ext/enterprise_script_service/msgpack/appveyor.yml +1 -1
  271. data/ext/enterprise_script_service/msgpack/erb/v1/cpp03_msgpack_tuple.hpp.erb +1 -1
  272. data/ext/enterprise_script_service/msgpack/erb/v1/cpp03_msgpack_tuple_decl.hpp.erb +1 -1
  273. data/ext/enterprise_script_service/msgpack/erb/v1/cpp03_zone.hpp.erb +3 -3
  274. data/ext/enterprise_script_service/msgpack/example/boost/asio_send_recv.cpp +1 -1
  275. data/ext/enterprise_script_service/msgpack/include/msgpack/adaptor/cpp11/timespec.hpp +16 -0
  276. data/ext/enterprise_script_service/msgpack/include/msgpack/adaptor/wstring.hpp +15 -0
  277. data/ext/enterprise_script_service/msgpack/include/msgpack/object.h +2 -0
  278. data/ext/enterprise_script_service/msgpack/include/msgpack/pack_template.h +17 -9
  279. data/ext/enterprise_script_service/msgpack/include/msgpack/sysdep.h +27 -16
  280. data/ext/enterprise_script_service/msgpack/include/msgpack/type.hpp +2 -0
  281. data/ext/enterprise_script_service/msgpack/include/msgpack/unpack_template.h +5 -0
  282. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/array_ref.hpp +0 -1
  283. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/check_container_size.hpp +1 -1
  284. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/cpp11/chrono.hpp +5 -5
  285. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/cpp11/timespec.hpp +140 -0
  286. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/detail/cpp03_msgpack_tuple.hpp +32 -32
  287. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/detail/cpp03_msgpack_tuple_decl.hpp +32 -32
  288. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/detail/cpp11_msgpack_tuple.hpp +6 -6
  289. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/detail/cpp11_msgpack_tuple_decl.hpp +10 -10
  290. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/ext.hpp +1 -1
  291. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/fixint.hpp +5 -4
  292. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/int.hpp +40 -13
  293. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/int_decl.hpp +3 -2
  294. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/adaptor/wstring.hpp +121 -0
  295. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/detail/cpp03_zone.hpp +3 -3
  296. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/detail/cpp11_zone.hpp +3 -3
  297. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/object.hpp +6 -6
  298. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/object_fwd.hpp +1 -1
  299. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/pack.hpp +40 -5
  300. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/unpack.hpp +11 -11
  301. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/vrefbuffer.hpp +7 -7
  302. data/ext/enterprise_script_service/msgpack/include/msgpack/v1/zbuffer.hpp +5 -5
  303. data/ext/enterprise_script_service/msgpack/include/msgpack/v2/adaptor/int_decl.hpp +1 -1
  304. data/ext/enterprise_script_service/msgpack/include/msgpack/v2/create_object_visitor.hpp +1 -1
  305. data/ext/enterprise_script_service/msgpack/include/msgpack/v2/parse.hpp +13 -13
  306. data/ext/enterprise_script_service/msgpack/include/msgpack/v2/x3_parse.hpp +28 -26
  307. data/ext/enterprise_script_service/msgpack/include/msgpack/v3/adaptor/int_decl.hpp +1 -1
  308. data/ext/enterprise_script_service/msgpack/include/msgpack/v3/parse.hpp +13 -13
  309. data/ext/enterprise_script_service/msgpack/include/msgpack/version_master.h +2 -2
  310. data/ext/enterprise_script_service/msgpack/include/msgpack/zbuffer.h +6 -6
  311. data/ext/enterprise_script_service/msgpack/include/msgpack/zone.h +1 -1
  312. data/ext/enterprise_script_service/msgpack/src/objectc.c +83 -148
  313. data/ext/enterprise_script_service/msgpack/src/unpack.c +73 -47
  314. data/ext/enterprise_script_service/msgpack/test/CMakeLists.txt +1 -1
  315. data/ext/enterprise_script_service/msgpack/test/array_ref.cpp +5 -0
  316. data/ext/enterprise_script_service/msgpack/test/boost_fusion.cpp +5 -0
  317. data/ext/enterprise_script_service/msgpack/test/boost_optional.cpp +7 -0
  318. data/ext/enterprise_script_service/msgpack/test/boost_string_ref.cpp +7 -0
  319. data/ext/enterprise_script_service/msgpack/test/boost_string_view.cpp +6 -0
  320. data/ext/enterprise_script_service/msgpack/test/boost_variant.cpp +15 -9
  321. data/ext/enterprise_script_service/msgpack/test/buffer.cpp +7 -0
  322. data/ext/enterprise_script_service/msgpack/test/carray.cpp +7 -0
  323. data/ext/enterprise_script_service/msgpack/test/cases.cpp +7 -1
  324. data/ext/enterprise_script_service/msgpack/test/convert.cpp +6 -0
  325. data/ext/enterprise_script_service/msgpack/test/fixint.cpp +7 -1
  326. data/ext/enterprise_script_service/msgpack/test/fixint_c.cpp +6 -1
  327. data/ext/enterprise_script_service/msgpack/test/fuzz_unpack_pack_fuzzer_cpp11.cpp +5 -0
  328. data/ext/enterprise_script_service/msgpack/test/iterator_cpp11.cpp +8 -2
  329. data/ext/enterprise_script_service/msgpack/test/json.cpp +6 -0
  330. data/ext/enterprise_script_service/msgpack/test/limit.cpp +7 -0
  331. data/ext/enterprise_script_service/msgpack/test/msgpack_basic.cpp +128 -6
  332. data/ext/enterprise_script_service/msgpack/test/msgpack_c.cpp +7 -2
  333. data/ext/enterprise_script_service/msgpack/test/msgpack_container.cpp +20 -3
  334. data/ext/enterprise_script_service/msgpack/test/msgpack_cpp11.cpp +159 -0
  335. data/ext/enterprise_script_service/msgpack/test/msgpack_cpp17.cpp +5 -0
  336. data/ext/enterprise_script_service/msgpack/test/msgpack_stream.cpp +8 -3
  337. data/ext/enterprise_script_service/msgpack/test/msgpack_tuple.cpp +6 -0
  338. data/ext/enterprise_script_service/msgpack/test/msgpack_vref.cpp +5 -0
  339. data/ext/enterprise_script_service/msgpack/test/msgpack_x3_parse.cpp +23 -18
  340. data/ext/enterprise_script_service/msgpack/test/object.cpp +77 -45
  341. data/ext/enterprise_script_service/msgpack/test/object_with_zone.cpp +28 -10
  342. data/ext/enterprise_script_service/msgpack/test/pack_unpack.cpp +25 -18
  343. data/ext/enterprise_script_service/msgpack/test/pack_unpack_c.cpp +7 -0
  344. data/ext/enterprise_script_service/msgpack/test/raw.cpp +17 -12
  345. data/ext/enterprise_script_service/msgpack/test/reference.cpp +6 -0
  346. data/ext/enterprise_script_service/msgpack/test/reference_cpp11.cpp +6 -0
  347. data/ext/enterprise_script_service/msgpack/test/reference_wrapper_cpp11.cpp +6 -0
  348. data/ext/enterprise_script_service/msgpack/test/shared_ptr_cpp11.cpp +6 -0
  349. data/ext/enterprise_script_service/msgpack/test/size_equal_only.cpp +6 -2
  350. data/ext/enterprise_script_service/msgpack/test/streaming.cpp +10 -3
  351. data/ext/enterprise_script_service/msgpack/test/streaming_c.cpp +7 -0
  352. data/ext/enterprise_script_service/msgpack/test/unique_ptr_cpp11.cpp +6 -0
  353. data/ext/enterprise_script_service/msgpack/test/user_class.cpp +5 -0
  354. data/ext/enterprise_script_service/msgpack/test/version.cpp +6 -0
  355. data/ext/enterprise_script_service/msgpack/test/visitor.cpp +7 -0
  356. data/ext/enterprise_script_service/msgpack/test/zone.cpp +6 -0
  357. data/lib/script_core/version.rb +1 -1
  358. data/lib/tasks/mruby/engine.gembox.example +1 -0
  359. data/lib/tasks/script_core.rake +21 -3
  360. data/spec/dummy/app/helpers/fields_helper.rb +2 -2
  361. data/spec/dummy/mruby/engine.gembox +1 -0
  362. data/spec/script_core_spec.rb +1 -1
  363. metadata +38 -22
  364. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/.gitignore +0 -1
  365. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/.travis.yml +0 -2
  366. data/ext/enterprise_script_service/mruby/mrbgems/mruby-io/run_test.rb +0 -26
  367. data/ext/enterprise_script_service/mruby/mrbgems/mruby-kernel-ext/mrblib/kernel.rb +0 -15
  368. data/ext/enterprise_script_service/mruby/mrbgems/mruby-method/mrblib/unbound_method.rb +0 -9
  369. data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/.gitignore +0 -5
  370. data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/.travis.yml +0 -2
  371. data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/packtest.rb +0 -157
  372. data/ext/enterprise_script_service/mruby/mrbgems/mruby-pack/run_test.rb +0 -26
  373. data/ext/enterprise_script_service/mruby/mrbgems/mruby-random/src/mt19937ar.c +0 -224
  374. data/ext/enterprise_script_service/mruby/mrbgems/mruby-random/src/mt19937ar.h +0 -80
  375. data/ext/enterprise_script_service/mruby/mrbgems/mruby-random/src/random.h +0 -12
  376. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sleep/.gitignore +0 -4
  377. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sleep/.travis.yml +0 -29
  378. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sleep/.travis_build_config.rb +0 -6
  379. data/ext/enterprise_script_service/mruby/mrbgems/mruby-sleep/Rakefile +0 -29
  380. data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/.travis.yml +0 -4
  381. data/ext/enterprise_script_service/mruby/mrbgems/mruby-socket/run_test.rb +0 -28
@@ -0,0 +1,209 @@
1
+ #include <mruby.h>
2
+ #include <mruby/class.h>
3
+ #include <mruby/string.h>
4
+ #include <mruby/numeric.h>
5
+
6
+ struct mrb_rational {
7
+ mrb_int numerator;
8
+ mrb_int denominator;
9
+ };
10
+
11
+ #if MRB_INT_MAX <= INTPTR_MAX
12
+
13
+ #define RATIONAL_USE_ISTRUCT
14
+ /* use TT_ISTRUCT */
15
+ #include <mruby/istruct.h>
16
+
17
+ #define rational_ptr(mrb, v) (struct mrb_rational*)mrb_istruct_ptr(v)
18
+
19
+ static struct RBasic*
20
+ rational_alloc(mrb_state *mrb, struct RClass *c, struct mrb_rational **p)
21
+ {
22
+ struct RIStruct *s;
23
+
24
+ s = (struct RIStruct*)mrb_obj_alloc(mrb, MRB_TT_ISTRUCT, c);
25
+ *p = (struct mrb_rational*)s->inline_data;
26
+
27
+ return (struct RBasic*)s;
28
+ }
29
+
30
+ #else
31
+ /* use TT_DATA */
32
+ #include <mruby/data.h>
33
+
34
+ static const struct mrb_data_type mrb_rational_type = {"Rational", mrb_free};
35
+
36
+ static struct RBasic*
37
+ rational_alloc(mrb_state *mrb, struct RClass *c, struct mrb_rational **p)
38
+ {
39
+ struct RData *d;
40
+
41
+ Data_Make_Struct(mrb, c, struct mrb_rational, &mrb_rational_type, *p, d);
42
+
43
+ return (struct RBasic*)d;
44
+ }
45
+
46
+ static struct mrb_rational*
47
+ rational_ptr(mrb_state *mrb, mrb_value v)
48
+ {
49
+ struct mrb_rational *p;
50
+
51
+ p = DATA_GET_PTR(mrb, v, &mrb_rational_type, struct mrb_rational);
52
+ if (!p) {
53
+ mrb_raise(mrb, E_ARGUMENT_ERROR, "uninitialized rational");
54
+ }
55
+ return p;
56
+ }
57
+ #endif
58
+
59
+ static mrb_value
60
+ rational_numerator(mrb_state *mrb, mrb_value self)
61
+ {
62
+ struct mrb_rational *p = rational_ptr(mrb, self);
63
+ return mrb_fixnum_value(p->numerator);
64
+ }
65
+
66
+ static mrb_value
67
+ rational_denominator(mrb_state *mrb, mrb_value self)
68
+ {
69
+ struct mrb_rational *p = rational_ptr(mrb, self);
70
+ return mrb_fixnum_value(p->denominator);
71
+ }
72
+
73
+ static mrb_value
74
+ rational_new(mrb_state *mrb, mrb_int numerator, mrb_int denominator)
75
+ {
76
+ struct RClass *c = mrb_class_get(mrb, "Rational");
77
+ struct mrb_rational *p;
78
+ struct RBasic *rat = rational_alloc(mrb, c, &p);
79
+ p->numerator = numerator;
80
+ p->denominator = denominator;
81
+ MRB_SET_FROZEN_FLAG(rat);
82
+ return mrb_obj_value(rat);
83
+ }
84
+
85
+ static mrb_value
86
+ rational_s_new(mrb_state *mrb, mrb_value self)
87
+ {
88
+ mrb_int numerator, denominator;
89
+
90
+ #ifdef MRB_WITHOUT_FLOAT
91
+ mrb_get_args(mrb, "ii", &numerator, &denominator);
92
+ #else
93
+
94
+ #define DROP_PRECISION(cond, num, denom) \
95
+ do { \
96
+ while (cond) { \
97
+ num /= 2; \
98
+ denom /= 2; \
99
+ } \
100
+ } while (0)
101
+
102
+ mrb_value numv, denomv;
103
+
104
+ mrb_get_args(mrb, "oo", &numv, &denomv);
105
+ if (mrb_fixnum_p(numv)) {
106
+ numerator = mrb_fixnum(numv);
107
+
108
+ if (mrb_fixnum_p(denomv)) {
109
+ denominator = mrb_fixnum(denomv);
110
+ }
111
+ else {
112
+ mrb_float denomf = mrb_to_flo(mrb, denomv);
113
+
114
+ DROP_PRECISION(denomf < MRB_INT_MIN || denomf > MRB_INT_MAX, numerator, denomf);
115
+ denominator = denomf;
116
+ }
117
+ }
118
+ else {
119
+ mrb_float numf = mrb_to_flo(mrb, numv);
120
+
121
+ if (mrb_fixnum_p(denomv)) {
122
+ denominator = mrb_fixnum(denomv);
123
+ }
124
+ else {
125
+ mrb_float denomf = mrb_to_flo(mrb, denomv);
126
+
127
+ DROP_PRECISION(denomf < MRB_INT_MIN || denomf > MRB_INT_MAX, numf, denomf);
128
+ denominator = denomf;
129
+ }
130
+
131
+ DROP_PRECISION(numf < MRB_INT_MIN || numf > MRB_INT_MAX, numf, denominator);
132
+ numerator = numf;
133
+ }
134
+ #endif
135
+
136
+ return rational_new(mrb, numerator, denominator);
137
+ }
138
+
139
+ #ifndef MRB_WITHOUT_FLOAT
140
+ static mrb_value
141
+ rational_to_f(mrb_state *mrb, mrb_value self)
142
+ {
143
+ struct mrb_rational *p = rational_ptr(mrb, self);
144
+ mrb_float f = (mrb_float)p->numerator / (mrb_float)p->denominator;
145
+
146
+ return mrb_float_value(mrb, f);
147
+ }
148
+ #endif
149
+
150
+ static mrb_value
151
+ rational_to_i(mrb_state *mrb, mrb_value self)
152
+ {
153
+ struct mrb_rational *p = rational_ptr(mrb, self);
154
+ if (p->denominator == 0) {
155
+ mrb_raise(mrb, mrb_exc_get(mrb, "StandardError"), "divided by 0");
156
+ }
157
+ return mrb_fixnum_value(p->numerator / p->denominator);
158
+ }
159
+
160
+ static mrb_value
161
+ rational_to_r(mrb_state *mrb, mrb_value self)
162
+ {
163
+ return self;
164
+ }
165
+
166
+ static mrb_value
167
+ rational_negative_p(mrb_state *mrb, mrb_value self)
168
+ {
169
+ struct mrb_rational *p = rational_ptr(mrb, self);
170
+ if (p->numerator < 0) {
171
+ return mrb_true_value();
172
+ }
173
+ return mrb_false_value();
174
+ }
175
+
176
+ static mrb_value
177
+ fix_to_r(mrb_state *mrb, mrb_value self)
178
+ {
179
+ return rational_new(mrb, mrb_fixnum(self), 1);
180
+ }
181
+
182
+ void mrb_mruby_rational_gem_init(mrb_state *mrb)
183
+ {
184
+ struct RClass *rat;
185
+
186
+ rat = mrb_define_class(mrb, "Rational", mrb_class_get(mrb, "Numeric"));
187
+ #ifdef RATIONAL_USE_ISTRUCT
188
+ MRB_SET_INSTANCE_TT(rat, MRB_TT_ISTRUCT);
189
+ mrb_assert(sizeof(struct mrb_rational) < ISTRUCT_DATA_SIZE);
190
+ #else
191
+ MRB_SET_INSTANCE_TT(rat, MRB_TT_DATA);
192
+ #endif
193
+ mrb_undef_class_method(mrb, rat, "new");
194
+ mrb_define_class_method(mrb, rat, "_new", rational_s_new, MRB_ARGS_REQ(2));
195
+ mrb_define_method(mrb, rat, "numerator", rational_numerator, MRB_ARGS_NONE());
196
+ mrb_define_method(mrb, rat, "denominator", rational_denominator, MRB_ARGS_NONE());
197
+ #ifndef MRB_WITHOUT_FLOAT
198
+ mrb_define_method(mrb, rat, "to_f", rational_to_f, MRB_ARGS_NONE());
199
+ #endif
200
+ mrb_define_method(mrb, rat, "to_i", rational_to_i, MRB_ARGS_NONE());
201
+ mrb_define_method(mrb, rat, "to_r", rational_to_r, MRB_ARGS_NONE());
202
+ mrb_define_method(mrb, rat, "negative?", rational_negative_p, MRB_ARGS_NONE());
203
+ mrb_define_method(mrb, mrb->fixnum_class, "to_r", fix_to_r, MRB_ARGS_NONE());
204
+ }
205
+
206
+ void
207
+ mrb_mruby_rational_gem_final(mrb_state* mrb)
208
+ {
209
+ }
@@ -0,0 +1,308 @@
1
+ class UserDefinedNumeric < Numeric
2
+ def initialize(n)
3
+ @n = n
4
+ end
5
+
6
+ def <=>(rhs)
7
+ return nil unless rhs.respond_to?(:to_i)
8
+ rhs = rhs.to_i
9
+ rhs < 0 ? nil : @n <=> rhs
10
+ end
11
+
12
+ def inspect
13
+ "#{self.class}(#{@n})"
14
+ end
15
+ end
16
+
17
+ class ComplexLikeNumeric < UserDefinedNumeric
18
+ def ==(rhs)
19
+ @n == 0 && rhs == 0
20
+ end
21
+
22
+ undef <=>
23
+ end
24
+
25
+ def assert_rational(exp, real)
26
+ assert "assert_rational" do
27
+ assert_float exp.numerator, real.numerator
28
+ assert_float exp.denominator, real.denominator
29
+ end
30
+ end
31
+
32
+ def assert_equal_rational(exp, o1, o2)
33
+ assert "assert_equal_rational" do
34
+ if exp
35
+ assert_operator(o1, :==, o2)
36
+ assert_not_operator(o1, :!=, o2)
37
+ else
38
+ assert_not_operator(o1, :==, o2)
39
+ assert_operator(o1, :!=, o2)
40
+ end
41
+ end
42
+ end
43
+
44
+ def assert_cmp(exp, o1, o2)
45
+ if exp == (o1 <=> o2)
46
+ pass
47
+ else
48
+ flunk "", " Expected #{o1.inspect} <=> #{o2.inspect} to be #{exp}."
49
+ end
50
+ end
51
+
52
+ assert 'Rational' do
53
+ r = 5r
54
+ assert_equal(Rational, r.class)
55
+ assert_equal([5, 1], [r.numerator, r.denominator])
56
+ end
57
+
58
+ assert 'Kernel#Rational' do
59
+ r = Rational(4,10)
60
+ assert_equal(2, r.numerator)
61
+ assert_equal(5, r.denominator)
62
+
63
+ r = Rational(3)
64
+ assert_equal(3, r.numerator)
65
+ assert_equal(1, r.denominator)
66
+
67
+ assert_raise(ArgumentError) { Rational() }
68
+ assert_raise(ArgumentError) { Rational(1,2,3) }
69
+ end
70
+
71
+ assert 'Rational#to_f' do
72
+ assert_float(2.0, Rational(2).to_f)
73
+ assert_float(2.25, Rational(9, 4).to_f)
74
+ assert_float(-0.75, Rational(-3, 4).to_f)
75
+ assert_float(6.666666666666667, Rational(20, 3).to_f)
76
+ end
77
+
78
+ assert 'Rational#to_i' do
79
+ assert_equal(0, Rational(2, 3).to_i)
80
+ assert_equal(3, Rational(3).to_i)
81
+ assert_equal(300, Rational(300.6).to_i)
82
+ assert_equal(1, Rational(98, 71).to_i)
83
+ assert_equal(-15, Rational(-30, 2).to_i)
84
+ end
85
+
86
+ assert 'Rational#*' do
87
+ assert_rational(Rational(4, 9), Rational(2, 3) * Rational(2, 3))
88
+ assert_rational(Rational(900, 1), Rational(900) * Rational(1))
89
+ assert_rational(Rational(1, 1), Rational(-2, 9) * Rational(-9, 2))
90
+ assert_rational(Rational(9, 2), Rational(9, 8) * 4)
91
+ assert_float( 21.77777777777778, Rational(20, 9) * 9.8)
92
+ end
93
+
94
+ assert 'Rational#+' do
95
+ assert_rational(Rational(4, 3), Rational(2, 3) + Rational(2, 3))
96
+ assert_rational(Rational(901, 1), Rational(900) + Rational(1))
97
+ assert_rational(Rational(-85, 18), Rational(-2, 9) + Rational(-9, 2))
98
+ assert_rational(Rational(41, 8), Rational(9, 8) + 4)
99
+ assert_float( 12.022222222222222, Rational(20, 9) + 9.8)
100
+ end
101
+
102
+ assert 'Rational#-' do
103
+ assert_rational(Rational(0, 1), Rational(2, 3) - Rational(2, 3))
104
+ assert_rational(Rational(899, 1), Rational(900) - Rational(1))
105
+ assert_rational(Rational(77, 18), Rational(-2, 9) - Rational(-9, 2))
106
+ assert_rational(Rational(-23, 8), Rational(9, 8) - 4)
107
+ assert_float( -7.577777777777778, Rational(20, 9) - 9.8)
108
+ end
109
+
110
+ assert 'Rational#/' do
111
+ assert_rational(Rational(1, 1), Rational(2, 3) / Rational(2, 3))
112
+ assert_rational(Rational(900, 1), Rational(900) / Rational(1))
113
+ assert_rational(Rational(4, 81), Rational(-2, 9) / Rational(-9, 2))
114
+ assert_rational(Rational(9, 32), Rational(9, 8) / 4)
115
+ assert_float( 0.22675736961451246, Rational(20, 9) / 9.8)
116
+ end
117
+
118
+ assert 'Rational#==, Rational#!=' do
119
+ assert_equal_rational(true, Rational(1,1), Rational(1))
120
+ assert_equal_rational(true, Rational(-1,1), -1r)
121
+ assert_equal_rational(true, Rational(13,4), 3.25)
122
+ assert_equal_rational(true, Rational(13,3.25), Rational(4,1))
123
+ assert_equal_rational(true, Rational(-3,-4), Rational(3,4))
124
+ assert_equal_rational(true, Rational(-4,5), Rational(4,-5))
125
+ assert_equal_rational(true, Rational(4,2), 2)
126
+ assert_equal_rational(true, Rational(-4,2), -2)
127
+ assert_equal_rational(true, Rational(4,-2), -2)
128
+ assert_equal_rational(true, Rational(4,2), 2.0)
129
+ assert_equal_rational(true, Rational(-4,2), -2.0)
130
+ assert_equal_rational(true, Rational(4,-2), -2.0)
131
+ assert_equal_rational(true, Rational(8,6), Rational(4,3))
132
+ assert_equal_rational(false, Rational(13,4), 3)
133
+ assert_equal_rational(false, Rational(13,4), 3.3)
134
+ assert_equal_rational(false, Rational(2,1), 1r)
135
+ assert_equal_rational(false, Rational(1), nil)
136
+ assert_equal_rational(false, Rational(1), '')
137
+ assert_equal_rational(true, 0r, UserDefinedNumeric.new(0))
138
+ assert_equal_rational(true, 1r, UserDefinedNumeric.new(1))
139
+ assert_equal_rational(false, 1r, UserDefinedNumeric.new(2))
140
+ assert_equal_rational(false, -1r, UserDefinedNumeric.new(-1))
141
+ assert_equal_rational(true, 0r, ComplexLikeNumeric.new(0))
142
+ assert_equal_rational(false, 1r, ComplexLikeNumeric.new(1))
143
+ assert_equal_rational(false, 1r, ComplexLikeNumeric.new(2))
144
+ end
145
+
146
+ assert 'Fixnum#==(Rational), Fixnum#!=(Rational)' do
147
+ assert_equal_rational(true, 2, Rational(4,2))
148
+ assert_equal_rational(true, -2, Rational(-4,2))
149
+ assert_equal_rational(true, -2, Rational(4,-2))
150
+ assert_equal_rational(false, 3, Rational(13,4))
151
+ end
152
+
153
+ assert 'Float#==(Rational), Float#!=(Rational)' do
154
+ assert_equal_rational(true, 2.0, Rational(4,2))
155
+ assert_equal_rational(true, -2.0, Rational(-4,2))
156
+ assert_equal_rational(true, -2.0, Rational(4,-2))
157
+ assert_equal_rational(false, 3.3, Rational(13,4))
158
+ end
159
+
160
+ assert 'Rational#<=>' do
161
+ assert_cmp(-1, Rational(-1), Rational(0))
162
+ assert_cmp(0, Rational(0), Rational(0))
163
+ assert_cmp(1, Rational(1), Rational(0))
164
+ assert_cmp(-1, Rational(-1), 0)
165
+ assert_cmp(0, Rational(0), 0)
166
+ assert_cmp(1, Rational(1), 0)
167
+ assert_cmp(-1, Rational(-1), 0.0)
168
+ assert_cmp(0, Rational(0), 0.0)
169
+ assert_cmp(1, Rational(1), 0.0)
170
+ assert_cmp(-1, Rational(1,2), Rational(2,3))
171
+ assert_cmp(0, Rational(2,3), Rational(2,3))
172
+ assert_cmp(1, Rational(2,3), Rational(1,2))
173
+ assert_cmp(1, Rational(2,3), Rational(1,2))
174
+ assert_cmp(1, Rational(0), Rational(-1))
175
+ assert_cmp(-1, Rational(0), Rational(1))
176
+ assert_cmp(1, Rational(2,3), Rational(1,2))
177
+ assert_cmp(0, Rational(2,3), Rational(2,3))
178
+ assert_cmp(-1, Rational(1,2), Rational(2,3))
179
+ assert_cmp(-1, Rational(1,2), Rational(2,3))
180
+ assert_cmp(nil, 3r, "3")
181
+ assert_cmp(1, 3r, UserDefinedNumeric.new(2))
182
+ assert_cmp(0, 3r, UserDefinedNumeric.new(3))
183
+ assert_cmp(-1, 3r, UserDefinedNumeric.new(4))
184
+ assert_cmp(nil, Rational(-3), UserDefinedNumeric.new(5))
185
+ assert_raise(NoMethodError) { 0r <=> ComplexLikeNumeric.new(0) }
186
+ assert_raise(NoMethodError) { 1r <=> ComplexLikeNumeric.new(2) }
187
+ end
188
+
189
+ assert 'Fixnum#<=>(Rational)' do
190
+ assert_cmp(-1, -2, Rational(-9,5))
191
+ assert_cmp(0, 5, 5r)
192
+ assert_cmp(1, 3, Rational(8,3))
193
+ end
194
+
195
+ assert 'Float#<=>(Rational)' do
196
+ assert_cmp(-1, -2.1, Rational(-9,5))
197
+ assert_cmp(0, 5.0, 5r)
198
+ assert_cmp(1, 2.7, Rational(8,3))
199
+ end
200
+
201
+ assert 'Rational#<' do
202
+ assert_operator(Rational(1,2), :<, Rational(2,3))
203
+ assert_not_operator(Rational(2,3), :<, Rational(2,3))
204
+ assert_operator(Rational(2,3), :<, 1)
205
+ assert_not_operator(2r, :<, 2)
206
+ assert_not_operator(Rational(2,3), :<, -3)
207
+ assert_operator(Rational(-4,3), :<, -0.3)
208
+ assert_not_operator(Rational(13,4), :<, 3.25)
209
+ assert_not_operator(Rational(2,3), :<, 0.6)
210
+ assert_raise(ArgumentError) { 1r < "2" }
211
+ end
212
+
213
+ assert 'Fixnum#<(Rational)' do
214
+ assert_not_operator(1, :<, Rational(2,3))
215
+ assert_not_operator(2, :<, 2r)
216
+ assert_operator(-3, :<, Rational(2,3))
217
+ end
218
+
219
+ assert 'Float#<(Rational)' do
220
+ assert_not_operator(-0.3, :<, Rational(-4,3))
221
+ assert_not_operator(3.25, :<, Rational(13,4))
222
+ assert_operator(0.6, :<, Rational(2,3))
223
+ end
224
+
225
+ assert 'Rational#<=' do
226
+ assert_operator(Rational(1,2), :<=, Rational(2,3))
227
+ assert_operator(Rational(2,3), :<=, Rational(2,3))
228
+ assert_operator(Rational(2,3), :<=, 1)
229
+ assert_operator(2r, :<=, 2)
230
+ assert_not_operator(Rational(2,3), :<=, -3)
231
+ assert_operator(Rational(-4,3), :<=, -0.3)
232
+ assert_operator(Rational(13,4), :<=, 3.25)
233
+ assert_not_operator(Rational(2,3), :<=, 0.6)
234
+ assert_raise(ArgumentError) { 1r <= "2" }
235
+ end
236
+
237
+ assert 'Fixnum#<=(Rational)' do
238
+ assert_not_operator(1, :<=, Rational(2,3))
239
+ assert_operator(2, :<=, 2r)
240
+ assert_operator(-3, :<=, Rational(2,3))
241
+ end
242
+
243
+ assert 'Float#<=(Rational)' do
244
+ assert_not_operator(-0.3, :<=, Rational(-4,3))
245
+ assert_operator(3.25, :<=, Rational(13,4))
246
+ assert_operator(0.6, :<=, Rational(2,3))
247
+ end
248
+
249
+ assert 'Rational#>' do
250
+ assert_not_operator(Rational(1,2), :>, Rational(2,3))
251
+ assert_not_operator(Rational(2,3), :>, Rational(2,3))
252
+ assert_not_operator(Rational(2,3), :>, 1)
253
+ assert_not_operator(2r, :>, 2)
254
+ assert_operator(Rational(2,3), :>, -3)
255
+ assert_not_operator(Rational(-4,3), :>, -0.3)
256
+ assert_not_operator(Rational(13,4), :>, 3.25)
257
+ assert_operator(Rational(2,3), :>, 0.6)
258
+ assert_raise(ArgumentError) { 1r > "2" }
259
+ end
260
+
261
+ assert 'Fixnum#>(Rational)' do
262
+ assert_operator(1, :>, Rational(2,3))
263
+ assert_not_operator(2, :>, 2r)
264
+ assert_not_operator(-3, :>, Rational(2,3))
265
+ end
266
+
267
+ assert 'Float#>(Rational)' do
268
+ assert_operator(-0.3, :>, Rational(-4,3))
269
+ assert_not_operator(3.25, :>, Rational(13,4))
270
+ assert_not_operator(0.6, :>, Rational(2,3))
271
+ end
272
+
273
+ assert 'Rational#>=' do
274
+ assert_not_operator(Rational(1,2), :>=, Rational(2,3))
275
+ assert_operator(Rational(2,3), :>=, Rational(2,3))
276
+ assert_not_operator(Rational(2,3), :>=, 1)
277
+ assert_operator(2r, :>=, 2)
278
+ assert_operator(Rational(2,3), :>=, -3)
279
+ assert_not_operator(Rational(-4,3), :>=, -0.3)
280
+ assert_operator(Rational(13,4), :>=, 3.25)
281
+ assert_operator(Rational(2,3), :>=, 0.6)
282
+ assert_raise(ArgumentError) { 1r >= "2" }
283
+ end
284
+
285
+ assert 'Fixnum#>=(Rational)' do
286
+ assert_operator(1, :>=, Rational(2,3))
287
+ assert_operator(2, :>=, 2r)
288
+ assert_not_operator(-3, :>=, Rational(2,3))
289
+ end
290
+
291
+ assert 'Float#>=(Rational)' do
292
+ assert_operator(-0.3, :>=, Rational(-4,3))
293
+ assert_operator(3.25, :>=, Rational(13,4))
294
+ assert_not_operator(0.6, :>=, Rational(2,3))
295
+ end
296
+
297
+ assert 'Rational#negative?' do
298
+ assert_predicate(Rational(-2,3), :negative?)
299
+ assert_predicate(Rational(2,-3), :negative?)
300
+ assert_not_predicate(Rational(2,3), :negative?)
301
+ assert_not_predicate(Rational(0), :negative?)
302
+ end
303
+
304
+ assert 'Rational#frozen?' do
305
+ assert_predicate(1r, :frozen?)
306
+ assert_predicate(Rational(2,3), :frozen?)
307
+ assert_predicate(4/5r, :frozen?)
308
+ end