Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

cancel subversion backfire. sorry

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31046 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
commit 1df42597d15416357a20bd68700ce1a2d245e8bb 1 parent fc634cc
matz authored
Showing with 1,828 additions and 711 deletions.
  1. +8 −0 .gitignore
  2. +1 −0  ChangeLog
  3. +1 −5 NEWS
  4. +1 −1  bin/gem
  5. +5 −5 class.c
  6. +0 −1  eval_jump.c
  7. +4 −4 ext/bigdecimal/bigdecimal.c
  8. +1 −1  ext/openssl/ossl_cipher.c
  9. +4 −4 ext/openssl/ossl_ns_spki.c
  10. +24 −24 ext/openssl/ossl_ocsp.c
  11. +6 −6 ext/openssl/ossl_pkcs12.c
  12. +19 −19 ext/openssl/ossl_pkcs7.c
  13. +8 −8 ext/openssl/ossl_pkey.h
  14. +2 −2 ext/openssl/ossl_pkey_dh.c
  15. +2 −2 ext/openssl/ossl_pkey_dsa.c
  16. +8 −0 golf_prelude.rb
  17. +196 −167 lib/date.rb
  18. +3 −3 lib/tempfile.rb
  19. +2 −2 marshal.c
  20. +7 −7 proc.c
  21. +51 −29 process.c
  22. +4 −0 strftime.c
  23. +1 −1  string.c
  24. +33 −0 test/ruby/test_io.rb
  25. +1 −0  test/ruby/test_m17n.rb
  26. +11 −7 test/ruby/test_process.rb
  27. +32 −0 test/ruby/test_string.rb
  28. +13 −17 test/ruby/test_system.rb
  29. +384 −38 test/rubygems/test_gem.rb
  30. +1 −1  test/rubygems/test_gem_builder.rb
  31. +2 −2 test/rubygems/test_gem_command_manager.rb
  32. +1 −1  test/rubygems/test_gem_commands_build_command.rb
  33. +2 −1  test/rubygems/test_gem_commands_cert_command.rb
  34. +6 −5 test/rubygems/test_gem_commands_dependency_command.rb
  35. +4 −4 test/rubygems/test_gem_commands_fetch_command.rb
  36. +21 −18 test/rubygems/test_gem_commands_install_command.rb
  37. +1 −1  test/rubygems/test_gem_commands_lock_command.rb
  38. +2 −5 test/rubygems/test_gem_commands_outdated_command.rb
  39. +28 −8 test/rubygems/test_gem_commands_pristine_command.rb
  40. +8 −8 test/rubygems/test_gem_commands_specification_command.rb
  41. +4 −2 test/rubygems/test_gem_commands_stale_command.rb
  42. +23 −4 test/rubygems/test_gem_commands_uninstall_command.rb
  43. +10 −8 test/rubygems/test_gem_commands_unpack_command.rb
  44. +192 −10 test/rubygems/test_gem_commands_update_command.rb
  45. +14 −0 test/rubygems/test_gem_config_file.rb
  46. +39 −0 test/rubygems/test_gem_dependency.rb
  47. +213 −92 test/rubygems/test_gem_dependency_installer.rb
  48. +37 −17 test/rubygems/test_gem_dependency_list.rb
  49. +5 −4 test/rubygems/test_gem_doc_manager.rb
  50. +2 −2 test/rubygems/test_gem_format.rb
  51. +9 −10 test/rubygems/test_gem_indexer.rb
  52. +0 −2  test/rubygems/test_gem_install_update_options.rb
  53. +151 −78 test/rubygems/test_gem_installer.rb
  54. +3 −0  test/rubygems/test_gem_package_tar_output.rb
  55. +23 −14 test/rubygems/test_gem_remote_fetcher.rb
  56. +17 −16 test/rubygems/test_gem_source_index.rb
  57. +6 −1 test/rubygems/test_gem_spec_fetcher.rb
  58. +93 −25 test/rubygems/test_gem_specification.rb
  59. +70 −10 test/rubygems/test_gem_uninstaller.rb
  60. +1 −1  test/rubygems/test_gem_validator.rb
  61. +1 −1  test/rubygems/test_kernel.rb
  62. +4 −4 vm_eval.c
  63. +3 −3 vm_method.c
