Skip to content

Commit

Permalink
Showing 64 changed files with 492 additions and 362 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
@@ -334,7 +334,7 @@ public static RubyArray newArrayMayCopy(Ruby runtime, IRubyObject[] args, int st
return newArrayNoCopy(runtime, args, start, length);
}

public static RubyArray newArrayNoCopy(Ruby runtime, IRubyObject[] args) {
public static RubyArray newArrayNoCopy(Ruby runtime, IRubyObject... args) {
return new RubyArray(runtime, args);
}

6 changes: 6 additions & 0 deletions core/src/main/java/org/jruby/RubyFixnum.java
Original file line number Diff line number Diff line change
@@ -1378,11 +1378,17 @@ public IRubyObject denominator(ThreadContext context) {
return one(context.runtime);
}

@Override
public RubyRational convertToRational() {
final Ruby runtime = getRuntime();
return RubyRational.newRationalRaw(runtime, this, one(runtime));
}

@Override
public IRubyObject remainder(ThreadContext context, IRubyObject y) {
return numRemainder(context, y);
}

private static JavaSites.FixnumSites sites(ThreadContext context) {
return context.sites.Fixnum;
}
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/RubyInteger.java
Original file line number Diff line number Diff line change
@@ -797,6 +797,7 @@ public IRubyObject op_ge(ThreadContext context, IRubyObject other) {
public IRubyObject op_le(ThreadContext context, IRubyObject other) {
return RubyComparable.op_le(context, this, other);
}

@JRubyMethod(name = "remainder")
public IRubyObject remainder(ThreadContext context, IRubyObject dividend) {
return context.nil;
23 changes: 10 additions & 13 deletions core/src/main/java/org/jruby/RubyNumeric.java
Original file line number Diff line number Diff line change
@@ -137,31 +137,24 @@ public static RoundingMode getRoundingMode(ThreadContext context, IRubyObject op
throw context.runtime.newArgumentError("invalid rounding mode: " + halfArg);
}

// The implementations of these are all bonus (see TODO above) I was going
// to throw an error from these, but it appears to be the wrong place to
// do it.
public double getDoubleValue() {
return 0;
}
// The implementations of these are all bonus (see above)

/**
* Return the value of this numeric as a 64-bit long. If the value does not
* fit in 64 bits, it will be truncated.
*/
public long getLongValue() {
return 0;
}
public long getLongValue() { return 0; }

/**
* Return the value of this numeric as a 32-bit long. If the value does not
* fit in 32 bits, it will be truncated.
*/
public int getIntValue() {
return 0;
}
public int getIntValue() { return (int) getLongValue(); }

public double getDoubleValue() { return getLongValue(); }

public BigInteger getBigIntegerValue() {
return BigInteger.ZERO;
return BigInteger.valueOf(getLongValue());
}

public static RubyNumeric newNumeric(Ruby runtime) {
@@ -808,6 +801,10 @@ public IRubyObject modulo(ThreadContext context, IRubyObject other) {
*/
@JRubyMethod(name = "remainder")
public IRubyObject remainder(ThreadContext context, IRubyObject y) {
return numRemainder(context, y);
}

public IRubyObject numRemainder(ThreadContext context, IRubyObject y) {
RubyNumeric x = this;
JavaSites.NumericSites sites = sites(context);
IRubyObject z = sites.op_mod.call(context, this, this, y);
52 changes: 16 additions & 36 deletions core/src/main/java/org/jruby/RubyRational.java
Original file line number Diff line number Diff line change
@@ -25,39 +25,8 @@
***** END LICENSE BLOCK *****/
package org.jruby;

import static org.jruby.util.Numeric.f_abs;
import static org.jruby.util.Numeric.f_add;
import static org.jruby.util.Numeric.f_cmp;
import static org.jruby.util.Numeric.f_div;
import static org.jruby.util.Numeric.f_equal;
import static org.jruby.util.Numeric.f_expt;
import static org.jruby.util.Numeric.f_floor;
import static org.jruby.util.Numeric.f_gcd;
import static org.jruby.util.Numeric.f_idiv;
import static org.jruby.util.Numeric.f_integer_p;
import static org.jruby.util.Numeric.f_minus_one_p;
import static org.jruby.util.Numeric.f_mul;
import static org.jruby.util.Numeric.f_negate;
import static org.jruby.util.Numeric.f_negative_p;
import static org.jruby.util.Numeric.f_odd_p;
import static org.jruby.util.Numeric.f_one_p;
import static org.jruby.util.Numeric.f_rshift;
import static org.jruby.util.Numeric.f_sub;
import static org.jruby.util.Numeric.f_to_f;
import static org.jruby.util.Numeric.f_to_i;
import static org.jruby.util.Numeric.f_to_r;
import static org.jruby.util.Numeric.f_truncate;
import static org.jruby.util.Numeric.f_xor;
import static org.jruby.util.Numeric.f_zero_p;
import static org.jruby.util.Numeric.i_gcd;
import static org.jruby.util.Numeric.i_ilog2;
import static org.jruby.util.Numeric.k_exact_p;
import static org.jruby.util.Numeric.k_integer_p;
import static org.jruby.util.Numeric.k_numeric_p;
import static org.jruby.util.Numeric.ldexp;
import static org.jruby.util.Numeric.nurat_rationalize_internal;

import java.io.IOException;
import java.math.BigInteger;
import java.math.RoundingMode;

import org.jcodings.specific.ASCIIEncoding;
@@ -83,6 +52,7 @@

import static org.jruby.runtime.Helpers.invokedynamic;
import static org.jruby.runtime.invokedynamic.MethodNames.HASH;
import static org.jruby.util.Numeric.*;

/**
* rational.c (as of revision: 20011)
@@ -375,7 +345,7 @@ public static IRubyObject convert(ThreadContext context, IRubyObject recv, IRuby
return convertCommon(context, (RubyClass) recv, a1, a2);
}

private static IRubyObject convertCommon(ThreadContext context, RubyClass clazz, IRubyObject a1, IRubyObject a2) {
private static RubyNumeric convertCommon(ThreadContext context, RubyClass clazz, IRubyObject a1, IRubyObject a2) {
if (a1 instanceof RubyComplex) {
RubyComplex a1c = (RubyComplex) a1;
if (k_exact_p(a1c.getImage()) && f_zero_p(context, a1c.getImage())) a1 = a1c.getReal();
@@ -406,18 +376,18 @@ private static IRubyObject convertCommon(ThreadContext context, RubyClass clazz,
}

if (a1 instanceof RubyRational) {
if (a2 == context.nil || (k_exact_p(a2) && f_one_p(context, a2))) return a1;
if (a2 == context.nil || (k_exact_p(a2) && f_one_p(context, a2))) return (RubyRational) a1;
}

if (a2 == context.nil) {
if (!(a1 instanceof RubyNumeric && f_integer_p(context, (RubyNumeric) a1))) {
return TypeConverter.convertToType(context, a1, context.runtime.getRational(), sites(context).to_r_checked);
return (RubyRational) TypeConverter.convertToType(context, a1, context.runtime.getRational(), sites(context).to_r_checked);
}
return newInstance(context, clazz, a1);
} else {
if ((a1 instanceof RubyNumeric && a2 instanceof RubyNumeric) &&
(!f_integer_p(context, (RubyNumeric) a1) || !f_integer_p(context, (RubyNumeric) a2))) {
return f_div(context, a1, a2);
return (RubyNumeric) f_div(context, a1, a2);
}
return newInstance(context, clazz, a1, a2);
}
@@ -947,6 +917,16 @@ public IRubyObject to_i(ThreadContext context) {
return mriTruncate(context); // truncate(context);
}

@Override
public long getLongValue() {
return convertToInteger().getLongValue();
}

@Override
public BigInteger getBigIntegerValue() {
return convertToInteger().getBigIntegerValue();
}

/**
* MRI: nurat_truncate
*/
2 changes: 1 addition & 1 deletion spec/mspec/.travis.yml
Original file line number Diff line number Diff line change
@@ -20,6 +20,6 @@ matrix:
- gem update --system
- jdk: oraclejdk8
install:
- curl -L https://github.com/graalvm/truffleruby/releases/download/vm-enterprise-0.28/truffleruby-testing-0.28.tar.gz | tar xz
- curl -L https://github.com/oracle/truffleruby/releases/download/vm-enterprise-0.28/truffleruby-testing-0.28.tar.gz | tar xz
- source truffleruby/setup_env
- bundle install
18 changes: 18 additions & 0 deletions spec/mspec/tool/pull-latest-mspec-spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# Assumes all commits have been synchronized to https://github.com/ruby/spec
# See spec/mspec/tool/sync/sync-rubyspec.rb

rm -rf spec/mspec
git clone --depth 1 https://github.com/ruby/mspec.git spec/mspec
commit=$(git -C spec/mspec log -n 1 --format='%h')
rm -rf spec/mspec/.git
git add spec/mspec
git commit -m "Update to ruby/mspec@${commit}"

rm -rf spec/ruby
git clone --depth 1 https://github.com/ruby/spec.git spec/ruby
commit=$(git -C spec/ruby log -n 1 --format='%h')
rm -rf spec/ruby/.git
git add spec/ruby
git commit -m "Update to ruby/spec@${commit}"
13 changes: 1 addition & 12 deletions spec/mspec/tool/sync/sync-rubyspec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
IMPLS = {
truffleruby: {
git: "https://github.com/graalvm/truffleruby.git",
git: "https://github.com/oracle/truffleruby.git",
from_commit: "f10ab6988d",
},
jruby: {
@@ -182,17 +182,6 @@ def test_new_specs
def verify_commits(impl)
puts
Dir.chdir(SOURCE_REPO) do
history = `git log master...`
history.lines.slice_before(/^commit \h{40}$/).each do |commit, *message|
commit = commit.chomp.split.last
message = message.join
if /\W(#\d+)/ === message
puts "Commit #{commit} contains an unqualified issue number: #{$1}"
puts "Replace it with #{impl.repo_org}/#{impl.repo_name}#{$1}"
sh "git", "rebase", "-i", "#{commit}^"
end
end

puts "Manually check commit messages:"
print "Press enter >"
STDIN.gets
2 changes: 2 additions & 0 deletions spec/ruby/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -158,6 +158,8 @@ guard -> { max_uint <= fixnum_max } do
end
```

Custom guards are better than a simple `if` as they allow [mspec commands](https://github.com/ruby/mspec/issues/30#issuecomment-312487779) to work properly.

In general, the usage of guards should be minimized as possible.

There are no guards to define implementation-specific behavior because
6 changes: 3 additions & 3 deletions spec/ruby/README.md
Original file line number Diff line number Diff line change
@@ -24,9 +24,9 @@ The language specs are grouped by keyword while the core and standard library sp

ruby/spec is known to be tested in these implementations for every commit:
* [MRI](http://rubyci.org/) on 30 platforms and 4 versions
* [JRuby](https://github.com/jruby/jruby/tree/master/spec/ruby) on Travis for both 1.7 and 9.x
* [TruffleRuby](https://github.com/graalvm/truffleruby) on Travis
* [Opal](https://github.com/opal/opal/tree/master/spec) on Travis
* [JRuby](https://github.com/jruby/jruby/tree/master/spec/ruby) for both 1.7 and 9.x
* [TruffleRuby](https://github.com/oracle/truffleruby)
* [Opal](https://github.com/opal/opal/tree/master/spec)

ruby/spec describes the behavior of Ruby 2.2 and more recent Ruby versions.
More precisely, every latest stable MRI release [passes](https://rubyci.org/) all specs of ruby/spec
25 changes: 25 additions & 0 deletions spec/ruby/command_line/dash_upper_e_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
describe "ruby -E" do
it "sets the external encoding with '-E external'" do
result = ruby_exe("print Encoding.default_external", options: '-E euc-jp')
result.should == "EUC-JP"
end

it "also sets the filesystem encoding with '-E external'" do
result = ruby_exe("print Encoding.find('filesystem')", options: '-E euc-jp')
result.should == "EUC-JP"
end

it "sets the external encoding with '-E external:'" do
result = ruby_exe("print Encoding.default_external", options: '-E Shift_JIS:')
result.should == "Shift_JIS"
end

it "sets the internal encoding with '-E :internal'" do
ruby_exe("print Encoding.default_internal", options: '-E :SHIFT_JIS').
should == 'Shift_JIS'
end

it "sets the external and internal encodings with '-E external:internal'" do
ruby_exe("puts Encoding.default_external, Encoding.default_internal", options: '-E euc-jp:SHIFT_JIS').
should == "EUC-JP\nShift_JIS\n"
end

it "raises a RuntimeError if used with -U" do
ruby_exe("p 1",
options: '-Eascii:ascii -U',
3 changes: 1 addition & 2 deletions spec/ruby/core/array/clear_spec.rb
Original file line number Diff line number Diff line change
@@ -10,8 +10,7 @@

it "returns self" do
a = [1]
oid = a.object_id
a.clear.object_id.should == oid
a.should equal a.clear
end

it "leaves the Array empty" do
2 changes: 1 addition & 1 deletion spec/ruby/core/array/compact_spec.rb
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@

it "returns self if some nil elements are removed" do
a = ['a', nil, 'b', false, 'c']
a.compact!.object_id.should == a.object_id
a.compact!.should equal a
end

it "returns nil if there are no nil elements to remove" do
16 changes: 16 additions & 0 deletions spec/ruby/core/array/filter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../shared/select', __FILE__)

ruby_version_is "2.6" do
describe "Array#filter" do
it_behaves_like :array_select, :filter
end

describe "Array#filter!" do
it "returns nil if no changes were made in the array" do
[1, 2, 3].filter! { true }.should be_nil
end

it_behaves_like :keep_if, :filter!
end
end
4 changes: 2 additions & 2 deletions spec/ruby/core/array/reject_spec.rb
Original file line number Diff line number Diff line change
@@ -9,9 +9,9 @@
ary = [1, 2, 3, 4, 5]
ary.reject { true }.should == []
ary.reject { false }.should == ary
ary.reject { false }.object_id.should_not == ary.object_id
ary.reject { false }.should_not equal ary
ary.reject { nil }.should == ary
ary.reject { nil }.object_id.should_not == ary.object_id
ary.reject { nil }.should_not equal ary
ary.reject { 5 }.should == []
ary.reject { |i| i < 3 }.should == [3, 4, 5]
ary.reject { |i| i % 2 == 0 }.should == [1, 3, 5]
26 changes: 2 additions & 24 deletions spec/ruby/core/array/select_spec.rb
Original file line number Diff line number Diff line change
@@ -1,30 +1,8 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
require File.expand_path('../shared/enumeratorize', __FILE__)
require File.expand_path('../shared/keep_if', __FILE__)
require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
require File.expand_path('../shared/select', __FILE__)

describe "Array#select" do
it_behaves_like :enumeratorize, :select
it_behaves_like :enumeratorized_with_origin_size, :select, [1,2,3]

it "returns a new array of elements for which block is true" do
[1, 3, 4, 5, 6, 9].select { |i| i % ((i + 1) / 2) == 0}.should == [1, 4, 6]
end

it "does not return subclass instance on Array subclasses" do
ArraySpecs::MyArray[1, 2, 3].select { true }.should be_an_instance_of(Array)
end

it "properly handles recursive arrays" do
empty = ArraySpecs.empty_recursive_array
empty.select { true }.should == empty
empty.select { false }.should == []

array = ArraySpecs.recursive_array
array.select { true }.should == [1, 'two', 3.0, array, array, array, array, array]
array.select { false }.should == []
end
it_behaves_like :array_select, :select
end

describe "Array#select!" do
4 changes: 2 additions & 2 deletions spec/ruby/core/array/shared/clone.rb
Original file line number Diff line number Diff line change
@@ -7,8 +7,8 @@
it "produces a shallow copy where the references are directly copied" do
a = [mock('1'), mock('2')]
b = a.send @method
b.first.object_id.should == a.first.object_id
b.last.object_id.should == a.last.object_id
b.first.should equal a.first
b.last.should equal a.last
end

it "creates a new array containing all elements or the original" do
4 changes: 2 additions & 2 deletions spec/ruby/core/array/shared/collect.rb
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
a = ['a', 'b', 'c', 'd']
b = a.send(@method) { |i| i + '!' }
b.should == ["a!", "b!", "c!", "d!"]
b.object_id.should_not == a.object_id
b.should_not equal a
end

it "does not return subclass instance" do
@@ -70,7 +70,7 @@
it "returns self" do
a = [1, 2, 3, 4, 5]
b = a.send(@method) {|i| i+1 }
a.object_id.should == b.object_id
a.should equal b
end

it "returns the evaluated value of block but its contents is partially modified, if it broke in the block" do
Loading

0 comments on commit 7cef66a

Please sign in to comment.