View
8 .gitignore
@@ -97,6 +97,9 @@
/ext/-test-/*/Makefile
/ext/-test-/*/extconf.h
/ext/-test-/*/mkmf.log
+/ext/-test-/*/*/Makefile
+/ext/-test-/*/*/extconf.h
+/ext/-test-/*/*/mkmf.log
# /ext/bigdecimal/
/ext/bigdecimal/*.def
@@ -446,6 +449,11 @@
/ext/zlib/zlib.a
/ext/zlib/conftest.dSYM
+# /ext/date/
+/ext/date/Makefile
+/ext/date/extconf.h
+/ext/date/mkmf.log
+
# /lib/rexml/
# /spec/
View
1  ChangeLog
@@ -6573,6 +6573,7 @@ For the changes before 1.9.3, see doc/ChangeLog-1.9.3
For the changes before 1.8.0, see doc/ChangeLog-1.8.0
Local variables:
+coding: us-ascii
add-log-time-format: (lambda ()
(let* ((time (current-time))
(system-time-locale "C")
View
6 NEWS
@@ -72,6 +72,7 @@ with all sufficient information, see the ChangeLog file.
* String#unpack supports endian modifiers
* new method:
* String#prepend
+ * String#byteslice
* Time
* extended method:
@@ -153,8 +154,3 @@ with all sufficient information, see the ChangeLog file.
* Kernel#respond_to?
See above.
-
-* REXML::Document#encoding, REXML::XMLDecl#encoding,
- REXML::Output#encoding and REXML::Source#encoding
-
- Return an Encoding object not encoding name as a String.
View
2  bin/gem
@@ -9,7 +9,7 @@ require 'rubygems'
require 'rubygems/gem_runner'
require 'rubygems/exceptions'
-required_version = Gem::Requirement.new ">= 1.8.6"
+required_version = Gem::Requirement.new ">= 1.8.7"
unless required_version.satisfied_by? Gem.ruby_version then
abort "Expected Ruby Version #{required_version}, is #{Gem.ruby_version}"
View
10 class.c
@@ -988,14 +988,14 @@ rb_class_public_instance_methods(int argc, VALUE *argv, VALUE mod)
* <i>obj</i>'s ancestors.
*
* class Klass
- * def kMethod()
+ * def klass_method()
* end
* end
* k = Klass.new
- * k.methods[0..9] #=> [:kMethod, :freeze, :nil?, :is_a?,
- * # :class, :instance_variable_set,
- * # :methods, :extend, :__send__, :instance_eval]
- * k.methods.length #=> 42
+ * k.methods[0..9] #=> [:klass_method, :nil?, :===,
+ * # :==~, :!, :eql?
+ * # :hash, :<=>, :class, :singleton_class]
+ * k.methods.length #=> 57
*/
VALUE
View
1  eval_jump.c
@@ -97,7 +97,6 @@ void
rb_exec_end_proc(void)
{
struct end_proc_data *volatile link;
- struct end_proc_data *tmp;
int status;
volatile int safe = rb_safe_level();
View
8 ext/bigdecimal/bigdecimal.c
@@ -2237,11 +2237,11 @@ static int gnAlloc=0; /* Memory allocation counter */
VP_EXPORT void *
VpMemAlloc(size_t mb)
{
- void *p = xmalloc((unsigned int)mb);
- if(!p) {
- VpException(VP_EXCEPTION_MEMORY,"failed to allocate memory",1);
+ void *p = xmalloc(mb);
+ if (!p) {
+ VpException(VP_EXCEPTION_MEMORY, "failed to allocate memory", 1);
}
- memset(p,0,mb);
+ memset(p, 0, mb);
#ifdef BIGDECIMAL_DEBUG
gnAlloc++; /* Count allocation call */
#endif /* BIGDECIMAL_DEBUG */
View
2  ext/openssl/ossl_cipher.c
@@ -202,7 +202,7 @@ ossl_cipher_init(int argc, VALUE *argv, VALUE self, int mode)
* keeping this behaviour for backward compatibility.
*/
const char *cname = rb_class2name(rb_obj_class(self));
- rb_warn("argumtents for %s#encrypt and %s#decrypt were deprecated; "
+ rb_warn("arguments for %s#encrypt and %s#decrypt were deprecated; "
"use %s#pkcs5_keyivgen to derive key and IV",
cname, cname, cname);
StringValue(pass);
View
8 ext/openssl/ossl_ns_spki.c
@@ -11,14 +11,14 @@
#include "ossl.h"
#define WrapSPKI(klass, obj, spki) do { \
- if (!spki) { \
+ if (!(spki)) { \
ossl_raise(rb_eRuntimeError, "SPKI wasn't initialized!"); \
} \
- obj = Data_Wrap_Struct(klass, 0, NETSCAPE_SPKI_free, spki); \
+ (obj) = Data_Wrap_Struct((klass), 0, NETSCAPE_SPKI_free, (spki)); \
} while (0)
#define GetSPKI(obj, spki) do { \
- Data_Get_Struct(obj, NETSCAPE_SPKI, spki); \
- if (!spki) { \
+ Data_Get_Struct((obj), NETSCAPE_SPKI, (spki)); \
+ if (!(spki)) { \
ossl_raise(rb_eRuntimeError, "SPKI wasn't initialized!"); \
} \
} while (0)
View
48 ext/openssl/ossl_ocsp.c
@@ -14,55 +14,55 @@
#if defined(OSSL_OCSP_ENABLED)
#define WrapOCSPReq(klass, obj, req) do { \
- if(!req) ossl_raise(rb_eRuntimeError, "Request wasn't initialized!"); \
- obj = Data_Wrap_Struct(klass, 0, OCSP_REQUEST_free, req); \
+ if(!(req)) ossl_raise(rb_eRuntimeError, "Request wasn't initialized!"); \
+ (obj) = Data_Wrap_Struct((klass), 0, OCSP_REQUEST_free, (req)); \
} while (0)
#define GetOCSPReq(obj, req) do { \
- Data_Get_Struct(obj, OCSP_REQUEST, req); \
- if(!req) ossl_raise(rb_eRuntimeError, "Request wasn't initialized!"); \
+ Data_Get_Struct((obj), OCSP_REQUEST, (req)); \
+ if(!(req)) ossl_raise(rb_eRuntimeError, "Request wasn't initialized!"); \
} while (0)
#define SafeGetOCSPReq(obj, req) do { \
- OSSL_Check_Kind(obj, cOCSPReq); \
- GetOCSPReq(obj, req); \
+ OSSL_Check_Kind((obj), cOCSPReq); \
+ GetOCSPReq((obj), (req)); \
} while (0)
#define WrapOCSPRes(klass, obj, res) do { \
- if(!res) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \
- obj = Data_Wrap_Struct(klass, 0, OCSP_RESPONSE_free, res); \
+ if(!(res)) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \
+ (obj) = Data_Wrap_Struct((klass), 0, OCSP_RESPONSE_free, (res)); \
} while (0)
#define GetOCSPRes(obj, res) do { \
- Data_Get_Struct(obj, OCSP_RESPONSE, res); \
- if(!res) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \
+ Data_Get_Struct((obj), OCSP_RESPONSE, (res)); \
+ if(!(res)) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \
} while (0)
#define SafeGetOCSPRes(obj, res) do { \
- OSSL_Check_Kind(obj, cOCSPRes); \
- GetOCSPRes(obj, res); \
+ OSSL_Check_Kind((obj), cOCSPRes); \
+ GetOCSPRes((obj), (res)); \
} while (0)
#define WrapOCSPBasicRes(klass, obj, res) do { \
- if(!res) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \
- obj = Data_Wrap_Struct(klass, 0, OCSP_BASICRESP_free, res); \
+ if(!(res)) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \
+ (obj) = Data_Wrap_Struct((klass), 0, OCSP_BASICRESP_free, (res)); \
} while (0)
#define GetOCSPBasicRes(obj, res) do { \
- Data_Get_Struct(obj, OCSP_BASICRESP, res); \
- if(!res) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \
+ Data_Get_Struct((obj), OCSP_BASICRESP, (res)); \
+ if(!(res)) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \
} while (0)
#define SafeGetOCSPBasicRes(obj, res) do { \
- OSSL_Check_Kind(obj, cOCSPBasicRes); \
- GetOCSPBasicRes(obj, res); \
+ OSSL_Check_Kind((obj), cOCSPBasicRes); \
+ GetOCSPBasicRes((obj), (res)); \
} while (0)
#define WrapOCSPCertId(klass, obj, cid) do { \
- if(!cid) ossl_raise(rb_eRuntimeError, "Cert ID wasn't initialized!"); \
- obj = Data_Wrap_Struct(klass, 0, OCSP_CERTID_free, cid); \
+ if(!(cid)) ossl_raise(rb_eRuntimeError, "Cert ID wasn't initialized!"); \
+ (obj) = Data_Wrap_Struct((klass), 0, OCSP_CERTID_free, (cid)); \
} while (0)
#define GetOCSPCertId(obj, cid) do { \
- Data_Get_Struct(obj, OCSP_CERTID, cid); \
- if(!cid) ossl_raise(rb_eRuntimeError, "Cert ID wasn't initialized!"); \
+ Data_Get_Struct((obj), OCSP_CERTID, (cid)); \
+ if(!(cid)) ossl_raise(rb_eRuntimeError, "Cert ID wasn't initialized!"); \
} while (0)
#define SafeGetOCSPCertId(obj, cid) do { \
- OSSL_Check_Kind(obj, cOCSPCertId); \
- GetOCSPCertId(obj, cid); \
+ OSSL_Check_Kind((obj), cOCSPCertId); \
+ GetOCSPCertId((obj), (cid)); \
} while (0)
VALUE mOCSP;
View
12 ext/openssl/ossl_pkcs12.c
@@ -6,18 +6,18 @@
#include "ossl.h"
#define WrapPKCS12(klass, obj, p12) do { \
- if(!p12) ossl_raise(rb_eRuntimeError, "PKCS12 wasn't initialized."); \
- obj = Data_Wrap_Struct(klass, 0, PKCS12_free, p12); \
+ if(!(p12)) ossl_raise(rb_eRuntimeError, "PKCS12 wasn't initialized."); \
+ (obj) = Data_Wrap_Struct((klass), 0, PKCS12_free, (p12)); \
} while (0)
#define GetPKCS12(obj, p12) do { \
- Data_Get_Struct(obj, PKCS12, p12); \
- if(!p12) ossl_raise(rb_eRuntimeError, "PKCS12 wasn't initialized."); \
+ Data_Get_Struct((obj), PKCS12, (p12)); \
+ if(!(p12)) ossl_raise(rb_eRuntimeError, "PKCS12 wasn't initialized."); \
} while (0)
#define SafeGetPKCS12(obj, p12) do { \
- OSSL_Check_Kind(obj, cPKCS12); \
- GetPKCS12(obj, p12); \
+ OSSL_Check_Kind((obj), cPKCS12); \
+ GetPKCS12((obj), (p12)); \
} while (0)
#define ossl_pkcs12_set_key(o,v) rb_iv_set((o), "@key", (v))
View
38 ext/openssl/ossl_pkcs7.c
@@ -11,57 +11,57 @@
#include "ossl.h"
#define WrapPKCS7(klass, obj, pkcs7) do { \
- if (!pkcs7) { \
+ if (!(pkcs7)) { \
ossl_raise(rb_eRuntimeError, "PKCS7 wasn't initialized."); \
} \
- obj = Data_Wrap_Struct(klass, 0, PKCS7_free, pkcs7); \
+ (obj) = Data_Wrap_Struct((klass), 0, PKCS7_free, (pkcs7)); \
} while (0)
#define GetPKCS7(obj, pkcs7) do { \
- Data_Get_Struct(obj, PKCS7, pkcs7); \
- if (!pkcs7) { \
+ Data_Get_Struct((obj), PKCS7, (pkcs7)); \
+ if (!(pkcs7)) { \
ossl_raise(rb_eRuntimeError, "PKCS7 wasn't initialized."); \
} \
} while (0)
#define SafeGetPKCS7(obj, pkcs7) do { \
- OSSL_Check_Kind(obj, cPKCS7); \
- GetPKCS7(obj, pkcs7); \
+ OSSL_Check_Kind((obj), cPKCS7); \
+ GetPKCS7((obj), (pkcs7)); \
} while (0)
#define WrapPKCS7si(klass, obj, p7si) do { \
- if (!p7si) { \
+ if (!(p7si)) { \
ossl_raise(rb_eRuntimeError, "PKCS7si wasn't initialized."); \
} \
- obj = Data_Wrap_Struct(klass, 0, PKCS7_SIGNER_INFO_free, p7si); \
+ (obj) = Data_Wrap_Struct((klass), 0, PKCS7_SIGNER_INFO_free, (p7si)); \
} while (0)
#define GetPKCS7si(obj, p7si) do { \
- Data_Get_Struct(obj, PKCS7_SIGNER_INFO, p7si); \
- if (!p7si) { \
+ Data_Get_Struct((obj), PKCS7_SIGNER_INFO, (p7si)); \
+ if (!(p7si)) { \
ossl_raise(rb_eRuntimeError, "PKCS7si wasn't initialized."); \
} \
} while (0)
#define SafeGetPKCS7si(obj, p7si) do { \
- OSSL_Check_Kind(obj, cPKCS7Signer); \
- GetPKCS7si(obj, p7si); \
+ OSSL_Check_Kind((obj), cPKCS7Signer); \
+ GetPKCS7si((obj), (p7si)); \
} while (0)
#define WrapPKCS7ri(klass, obj, p7ri) do { \
- if (!p7ri) { \
+ if (!(p7ri)) { \
ossl_raise(rb_eRuntimeError, "PKCS7ri wasn't initialized."); \
} \
- obj = Data_Wrap_Struct(klass, 0, PKCS7_RECIP_INFO_free, p7ri); \
+ (obj) = Data_Wrap_Struct((klass), 0, PKCS7_RECIP_INFO_free, (p7ri)); \
} while (0)
#define GetPKCS7ri(obj, p7ri) do { \
- Data_Get_Struct(obj, PKCS7_RECIP_INFO, p7ri); \
- if (!p7ri) { \
+ Data_Get_Struct((obj), PKCS7_RECIP_INFO, (p7ri)); \
+ if (!(p7ri)) { \
ossl_raise(rb_eRuntimeError, "PKCS7ri wasn't initialized."); \
} \
} while (0)
#define SafeGetPKCS7ri(obj, p7ri) do { \
- OSSL_Check_Kind(obj, cPKCS7Recipient); \
- GetPKCS7ri(obj, p7ri); \
+ OSSL_Check_Kind((obj), cPKCS7Recipient); \
+ GetPKCS7ri((obj), (p7ri)); \
} while (0)
-#define numberof(ary) (int)(sizeof(ary)/sizeof(ary[0]))
+#define numberof(ary) (int)(sizeof(ary)/sizeof((ary)[0]))
#define ossl_pkcs7_set_data(o,v) rb_iv_set((o), "@data", (v))
#define ossl_pkcs7_get_data(o) rb_iv_get((o), "@data")
View
16 ext/openssl/ossl_pkey.h
@@ -21,21 +21,21 @@ extern ID id_private_q;
#define OSSL_PKEY_IS_PRIVATE(obj) (rb_iv_get((obj), "private") == Qtrue)
#define WrapPKey(klass, obj, pkey) do { \
- if (!pkey) { \
+ if (!(pkey)) { \
rb_raise(rb_eRuntimeError, "PKEY wasn't initialized!"); \
} \
- obj = Data_Wrap_Struct(klass, 0, EVP_PKEY_free, pkey); \
+ (obj) = Data_Wrap_Struct((klass), 0, EVP_PKEY_free, (pkey)); \
OSSL_PKEY_SET_PUBLIC(obj); \
} while (0)
#define GetPKey(obj, pkey) do {\
- Data_Get_Struct(obj, EVP_PKEY, pkey);\
- if (!pkey) { \
+ Data_Get_Struct((obj), EVP_PKEY, (pkey));\
+ if (!(pkey)) { \
rb_raise(rb_eRuntimeError, "PKEY wasn't initialized!");\
} \
} while (0)
#define SafeGetPKey(obj, pkey) do { \
- OSSL_Check_Kind(obj, cPKey); \
- GetPKey(obj, pkey); \
+ OSSL_Check_Kind((obj), cPKey); \
+ GetPKey((obj), (pkey)); \
} while (0)
void ossl_generate_cb(int, int, void *);
@@ -134,8 +134,8 @@ static VALUE ossl_##keytype##_set_##name(VALUE self, VALUE bignum) \
#define DEF_OSSL_PKEY_BN(class, keytype, name) \
do { \
- rb_define_method(class, #name, ossl_##keytype##_get_##name, 0); \
- rb_define_method(class, #name "=", ossl_##keytype##_set_##name, 1);\
+ rb_define_method((class), #name, ossl_##keytype##_get_##name, 0); \
+ rb_define_method((class), #name "=", ossl_##keytype##_set_##name, 1);\
} while (0)
#endif /* _OSSL_PKEY_H_ */
View
4 ext/openssl/ossl_pkey_dh.c
@@ -13,8 +13,8 @@
#include "ossl.h"
#define GetPKeyDH(obj, pkey) do { \
- GetPKey(obj, pkey); \
- if (EVP_PKEY_type(pkey->type) != EVP_PKEY_DH) { /* PARANOIA? */ \
+ GetPKey((obj), (pkey)); \
+ if (EVP_PKEY_type((pkey)->type) != EVP_PKEY_DH) { /* PARANOIA? */ \
ossl_raise(rb_eRuntimeError, "THIS IS NOT A DH!") ; \
} \
} while (0)
View
4 ext/openssl/ossl_pkey_dsa.c
@@ -13,8 +13,8 @@
#include "ossl.h"
#define GetPKeyDSA(obj, pkey) do { \
- GetPKey(obj, pkey); \
- if (EVP_PKEY_type(pkey->type) != EVP_PKEY_DSA) { /* PARANOIA? */ \
+ GetPKey((obj), (pkey)); \
+ if (EVP_PKEY_type((pkey)->type) != EVP_PKEY_DSA) { /* PARANOIA? */ \
ossl_raise(rb_eRuntimeError, "THIS IS NOT A DSA!"); \
} \
} while (0)
View
8 golf_prelude.rb
@@ -112,3 +112,11 @@ def #{meth}(*args, &block)
alias old_inspect inspect
alias inspect old_to_s
end
+
+class Symbol
+ def call(*args, &block)
+ proc do |recv|
+ recv.__send__(self, *args, &block)
+ end
+ end
+end
View
363 lib/date.rb
@@ -5,10 +5,6 @@
#
# Documentation: William Webber <william@williamwebber.com>
#
-#--
-# $Id: date.rb,v 2.37 2008-01-17 20:16:31+09 tadf Exp $
-#++
-#
# == Overview
#
# This file provides two classes for working with
@@ -280,6 +276,15 @@ def coerce(other)
end
end
+ def to_f
+ return 0 if @d == 0
+ if @d > 0
+ Float::INFINITY
+ else
+ -Float::INFINITY
+ end
+ end
+
end
# The Julian Day Number of the Day of Calendar Reform for Italy
@@ -443,8 +448,14 @@ def commercial_to_jd(y, w, d, sg=GREGORIAN) # :nodoc:
# [commercial_year, week_of_year, day_of_week]
def jd_to_commercial(jd, sg=GREGORIAN) # :nodoc:
a = jd_to_civil(jd - 3, sg)[0]
- y = if jd >= commercial_to_jd(a + 1, 1, 1, sg) then a + 1 else a end
- w = 1 + ((jd - commercial_to_jd(y, 1, 1, sg)) / 7).floor
+ j = commercial_to_jd(a + 1, 1, 1, sg)
+ if jd >= j
+ y = a + 1
+ else
+ j = commercial_to_jd(a, 1, 1, sg)
+ y = a
+ end
+ w = 1 + ((jd - j) / 7).floor
d = (jd + 1) % 7
d = 7 if d == 0
return y, w, d
@@ -719,26 +730,31 @@ def self.julian_leap? (y) y % 4 == 0 end
def self.gregorian_leap? (y) y % 4 == 0 && y % 100 != 0 || y % 400 == 0 end
class << self; alias_method :leap?, :gregorian_leap? end
- class << self; alias_method :new!, :new end
- def self.valid_jd? (jd, sg=ITALY)
+ def self.valid_jd_r? (jd, sg=ITALY)
!!_valid_jd?(jd, sg)
end
- def self.valid_ordinal? (y, d, sg=ITALY)
+ private_class_method :valid_jd_r?
+
+ def self.valid_ordinal_r? (y, d, sg=ITALY)
!!_valid_ordinal?(y, d, sg)
end
- def self.valid_civil? (y, m, d, sg=ITALY)
+ private_class_method :valid_ordinal_r?
+
+ def self.valid_civil_r? (y, m, d, sg=ITALY)
!!_valid_civil?(y, m, d, sg)
end
- class << self; alias_method :valid_date?, :valid_civil? end
+ private_class_method :valid_civil_r?
- def self.valid_commercial? (y, w, d, sg=ITALY)
+ def self.valid_commercial_r? (y, w, d, sg=ITALY)
!!_valid_commercial?(y, w, d, sg)
end
+ private_class_method :valid_commercial_r?
+
def self.valid_weeknum? (y, w, d, f, sg=ITALY) # :nodoc:
!!_valid_weeknum?(y, w, d, f, sg)
end
@@ -757,16 +773,28 @@ def self.valid_time? (h, min, s) # :nodoc:
private_class_method :valid_time?
+ def self.new!(ajd=0, of=0, sg=ITALY)
+ jd, df = ajd_to_jd(ajd, 0)
+ if !(Fixnum === jd) ||
+ jd < sg || df !=0 || of != 0 ||
+ jd < -327 || jd > 366963925
+ return new_r!(ajd, of, sg)
+ end
+ new_l!(jd, sg)
+ end
+
# Create a new Date object from a Julian Day Number.
#
# +jd+ is the Julian Day Number; if not specified, it defaults to
# 0.
# +sg+ specifies the Day of Calendar Reform.
- def self.jd(jd=0, sg=ITALY)
+ def self.jd_r(jd=0, sg=ITALY) # :nodoc:
jd = _valid_jd?(jd, sg)
- new!(jd_to_ajd(jd, 0, 0), 0, sg)
+ new_r!(jd_to_ajd(jd, 0, 0), 0, sg)
end
+ private_class_method :jd_r
+
# Create a new Date object from an Ordinal Date, specified
# by year +y+ and day-of-year +d+. +d+ can be negative,
# in which it counts backwards from the end of the year.
@@ -777,13 +805,15 @@ def self.jd(jd=0, sg=ITALY)
# Number day 0.
#
# +sg+ specifies the Day of Calendar Reform.
- def self.ordinal(y=-4712, d=1, sg=ITALY)
+ def self.ordinal_r(y=-4712, d=1, sg=ITALY) # :nodoc:
unless jd = _valid_ordinal?(y, d, sg)
raise ArgumentError, 'invalid date'
end
- new!(jd_to_ajd(jd, 0, 0), 0, sg)
+ new_r!(jd_to_ajd(jd, 0, 0), 0, sg)
end
+ private_class_method :ordinal_r
+
# Create a new Date object for the Civil Date specified by
# year +y+, month +m+, and day-of-month +d+.
#
@@ -797,14 +827,14 @@ def self.ordinal(y=-4712, d=1, sg=ITALY)
# Julian Day Number day 0.
#
# +sg+ specifies the Day of Calendar Reform.
- def self.civil(y=-4712, m=1, d=1, sg=ITALY)
+ def self.civil_r(y=-4712, m=1, d=1, sg=ITALY) # :nodoc:
unless jd = _valid_civil?(y, m, d, sg)
raise ArgumentError, 'invalid date'
end
- new!(jd_to_ajd(jd, 0, 0), 0, sg)
+ new_r!(jd_to_ajd(jd, 0, 0), 0, sg)
end
- class << self; alias_method :new, :civil end
+ private_class_method :civil_r
# Create a new Date object for the Commercial Date specified by
# year +y+, week-of-year +w+, and day-of-week +d+.
@@ -820,13 +850,15 @@ class << self; alias_method :new, :civil end
# Julian Day Number day 0.
#
# +sg+ specifies the Day of Calendar Reform.
- def self.commercial(y=-4712, w=1, d=1, sg=ITALY)
+ def self.commercial_r(y=-4712, w=1, d=1, sg=ITALY) # :nodoc:
unless jd = _valid_commercial?(y, w, d, sg)
raise ArgumentError, 'invalid date'
end
- new!(jd_to_ajd(jd, 0, 0), 0, sg)
+ new_r!(jd_to_ajd(jd, 0, 0), 0, sg)
end
+ private_class_method :commercial_r
+
def self.weeknum(y=-4712, w=0, d=1, f=0, sg=ITALY)
unless jd = _valid_weeknum?(y, w, d, f, sg)
raise ArgumentError, 'invalid date'
@@ -1099,7 +1131,7 @@ def once(*ids) # :nodoc: -- restricted
alias_method :__#{id.object_id}__, :#{id.to_s}
private :__#{id.object_id}__
def #{id.to_s}(*args)
- @__ca__[#{id.object_id}] ||= __#{id.object_id}__(*args)
+ __ca__[#{id.object_id}] ||= __#{id.object_id}__(*args)
end
end;
end
@@ -1109,96 +1141,69 @@ def #{id.to_s}(*args)
end
- # *NOTE* this is the documentation for the method new!(). If
- # you are reading this as the documentation for new(), that is
- # because rdoc doesn't fully support the aliasing of the
- # initialize() method.
- # new() is in
- # fact an alias for #civil(): read the documentation for that
- # method instead.
- #
- # Create a new Date object.
- #
- # +ajd+ is the Astronomical Julian Day Number.
- # +of+ is the offset from UTC as a fraction of a day.
- # Both default to 0.
- #
- # +sg+ specifies the Day of Calendar Reform to use for this
- # Date object.
- #
- # Using one of the factory methods such as Date::civil is
- # generally easier and safer.
- def initialize(ajd=0, of=0, sg=ITALY)
- @ajd, @of, @sg = ajd, of, sg
- @__ca__ = {}
- end
-
- # Get the date as an Astronomical Julian Day Number.
- def ajd() @ajd end
-
# Get the date as an Astronomical Modified Julian Day Number.
- def amjd() ajd_to_amjd(@ajd) end
+ def amjd_r() ajd_to_amjd(ajd) end
- once :amjd
+ once :amjd_r
- def daynum() ajd_to_jd(@ajd, @of) end
+ def daynum() ajd_to_jd(ajd, offset) end
once :daynum
private :daynum
# Get the date as a Julian Day Number.
- def jd() daynum[0] end
+ def jd_r() daynum[0] end # :nodoc:
# Get any fractional day part of the date.
- def day_fraction() daynum[1] end
+ def day_fraction_r() daynum[1] end # :nodoc:
# Get the date as a Modified Julian Day Number.
- def mjd() jd_to_mjd(jd) end
+ def mjd_r() jd_to_mjd(jd) end # :nodoc:
# Get the date as the number of days since the Day of Calendar
# Reform (in Italy and the Catholic countries).
- def ld() jd_to_ld(jd) end
+ def ld_r() jd_to_ld(jd) end # :nodoc:
- once :jd, :day_fraction, :mjd, :ld
+ once :jd_r, :day_fraction_r, :mjd_r, :ld_r
+ private :jd_r, :day_fraction_r, :mjd_r, :ld_r
# Get the date as a Civil Date, [year, month, day_of_month]
- def civil() jd_to_civil(jd, @sg) end # :nodoc:
+ def civil() jd_to_civil(jd, start) end # :nodoc:
# Get the date as an Ordinal Date, [year, day_of_year]
- def ordinal() jd_to_ordinal(jd, @sg) end # :nodoc:
+ def ordinal() jd_to_ordinal(jd, start) end # :nodoc:
# Get the date as a Commercial Date, [year, week_of_year, day_of_week]
- def commercial() jd_to_commercial(jd, @sg) end # :nodoc:
+ def commercial() jd_to_commercial(jd, start) end # :nodoc:
- def weeknum0() jd_to_weeknum(jd, 0, @sg) end # :nodoc:
- def weeknum1() jd_to_weeknum(jd, 1, @sg) end # :nodoc:
+ def weeknum0() jd_to_weeknum(jd, 0, start) end # :nodoc:
+ def weeknum1() jd_to_weeknum(jd, 1, start) end # :nodoc:
once :civil, :ordinal, :commercial, :weeknum0, :weeknum1
private :civil, :ordinal, :commercial, :weeknum0, :weeknum1
# Get the year of this date.
- def year() civil[0] end
+ def year_r() civil[0] end # :nodoc:
# Get the day-of-the-year of this date.
#
# January 1 is day-of-the-year 1
- def yday() ordinal[1] end
+ def yday_r() ordinal[1] end # :nodoc:
# Get the month of this date.
#
# January is month 1.
- def mon() civil[1] end
+ def mon_r() civil[1] end # :nodoc:
# Get the day-of-the-month of this date.
- def mday() civil[2] end
+ def mday_r() civil[2] end # :nodoc:
- alias_method :month, :mon
- alias_method :day, :mday
+ private :year_r, :yday_r, :mon_r, :mday_r
- def wnum0() weeknum0[1] end # :nodoc:
- def wnum1() weeknum1[1] end # :nodoc:
+ def wnum0_r() weeknum0[1] end # :nodoc:
+ def wnum1_r() weeknum1[1] end # :nodoc:
- private :wnum0, :wnum1
+ private :wnum0_r, :wnum1_r
# Get the time of this date as [hours, minutes, seconds,
# fraction_of_a_second]
@@ -1210,25 +1215,20 @@ def time_sf() day_fraction % SECONDS_IN_DAY * 86400 end # :nodoc:
private :time, :time_wo_sf, :time_sf
# Get the hour of this date.
- def hour() time_wo_sf[0] end # 4p
+ def hour_r() time_wo_sf[0] end # :nodoc: # 4p
# Get the minute of this date.
- def min() time_wo_sf[1] end # 4p
+ def min_r() time_wo_sf[1] end # :nodoc: # 4p
# Get the second of this date.
- def sec() time_wo_sf[2] end # 4p
+ def sec_r() time_wo_sf[2] end # :nodoc: # 4p
# Get the fraction-of-a-second of this date.
- def sec_fraction() time_sf end # 4p
-
- alias_method :minute, :min
- alias_method :second, :sec
- alias_method :second_fraction, :sec_fraction
+ def sec_fraction_r() time_sf end # 4p
- private :hour, :min, :sec, :sec_fraction,
- :minute, :second, :second_fraction
+ private :hour_r, :min_r, :sec_r, :sec_fraction_r
- def zone # 4p - strftime('%:z')
+ def zone_r # :nodoc: # 4p - strftime('%:z')
sign = if offset < 0 then '-' else '+' end
fr = offset.abs
ss = fr.div(SECONDS_IN_DAY)
@@ -1237,24 +1237,27 @@ def zone # 4p - strftime('%:z')
format('%s%02d:%02d', sign, hh, mm)
end
- private :zone
+ private :zone_r
# Get the commercial year of this date. See *Commercial* *Date*
# in the introduction for how this differs from the normal year.
- def cwyear() commercial[0] end
+ def cwyear_r() commercial[0] end # :nodoc:
# Get the commercial week of the year of this date.
- def cweek() commercial[1] end
+ def cweek_r() commercial[1] end # :nodoc:
# Get the commercial day of the week of this date. Monday is
# commercial day-of-week 1; Sunday is commercial day-of-week 7.
- def cwday() commercial[2] end
+ def cwday_r() commercial[2] end # :nodoc:
+
+ private :cwyear_r, :cweek_r, :cwday_r
# Get the week day of this date. Sunday is day-of-week 0;
# Saturday is day-of-week 6.
- def wday() jd_to_wday(jd) end
+ def wday_r() jd_to_wday(jd) end # :nodoc:
- once :wday
+ once :wday_r
+ private :wday_r
=begin
MONTHNAMES.each_with_index do |n, i|
@@ -1268,19 +1271,20 @@ def wday() jd_to_wday(jd) end
define_method(n.downcase + '?'){wday == i}
end
- def nth_kday? (n, k)
+ def nth_kday? (n, k) # :nodoc:
k == wday && jd === nth_kday_to_jd(year, mon, n, k, start)
end
private :nth_kday?
# Is the current date old-style (Julian Calendar)?
- def julian? () jd < @sg end
+ def julian_r? () jd < start end # :nodoc:
# Is the current date new-style (Gregorian Calendar)?
- def gregorian? () !julian? end
+ def gregorian_r? () !julian? end # :nodoc:
- once :julian?, :gregorian?
+ once :julian_r?, :gregorian_r?
+ private :julian_r?, :gregorian_r?
def fix_style # :nodoc:
if julian?
@@ -1291,18 +1295,21 @@ def fix_style # :nodoc:
private :fix_style
# Is this a leap year?
- def leap?
+ def leap_r? # :nodoc:
jd_to_civil(civil_to_jd(year, 3, 1, fix_style) - 1,
fix_style)[-1] == 29
end
- once :leap?
+ once :leap_r?
+ private :leap_r?
# When is the Day of Calendar Reform for this Date object?
- def start() @sg end
+ def start_r() @sg end # :nodoc:
# Create a copy of this Date object using a new Day of Calendar Reform.
- def new_start(sg=self.class::ITALY) self.class.new!(@ajd, @of, sg) end
+ def new_start_r(sg=self.class::ITALY) self.class.new_r!(ajd, offset, sg) end # :nodoc:
+
+ private :start_r, :new_start_r
# Create a copy of this Date object that uses the Italian/Catholic
# Day of Calendar Reform.
@@ -1320,16 +1327,16 @@ def julian() new_start(self.class::JULIAN) end
# Calendar.
def gregorian() new_start(self.class::GREGORIAN) end
- def offset() @of end
-
- def new_offset(of=0)
+ def new_offset_r(of=0) # :nodoc:
if String === of
of = Rational(zone_to_diff(of) || 0, 86400)
+ elsif Float === of
+ of = Rational((of * 86400).round, 86400)
end
- self.class.new!(@ajd, of, @sg)
+ self.class.new_r!(ajd, of, start)
end
- private :offset, :new_offset
+ private :new_offset_r
# Return a new Date object that is +n+ days later than the
# current one.
@@ -1340,13 +1347,19 @@ def new_offset(of=0)
#
# If +n+ is not a Numeric, a TypeError will be thrown. In
# particular, two Dates cannot be added to each other.
- def + (n)
+ def plus_r (n) # :nodoc:
case n
- when Numeric; return self.class.new!(@ajd + n, @of, @sg)
+ when Numeric
+ if Float === n
+ n = Rational((n * 86400000000000).round, 86400000000000)
+ end
+ return self.class.new_r!(ajd + n, offset, start)
end
raise TypeError, 'expected numeric'
end
+ private :plus_r
+
# If +x+ is a Numeric value, create a new Date object that is
# +x+ days earlier than the current one.
#
@@ -1355,14 +1368,21 @@ def + (n)
# date is than +x+.
#
# If +x+ is neither Numeric nor a Date, a TypeError is raised.
- def - (x)
+ def minus_r (x) # :nodoc:
case x
- when Numeric; return self.class.new!(@ajd - x, @of, @sg)
- when Date; return @ajd - x.ajd
+ when Numeric
+ if Float === x
+ x = Rational((x * 86400000000000).round, 86400000000000)
+ end
+ return self.class.new_r!(ajd - x, offset, start)
+ when Date
+ return ajd - x.ajd
end
raise TypeError, 'expected numeric or date'
end
+ private :minus_r
+
# Compare this date with another date.
#
# +other+ can also be a Numeric value, in which case it is
@@ -1374,10 +1394,10 @@ def - (x)
# two DateTime instances. When comparing a DateTime instance
# with a Date instance, the time of the latter will be
# considered as falling on midnight UTC.
- def <=> (other)
+ def cmp_r (other) # :nodoc:
case other
- when Numeric; return @ajd <=> other
- when Date; return @ajd <=> other.ajd
+ when Numeric; return ajd <=> other
+ when Date; return ajd <=> other.ajd
else
begin
l, r = other.coerce(self)
@@ -1388,13 +1408,15 @@ def <=> (other)
nil
end
+ private :cmp_r
+
# The relationship operator for Date.
#
# Compares dates by Julian Day Number. When comparing
# two DateTime instances, or a DateTime with a Date,
# the instances will be regarded as equivalent if they
# fall on the same date in local time.
- def === (other)
+ def equal_r (other) # :nodoc:
case other
when Numeric; return jd == other
when Date; return jd == other.jd
@@ -1408,6 +1430,8 @@ def === (other)
false
end
+ private :equal_r
+
def next_day(n=1) self + n end
def prev_day(n=1) self - n end
@@ -1426,7 +1450,7 @@ def >> (n)
y, m = (year * 12 + (mon - 1) + n).divmod(12)
m, = (m + 1) .divmod(1)
d = mday
- until jd2 = _valid_civil?(y, m, d, @sg)
+ until jd2 = _valid_civil?(y, m, d, start)
d -= 1
raise ArgumentError, 'invalid date' unless d > 0
end
@@ -1486,29 +1510,28 @@ def downto(min, &block) # :yield: date
# Is this Date equal to +other+?
#
# +other+ must both be a Date object, and represent the same date.
- def eql? (other) Date === other && self == other end
+ def eql_r? (other) Date === other && self == other end # :nodoc:
+
+ private :eql_r?
# Calculate a hash value for this date.
- def hash() @ajd.hash end
+ def hash_r() ajd.hash end # :nodoc:
+
+ private :hash_r
# Return internal object state as a programmer-readable string.
- def inspect
- format('#<%s: %s (%s,%s,%s)>', self.class, to_s, @ajd, @of, @sg)
+ def inspect_r # :nodoc:
+ format('#<%s[R]: %s (%s,%s,%s)>', self.class, to_s_r, ajd, offset, start)
end
+ private :inspect_r
+
# Return the date as a human-readable string.
#
# The format used is YYYY-MM-DD.
- def to_s() format('%.4d-%02d-%02d', year, mon, mday) end # 4p
-
- # Dump to Marshal format.
- def marshal_dump() [@ajd, @of, @sg] end
+ def to_s_r() format('%.4d-%02d-%02d', year, mon, mday) end # :nodoc: # 4p
- # Load from Marshal format.
- def marshal_load(a)
- @ajd, @of, @sg, = a
- @__ca__ = {}
- end
+ private :to_s_r
end
@@ -1562,6 +1585,19 @@ def marshal_load(a)
#
class DateTime < Date
+ def self.new!(ajd=0, of=0, sg=ITALY)
+ jd, df = ajd_to_jd(ajd, 0)
+ df, sf = (df * 86400).divmod(1)
+ sf, ssf = (sf * 1000000000).divmod(1)
+ odf, osf = (of * 86400).divmod(1)
+ if !(Fixnum === jd) ||
+ jd < sg || ssf != 0 || osf != 0 ||
+ jd < -327 || jd > 366963925
+ return new_r!(ajd, of, sg)
+ end
+ new_l!(jd, df, sf, odf, sg)
+ end
+
# Create a new DateTime object corresponding to the specified
# Julian Day Number +jd+ and hour +h+, minute +min+, second +s+.
#
@@ -1575,17 +1611,21 @@ class DateTime < Date
# +sg+ specifies the Day of Calendar Reform.
#
# All day/time values default to 0.
- def self.jd(jd=0, h=0, min=0, s=0, of=0, sg=ITALY)
+ def self.jd_r(jd=0, h=0, min=0, s=0, of=0, sg=ITALY) # :nodoc:
unless (jd = _valid_jd?(jd, sg)) &&
(fr = _valid_time?(h, min, s))
raise ArgumentError, 'invalid date'
end
if String === of
of = Rational(zone_to_diff(of) || 0, 86400)
+ elsif Float === of
+ of = Rational((of * 86400).round, 86400)
end
- new!(jd_to_ajd(jd, fr, of), of, sg)
+ new_r!(jd_to_ajd(jd, fr, of), of, sg)
end
+ private_class_method :jd_r
+
# Create a new DateTime object corresponding to the specified
# Ordinal Date and hour +h+, minute +min+, second +s+.
#
@@ -1600,17 +1640,21 @@ def self.jd(jd=0, h=0, min=0, s=0, of=0, sg=ITALY)
#
# +y+ defaults to -4712, and +d+ to 1; this is Julian Day Number
# day 0. The time values default to 0.
- def self.ordinal(y=-4712, d=1, h=0, min=0, s=0, of=0, sg=ITALY)
+ def self.ordinal_r(y=-4712, d=1, h=0, min=0, s=0, of=0, sg=ITALY) # :nodoc:
unless (jd = _valid_ordinal?(y, d, sg)) &&
(fr = _valid_time?(h, min, s))
raise ArgumentError, 'invalid date'
end
if String === of
of = Rational(zone_to_diff(of) || 0, 86400)
+ elsif Float === of
+ of = Rational((of * 86400).round, 86400)
end
- new!(jd_to_ajd(jd, fr, of), of, sg)
+ new_r!(jd_to_ajd(jd, fr, of), of, sg)
end
+ private_class_method :ordinal_r
+
# Create a new DateTime object corresponding to the specified
# Civil Date and hour +h+, minute +min+, second +s+.
#
@@ -1625,18 +1669,20 @@ def self.ordinal(y=-4712, d=1, h=0, min=0, s=0, of=0, sg=ITALY)
#
# +y+ defaults to -4712, +m+ to 1, and +d+ to 1; this is Julian Day
# Number day 0. The time values default to 0.
- def self.civil(y=-4712, m=1, d=1, h=0, min=0, s=0, of=0, sg=ITALY)
+ def self.civil_r(y=-4712, m=1, d=1, h=0, min=0, s=0, of=0, sg=ITALY) # :nodoc:
unless (jd = _valid_civil?(y, m, d, sg)) &&
(fr = _valid_time?(h, min, s))
raise ArgumentError, 'invalid date'
end
if String === of
of = Rational(zone_to_diff(of) || 0, 86400)
+ elsif Float === of
+ of = Rational((of * 86400).round, 86400)
end
- new!(jd_to_ajd(jd, fr, of), of, sg)
+ new_r!(jd_to_ajd(jd, fr, of), of, sg)
end
- class << self; alias_method :new, :civil end
+ private_class_method :civil_r
# Create a new DateTime object corresponding to the specified
# Commercial Date and hour +h+, minute +min+, second +s+.
@@ -1653,17 +1699,21 @@ class << self; alias_method :new, :civil end
# +y+ defaults to -4712, +w+ to 1, and +d+ to 1; this is
# Julian Day Number day 0.
# The time values default to 0.
- def self.commercial(y=-4712, w=1, d=1, h=0, min=0, s=0, of=0, sg=ITALY)
+ def self.commercial_r(y=-4712, w=1, d=1, h=0, min=0, s=0, of=0, sg=ITALY) # :nodoc:
unless (jd = _valid_commercial?(y, w, d, sg)) &&
(fr = _valid_time?(h, min, s))
raise ArgumentError, 'invalid date'
end
if String === of
of = Rational(zone_to_diff(of) || 0, 86400)
+ elsif Float === of
+ of = Rational((of * 86400).round, 86400)
end
- new!(jd_to_ajd(jd, fr, of), of, sg)
+ new_r!(jd_to_ajd(jd, fr, of), of, sg)
end
+ private_class_method :commercial_r
+
def self.weeknum(y=-4712, w=0, d=1, f=0, h=0, min=0, s=0, of=0, sg=ITALY) # :nodoc:
unless (jd = _valid_weeknum?(y, w, d, f, sg)) &&
(fr = _valid_time?(h, min, s))
@@ -1671,6 +1721,8 @@ def self.weeknum(y=-4712, w=0, d=1, f=0, h=0, min=0, s=0, of=0, sg=ITALY) # :nod
end
if String === of
of = Rational(zone_to_diff(of) || 0, 86400)
+ elsif Float === of
+ of = Rational((of * 86400).round, 86400)
end
new!(jd_to_ajd(jd, fr, of), of, sg)
end
@@ -1684,6 +1736,8 @@ def self.nth_kday(y=-4712, m=1, n=1, k=1, h=0, min=0, s=0, of=0, sg=ITALY) # :no
end
if String === of
of = Rational(zone_to_diff(of) || 0, 86400)
+ elsif Float === of
+ of = Rational((of * 86400).round, 86400)
end
new!(jd_to_ajd(jd, fr, of), of, sg)
end
@@ -1770,14 +1824,13 @@ def self.jisx0301(str='-4712-01-01T00:00:00+00:00', sg=ITALY) # :nodoc:
new_by_frags(elem, sg)
end
- public :hour, :min, :sec, :sec_fraction, :zone, :offset, :new_offset,
- :minute, :second, :second_fraction
-
- def to_s # 4p
+ def to_s_r # :nodoc: # 4p
format('%.4d-%02d-%02dT%02d:%02d:%02d%s',
year, mon, mday, hour, min, sec, zone)
end
+ private :to_s_r
+
end
class Time
@@ -1795,7 +1848,7 @@ def to_datetime
Rational(subsec, 86400)
of = Rational(utc_offset, 86400)
DateTime.new!(DateTime.__send__(:jd_to_ajd, jd, fr, of),
- of, DateTime::ITALY)
+ of, DateTime::ITALY)
end
end
@@ -1804,30 +1857,7 @@ class Date
def to_time() Time.local(year, mon, mday) end
def to_date() self end
- def to_datetime() DateTime.new!(jd_to_ajd(jd, 0, 0), @of, @sg) end
-
- # Create a new Date object representing today.
- #
- # +sg+ specifies the Day of Calendar Reform.
- def self.today(sg=ITALY)
- t = Time.now
- jd = civil_to_jd(t.year, t.mon, t.mday, sg)
- new!(jd_to_ajd(jd, 0, 0), 0, sg)
- end
-
- # Create a new DateTime object representing the current time.
- #
- # +sg+ specifies the Day of Calendar Reform.
- def self.now(sg=ITALY)
- t = Time.now
- jd = civil_to_jd(t.year, t.mon, t.mday, sg)
- fr = time_to_day_fraction(t.hour, t.min, [t.sec, 59].min) +
- Rational(t.subsec, 86400)
- of = Rational(t.utc_offset, 86400)
- new!(jd_to_ajd(jd, fr, of), of, sg)
- end
-
- private_class_method :now
+ def to_datetime() DateTime.new!(jd_to_ajd(jd, 0, 0), offset, start) end
end
@@ -1839,13 +1869,12 @@ def to_time
Time.utc(year, mon, mday, hour, min, sec +
sec_fraction)
end.
- getlocal
+ getlocal
end
- def to_date() Date.new!(jd_to_ajd(jd, 0, 0), 0, @sg) end
+ def to_date() Date.new!(jd_to_ajd(jd, 0, 0), 0, start) end
def to_datetime() self end
- private_class_method :today
- public_class_method :now
-
end
+
+require 'date_core'
View
6 lib/tempfile.rb
@@ -96,11 +96,11 @@ class Tempfile < DelegateClass(File)
# element, and end with the second element. For example:
#
# file = Tempfile.new('hello')
- # file.path # => something like: "/tmp/foo2843-8392-92849382--0"
+ # file.path # => something like: "/tmp/hello2843-8392-92849382--0"
#
# # Use the Array form to enforce an extension in the filename:
# file = Tempfile.new(['hello', '.jpg'])
- # file.path # => something like: "/tmp/foo2843-8392-92849382--0.jpg"
+ # file.path # => something like: "/tmp/hello2843-8392-92849382--0.jpg"
#
# The temporary file will be placed in the directory as specified
# by the +tmpdir+ parameter. By default, this is +Dir.tmpdir+.
@@ -110,7 +110,7 @@ class Tempfile < DelegateClass(File)
# come from environment variables (e.g. <tt>$TMPDIR</tt>).
#
# file = Tempfile.new('hello', '/home/aisaka')
- # file.path # => something like: "/home/aisaka/foo2843-8392-92849382--0"
+ # file.path # => something like: "/home/aisaka/hello2843-8392-92849382--0"
#
# You can also pass an options hash. Under the hood, Tempfile creates
# the temporary file using +File.open+. These options will be passed to
View
4 marshal.c
@@ -876,7 +876,7 @@ clear_dump_arg(struct dump_arg *arg)
* def initialize(str)
* @str = str
* end
- * def sayHello
+ * def say_hello
* @str
* end
* end
@@ -886,7 +886,7 @@ clear_dump_arg(struct dump_arg *arg)
* o = Klass.new("hello\n")
* data = Marshal.dump(o)
* obj = Marshal.load(data)
- * obj.sayHello #=> "hello\n"
+ * obj.say_hello #=> "hello\n"
*
* Marshal can't dump following objects:
* * anonymous Class/Module.
View
14 proc.c
@@ -336,10 +336,10 @@ rb_binding_new(void)
* calling +eval+ to execute the evaluated command in this
* environment. Also see the description of class +Binding+.
*
- * def getBinding(param)
+ * def get_binding(param)
* return binding
* end
- * b = getBinding("hello")
+ * b = get_binding("hello")
* eval("param", b) #=> "hello"
*/
@@ -358,10 +358,10 @@ rb_f_binding(VALUE self)
* <em>lineno</em> parameters are present, they will be used when
* reporting syntax errors.
*
- * def getBinding(param)
+ * def get_binding(param)
* return binding
* end
- * b = getBinding("hello")
+ * b = get_binding("hello")
* b.eval("param") #=> "hello"
*/
@@ -2211,15 +2211,15 @@ Init_Proc(void)
* def initialize(n)
* @secret = n
* end
- * def getBinding
+ * def get_binding
* return binding()
* end
* end
*
* k1 = Demo.new(99)
- * b1 = k1.getBinding
+ * b1 = k1.get_binding
* k2 = Demo.new(-3)
- * b2 = k2.getBinding
+ * b2 = k2.get_binding
*
* eval("@secret", b1) #=> 99
* eval("@secret", b2) #=> -3
View
80 process.c
@@ -122,17 +122,6 @@ static VALUE rb_cProcessTms;
#endif
#endif
-#if SIZEOF_RLIM_T == SIZEOF_INT
-# define RLIM2NUM(v) UINT2NUM(v)
-# define NUM2RLIM(v) NUM2UINT(v)
-#elif SIZEOF_RLIM_T == SIZEOF_LONG
-# define RLIM2NUM(v) ULONG2NUM(v)
-# define NUM2RLIM(v) NUM2ULONG(v)
-#elif SIZEOF_RLIM_T == SIZEOF_LONG_LONG
-# define RLIM2NUM(v) ULL2NUM(v)
-# define NUM2RLIM(v) NUM2ULL(v)
-#endif
-
#define preserving_errno(stmts) \
do {int saved_errno = errno; stmts; errno = saved_errno;} while (0)
@@ -1294,7 +1283,7 @@ enum {
};
static VALUE
-check_exec_redirect_fd(VALUE v)
+check_exec_redirect_fd(VALUE v, int iskey)
{
VALUE tmp;
int fd;
@@ -1326,6 +1315,11 @@ check_exec_redirect_fd(VALUE v)
wrong:
rb_raise(rb_eArgError, "negative file descriptor");
}
+#ifdef _WIN32
+ else if (fd >= 3 && iskey) {
+ rb_raise(rb_eArgError, "wrong file descriptor (%d)", fd);
+ }
+#endif
return INT2FIX(fd);
}
@@ -1363,7 +1357,7 @@ check_exec_redirect(VALUE key, VALUE val, VALUE options)
break;
case T_FILE:
- val = check_exec_redirect_fd(val);
+ val = check_exec_redirect_fd(val, 0);
/* fall through */
case T_FIXNUM:
index = EXEC_OPTION_DUP2;
@@ -1375,7 +1369,7 @@ check_exec_redirect(VALUE key, VALUE val, VALUE options)
if (RARRAY_LEN(val) == 2 && SYMBOL_P(path) &&
SYM2ID(path) == rb_intern("child")) {
index = EXEC_OPTION_DUP2_CHILD;
- param = check_exec_redirect_fd(rb_ary_entry(val, 1));
+ param = check_exec_redirect_fd(rb_ary_entry(val, 1), 0);
}
else {
index = EXEC_OPTION_OPEN;
@@ -1399,7 +1393,7 @@ check_exec_redirect(VALUE key, VALUE val, VALUE options)
path = val;
FilePathValue(path);
if (TYPE(key) == T_FILE)
- key = check_exec_redirect_fd(key);
+ key = check_exec_redirect_fd(key, 1);
if (FIXNUM_P(key) && (FIX2INT(key) == 1 || FIX2INT(key) == 2))
flags = INT2NUM(O_WRONLY|O_CREAT|O_TRUNC);
else
@@ -1419,21 +1413,21 @@ check_exec_redirect(VALUE key, VALUE val, VALUE options)
rb_ary_store(options, index, ary);
}
if (TYPE(key) != T_ARRAY) {
- VALUE fd = check_exec_redirect_fd(key);
+ VALUE fd = check_exec_redirect_fd(key, !NIL_P(param));
rb_ary_push(ary, hide_obj(rb_assoc_new(fd, param)));
}
else {
int i, n=0;
for (i = 0 ; i < RARRAY_LEN(key); i++) {
VALUE v = RARRAY_PTR(key)[i];
- VALUE fd = check_exec_redirect_fd(v);
+ VALUE fd = check_exec_redirect_fd(v, !NIL_P(param));
rb_ary_push(ary, hide_obj(rb_assoc_new(fd, param)));
n++;
}
}
}
-#ifdef RLIM2NUM
+#if defined(HAVE_SETRLIMIT) && defined(NUM2RLIM)
static int rlimit_type_by_lname(const char *name);
#endif
@@ -1471,7 +1465,7 @@ rb_exec_arg_addopt(struct rb_exec_arg *e, VALUE key, VALUE val)
}
else
#endif
-#ifdef RLIM2NUM
+#if defined(HAVE_SETRLIMIT) && defined(NUM2RLIM)
if (strncmp("rlimit_", rb_id2name(id), 7) == 0 &&
(rtype = rlimit_type_by_lname(rb_id2name(id)+7)) != -1) {
VALUE ary = rb_ary_entry(options, EXEC_OPTION_RLIMIT);
@@ -2228,7 +2222,7 @@ run_exec_pgroup(VALUE obj, VALUE save, char *errmsg, size_t errmsg_buflen)
}
#endif
-#ifdef RLIM2NUM
+#if defined(HAVE_SETRLIMIT) && defined(RLIM2NUM)
static int
run_exec_rlimit(VALUE ary, VALUE save, char *errmsg, size_t errmsg_buflen)
{
@@ -2290,7 +2284,7 @@ rb_run_exec_options_err(const struct rb_exec_arg *e, struct rb_exec_arg *s, char
}
#endif
-#ifdef RLIM2NUM
+#if defined(HAVE_SETRLIMIT) && defined(RLIM2NUM)
obj = rb_ary_entry(options, EXEC_OPTION_RLIMIT);
if (!NIL_P(obj)) {
if (run_exec_rlimit(obj, soptions, errmsg, errmsg_buflen) == -1)
@@ -3632,7 +3626,7 @@ proc_setpriority(VALUE obj, VALUE which, VALUE who, VALUE prio)
#define proc_setpriority rb_f_notimplement
#endif
-#if defined(RLIM2NUM)
+#if defined(HAVE_SETRLIMIT) && defined(NUM2RLIM)
static int
rlimit_resource_name2int(const char *name, int casetype)
{
@@ -4526,7 +4520,28 @@ proc_setgid(VALUE obj, VALUE id)
#endif
-static int maxgroups = 32;
+/*
+ * Maximum supplementary groups are platform dependent.
+ * FWIW, 65536 is enough big for our supported OSs.
+ *
+ * OS Name max groups
+ * -----------------------------------------------
+ * Linux Kernel >= 2.6.3 65536
+ * Linux Kernel < 2.6.3 32
+ * IBM AIX 5.2 64
+ * IBM AIX 5.3 ... 6.1 128
+ * IBM AIX 7.1 128 (can be configured to be up to 2048)
+ * OpenBSD, NetBSD 16
+ * FreeBSD < 8.0 16
+ * FreeBSD >=8.0 1023
+ * Darwin (Mac OS X) 16
+ * Sun Solaris 7,8,9,10 16
+ * Sun Solaris 11 / OpenSolaris 1024
+ * HP-UX 20
+ * Windows 1015
+ */
+#define RB_MAX_GROUPS (65536)
+static int maxgroups = RB_MAX_GROUPS;
#ifdef HAVE_GETGROUPS
@@ -4548,9 +4563,13 @@ proc_getgroups(VALUE obj)
int i, ngroups;
rb_gid_t *groups;
- groups = ALLOCA_N(rb_gid_t, maxgroups);
+ ngroups = getgroups(0, NULL);
+ if (ngroups == -1)
+ rb_sys_fail(0);
+
+ groups = ALLOCA_N(rb_gid_t, ngroups);
- ngroups = getgroups(maxgroups, groups);
+ ngroups = getgroups(ngroups, groups);
if (ngroups == -1)
rb_sys_fail(0);
@@ -4687,10 +4706,13 @@ proc_getmaxgroups(VALUE obj)
static VALUE
proc_setmaxgroups(VALUE obj, VALUE val)
{
- int ngroups = FIX2UINT(val);
+ int ngroups = FIX2INT(val);
- if (ngroups > 4096)
- ngroups = 4096;
+ if (ngroups <= 0)
+ rb_raise(rb_eArgError, "maxgroups %d shold be positive", ngroups);
+
+ if (ngroups > RB_MAX_GROUPS)
+ ngroups = RB_MAX_GROUPS;
maxgroups = ngroups;
@@ -5668,7 +5690,7 @@ Init_process(void)
rb_define_module_function(rb_mProcess, "getrlimit", proc_getrlimit, 1);
rb_define_module_function(rb_mProcess, "setrlimit", proc_setrlimit, -1);
-#ifdef RLIM2NUM
+#if defined(RLIM2NUM) && defined(RLIM_INFINITY)
{
VALUE inf = RLIM2NUM(RLIM_INFINITY);
#ifdef RLIM_SAVED_MAX
View
4 strftime.c
@@ -237,6 +237,10 @@ rb_strftime_with_timespec(char *s, size_t maxsize, const char *format, const str
i = rb_strftime_with_timespec(s, endp - s, (fmt), vtm, timev, ts, gmt); \
if (!i) return 0; \
if (precision > i) {\
+ if (start + maxsize < s + precision) { \
+ errno = ERANGE; \
+ return 0; \
+ } \
memmove(s + precision - i, s, i);\
memset(s, padding ? padding : ' ', precision - i); \
s += precision; \
View
2  string.c
@@ -5164,7 +5164,7 @@ tr_trans(VALUE str, VALUE src, VALUE repl, int sflag)
else c = NUM2INT(tmp);
}
else {
- c = errc;
+ c = cflag ? last : errc;
}
if (c != errc) {
tlen = rb_enc_codelen(c, enc);
View
33 test/ruby/test_io.rb
@@ -1776,4 +1776,37 @@ def test_invalid_advise
end
end
end
+
+ def test_fcntl_lock
+ return if /x86_64-linux/ !~ RUBY_PLATFORM # A binary form of struct flock depend on platform
+
+ pad=0
+ Tempfile.open(self.class.name) do |f|
+ r, w = IO.pipe
+ pid = fork do
+ r.close
+ lock = [Fcntl::F_WRLCK, IO::SEEK_SET, pad, 12, 34, 0].pack("s!s!i!L!L!i!")
+ f.fcntl Fcntl::F_SETLKW, lock
+ w.syswrite "."
+ sleep
+ end
+ w.close
+ assert_equal ".", r.read(1)
+ r.close
+ pad = 0
+ getlock = [Fcntl::F_WRLCK, 0, pad, 0, 0, 0].pack("s!s!i!L!L!i!")
+ f.fcntl Fcntl::F_GETLK, getlock
+
+ ptype, whence, pad, start, len, lockpid = getlock.unpack("s!s!i!L!L!i!")
+
+ assert_equal(ptype, Fcntl::F_WRLCK)
+ assert_equal(whence, IO::SEEK_SET)
+ assert_equal(start, 12)
+ assert_equal(len, 34)
+ assert_equal(pid, lockpid)
+
+ Process.kill :TERM, pid
+ Process.waitpid2(pid)
+ end
+ end
end
View
1  test/ruby/test_m17n.rb
@@ -962,6 +962,7 @@ def test_tr
assert_equal("X\u3042\u3044X", "A\u3042\u3044\u3046".tr("^\u3042\u3044", "X"))
assert_equal("\u3042\u3046" * 100, ("\u3042\u3044" * 100).tr("\u3044", "\u3046"))
+ assert_equal("Y", "\u3042".tr("^X", "Y"))
end
def test_tr_s
View
18 test/ruby/test_process.rb
@@ -384,16 +384,20 @@ def test_execopts_redirect
Process.wait Process.spawn(*ECHO["c"], STDERR=>STDOUT, STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644])
assert_equal("c", File.read("out").chomp)
File.open("out", "w") {|f|
- Process.wait Process.spawn(*ECHO["d"], f=>STDOUT, STDOUT=>f)
+ Process.wait Process.spawn(*ECHO["d"], STDOUT=>f)
assert_equal("d", File.read("out").chomp)
}
- Process.wait Process.spawn(*ECHO["e"], STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644],
- 3=>STDOUT, 4=>STDOUT, 5=>STDOUT, 6=>STDOUT, 7=>STDOUT)
+ opts = {STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644]}
+ if /mswin|mingw/ !~ RUBY_PLATFORM
+ opts.merge(3=>STDOUT, 4=>STDOUT, 5=>STDOUT, 6=>STDOUT, 7=>STDOUT)
+ end
+ Process.wait Process.spawn(*ECHO["e"], opts)
assert_equal("e", File.read("out").chomp)
- Process.wait Process.spawn(*ECHO["ee"], STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644],
- 3=>0, 4=>:in, 5=>STDIN,
- 6=>1, 7=>:out, 8=>STDOUT,
- 9=>2, 10=>:err, 11=>STDERR)
+ opts = {STDOUT=>["out", File::WRONLY|File::CREAT|File::TRUNC, 0644]}
+ if /mswin|mingw/ !~ RUBY_PLATFORM
+ opts.merge(3=>0, 4=>:in, 5=>STDIN, 6=>1, 7=>:out, 8=>STDOUT, 9=>2, 10=>:err, 11=>STDERR)
+ end
+ Process.wait Process.spawn(*ECHO["ee"], opts)
assert_equal("ee", File.read("out").chomp)
if /mswin|mingw/ !~ RUBY_PLATFORM
# passing non-stdio fds is not supported on Windows
View
32 test/ruby/test_string.rb
@@ -1944,4 +1944,36 @@ def foo.to_str
assert_equal(S("hello world"), a)
assert_equal(S("hello "), b)
end
+
+ def u(str)
+ str.force_encoding(Encoding::UTF_8)
+ end
+
+ def test_byteslice
+ assert_equal("h", "hello".byteslice(0))
+ assert_equal(nil, "hello".byteslice(5))
+ assert_equal("o", "hello".byteslice(-1))
+ assert_equal(nil, "hello".byteslice(-6))
+
+ assert_equal("", "hello".byteslice(0, 0))
+ assert_equal("hello", "hello".byteslice(0, 6))
+ assert_equal("hello", "hello".byteslice(0, 6))
+ assert_equal("", "hello".byteslice(5, 1))
+ assert_equal("o", "hello".byteslice(-1, 6))
+ assert_equal(nil, "hello".byteslice(-6, 1))
+ assert_equal(nil, "hello".byteslice(0, -1))
+
+ assert_equal("h", "hello".byteslice(0..0))
+ assert_equal("", "hello".byteslice(5..0))
+ assert_equal("o", "hello".byteslice(4..5))
+ assert_equal(nil, "hello".byteslice(6..0))
+ assert_equal("", "hello".byteslice(-1..0))
+ assert_equal("llo", "hello".byteslice(-3..5))
+
+ assert_equal(u("\x81"), "\u3042".byteslice(1))
+ assert_equal(u("\x81\x82"), "\u3042".byteslice(1, 2))
+ assert_equal(u("\x81\x82"), "\u3042".byteslice(1..2))
+
+ assert_equal(u("\x82")+("\u3042"*9), ("\u3042"*10).byteslice(2, 28))
+ end
end
View
30 test/ruby/test_system.rb
@@ -91,24 +91,13 @@ def test_system
def test_system_at
if /mswin|mingw/ =~ RUBY_PLATFORM
bug4393 = '[ruby-core:35218]'
- bug4396 = '[ruby-core:35227]'
# @ + builtin command
assert_equal("foo\n", `@echo foo`, bug4393);
assert_equal("foo\n", `@@echo foo`, bug4393);
assert_equal("@@foo\n", `@@echo @@foo`, bug4393);
- # "" + @ + built-in
- assert_equal("@@foo\n", `"echo" @@foo`, bug4396);
- assert_equal("@@foo\n", `"@@echo" @@foo`, bug4396);
- assert_equal("@@foo\n", `"@@echo @@foo"`, bug4396);
- assert_equal('"@foo"\n', `"echo" "@foo"`, bug4396);
-
- # ^ + @ + built-in
- assert_equal(nil, system('^@echo foo'), bug4396);
- assert_equal(nil, system('"^@echo foo"'), bug4396);
- assert_equal("@foo\n", `echo ^@foo`);
-
+ # @ + non builtin command
Dir.mktmpdir("ruby_script_tmp") {|tmpdir|
tmpfilename = "#{tmpdir}/ruby_script_tmp.#{$$}"
@@ -116,16 +105,23 @@ def test_system_at
tmp.print "foo\nbar\nbaz\n@foo";
tmp.close
- # @ + non builtin command
assert_match(/\Abar\nbaz\n?\z/, `@@findstr "ba" #{tmpfilename.gsub("/", "\\")}`, bug4393);
-
- # "" + @ + non built-in
- assert_match(/\Abar\nbaz\n?\z/, `"@@findstr" "ba" #{tmpfilename.gsub("/", "\\")}`, bug4396);
- assert_match(/\A@foo\n?\z/, `"@@findstr" "@foo" #{tmpfilename.gsub("/", "\\")}`, bug4396);
}
end
end
+ def test_system_redirect_win
+ if /mswin|mingw/ !~ RUBY_PLATFORM
+ return
+ end
+
+ cmd = "%WINDIR%/system32/ping.exe \"BFI3CHL671\" > out.txt 2>NUL"
+ assert_equal(false, system(cmd), '[ruby-talk:258939]');
+
+ cmd = "\"%WINDIR%/system32/ping.exe BFI3CHL671\" > out.txt 2>NUL"
+ assert_equal(false, system(cmd), '[ruby-talk:258939]');
+ end
+
def test_empty_evstr
assert_equal("", eval('"#{}"', nil, __FILE__, __LINE__), "[ruby-dev:25113]")
end
View
422 test/rubygems/test_gem.rb
@@ -26,6 +26,352 @@ def setup
util_remove_interrupt_command
end
+ def assert_activate expected, *specs
+ specs.each do |spec|
+ case spec
+ when Array
+ Gem.activate(*spec)
+ when String
+ Gem.activate spec
+ else
+ Gem.activate spec.name
+ end
+ end
+
+ loaded = Gem.loaded_specs.values.map(&:full_name)
+
+ assert_equal expected.sort, loaded.sort if expected
+ end
+
+ def test_self_activate
+ foo = util_spec 'foo', '1'
+
+ assert_activate %w[foo-1], foo
+ end
+
+ def loaded_spec_names
+ Gem.loaded_specs.values.map(&:full_name).sort
+ end
+
+ def unresolved_names
+ Gem.unresolved_deps.values.map(&:to_s).sort
+ end
+
+ def test_self_activate_via_require
+ a1 = new_spec "a", "1", "b" => "= 1"
+ b1 = new_spec "b", "1", nil, "lib/b/c.rb"
+ b2 = new_spec "b", "2", nil, "lib/b/c.rb"
+
+ Gem.activate "a", "= 1"
+ require "b/c"
+
+ assert_equal %w(a-1 b-1), loaded_spec_names
+ end
+
+ def test_self_activate_deep_unambiguous
+ a1 = new_spec "a", "1", "b" => "= 1"
+ b1 = new_spec "b", "1", "c" => "= 1"
+ b2 = new_spec "b", "2", "c" => "= 2"
+ c1 = new_spec "c", "1"
+ c2 = new_spec "c", "2"
+
+ install_specs a1, b1, b2, c1, c2
+
+ Gem.activate "a", "= 1"
+ assert_equal %w(a-1 b-1 c-1), loaded_spec_names
+ end
+
+ def save_loaded_features
+ old_loaded_features = $LOADED_FEATURES.dup
+ yield
+ ensure
+ $LOADED_FEATURES.replace old_loaded_features
+ end
+
+ def test_self_activate_ambiguous_direct
+ save_loaded_features do
+ a1 = new_spec "a", "1", "b" => "> 0"
+ b1 = new_spec("b", "1", { "c" => ">= 1" }, "lib/d.rb")
+ b2 = new_spec("b", "2", { "c" => ">= 2" }, "lib/d.rb")
+ c1 = new_spec "c", "1"
+ c2 = new_spec "c", "2"
+
+ install_specs a1, b1, b2, c1, c2
+
+ Gem.activate "a", "= 1"
+ assert_equal %w(a-1), loaded_spec_names
+ assert_equal ["b (> 0)"], unresolved_names
+
+ require "d"
+
+ assert_equal %w(a-1 b-2 c-2), loaded_spec_names
+ assert_equal [], unresolved_names
+ end
+ end
+
+ def test_self_activate_ambiguous_indirect
+ save_loaded_features do
+ a1 = new_spec "a", "1", "b" => "> 0"
+ b1 = new_spec "b", "1", "c" => ">= 1"
+ b2 = new_spec "b", "2", "c" => ">= 2"
+ c1 = new_spec "c", "1", nil, "lib/d.rb"
+ c2 = new_spec "c", "2", nil, "lib/d.rb"
+
+ install_specs a1, b1, b2, c1, c2
+
+ Gem.activate "a", "= 1"
+ assert_equal %w(a-1), loaded_spec_names
+ assert_equal ["b (> 0)"], unresolved_names
+
+ require "d"
+
+ assert_equal %w(a-1 b-2 c-2), loaded_spec_names
+ assert_equal [], unresolved_names
+ end
+ end
+
+ def test_self_activate_ambiguous_unrelated
+ save_loaded_features do
+ a1 = new_spec "a", "1", "b" => "> 0"
+ b1 = new_spec "b", "1", "c" => ">= 1"
+ b2 = new_spec "b", "2", "c" => ">= 2"
+ c1 = new_spec "c", "1"
+ c2 = new_spec "c", "2"
+ d1 = new_spec "d", "1", nil, "lib/d.rb"
+
+ install_specs a1, b1, b2, c1, c2
+
+ Gem.activate "a", "= 1"
+ assert_equal %w(a-1), loaded_spec_names
+ assert_equal ["b (> 0)"], unresolved_names
+
+ require "d"
+
+ assert_equal %w(a-1 d-1), loaded_spec_names
+ assert_equal ["b (> 0)"], unresolved_names
+ end
+ end
+
+ def test_self_activate_ambiguous_indirect_conflict
+ save_loaded_features do
+ a1 = new_spec "a", "1", "b" => "> 0"
+ a2 = new_spec "a", "2", "b" => "> 0"
+ b1 = new_spec "b", "1", "c" => ">= 1"
+ b2 = new_spec "b", "2", "c" => ">= 2"
+ c1 = new_spec "c", "1", nil, "lib/d.rb"
+ c2 = new_spec("c", "2", { "a" => "1" }, "lib/d.rb") # conflicts with a-2
+
+ install_specs a1, b1, b2, c1, c2
+
+ Gem.activate "a", "= 2"
+ assert_equal %w(a-2), loaded_spec_names
+ assert_equal ["b (> 0)"], unresolved_names
+
+ require "d"
+
+ assert_equal %w(a-2 b-1 c-1), loaded_spec_names
+ assert_equal [], unresolved_names
+ end
+ end
+
+ def test_require_missing
+ save_loaded_features do
+ assert_raises ::LoadError do
+ require "q"
+ end
+ end
+ end
+
+ def test_self_activate_loaded
+ util_spec 'foo', '1'
+
+ assert Gem.activate 'foo'
+ refute Gem.activate 'foo'
+ end
+
+ ##
+ # [A] depends on
+ # [B] >= 1.0 (satisfied by 2.0)
+ # [C] depends on nothing
+
+ def test_self_activate_unrelated
+ a = util_spec 'a', '1.0', 'b' => '>= 1.0'
+ util_spec 'b', '1.0'
+ c = util_spec 'c', '1.0'
+
+ assert_activate %w[b-1.0 c-1.0 a-1.0], a, c, "b"
+ end
+
+ ##
+ # [A] depends on
+ # [B] >= 1.0 (satisfied by 2.0)
+ # [C] = 1.0 depends on
+ # [B] ~> 1.0
+ #
+ # and should resolve using b-1.0
+
+ def test_self_activate_over
+ a, _ = util_spec 'a', '1.0', 'b' => '>= 1.0', 'c' => '= 1.0'
+ util_spec 'b', '1.0'
+ util_spec 'b', '1.1'
+ util_spec 'b', '2.0'
+ c, _ = util_spec 'c', '1.0', 'b' => '~> 1.0'
+
+ Gem.activate "a"
+
+ assert_equal %w[a-1.0 c-1.0], loaded_spec_names
+ assert_equal ["b (>= 1.0, ~> 1.0)"], unresolved_names
+ end
+
+ ##
+ # [A] depends on
+ # [B] ~> 1.0 (satisfied by 1.1)
+ # [C] = 1.0 depends on
+ # [B] = 1.0
+ #
+ # and should resolve using b-1.0
+ #
+ # TODO: this is not under, but over... under would require depth
+ # first resolve through a dependency that is later pruned.
+
+ def test_self_activate_under
+ a, _ = util_spec 'a', '1.0', 'b' => '~> 1.0', 'c' => '= 1.0'
+ util_spec 'b', '1.0'
+ util_spec 'b', '1.1'
+ c, _ = util_spec 'c', '1.0', 'b' => '= 1.0'
+
+ assert_activate %w[b-1.0 c-1.0 a-1.0], a, c, "b"
+ end
+
+ ##
+ # [A1] depends on
+ # [B] > 0 (satisfied by 2.0)
+ # [B1] depends on
+ # [C] > 0 (satisfied by 1.0)
+ # [B2] depends on nothing!
+ # [C1] depends on nothing
+
+ def test_self_activate_dropped
+ a1, = util_spec 'a', '1', 'b' => nil
+ util_spec 'b', '1', 'c' => nil
+ util_spec 'b', '2'
+ util_spec 'c', '1'
+
+ assert_activate %w[b-2 a-1], a1, "b"
+ end
+
+ ##
+ # [A] depends on
+ # [B] >= 1.0 (satisfied by 1.1) depends on