Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: d7ac8f58e450
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cb159358580b
Choose a head ref
  • 2 commits
  • 18 files changed
  • 1 contributor

Commits on May 11, 2016

  1. [Truffle] Formatting.

    chrisseaton committed May 11, 2016
    Copy the full SHA
    c337fe2 View commit details
  2. 1
    Copy the full SHA
    cb15935 View commit details
25 changes: 25 additions & 0 deletions spec/truffle/specs/truffle/interop/boxed_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
# code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
#
# Eclipse Public License version 1.0
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

require_relative '../../../../ruby/spec_helper'

describe "Truffle::Interop.boxed?" do

it "returns false for empty strings" do
Truffle::Interop.boxed?('').should be_false
end

it "returns true for strings with one byte" do
Truffle::Interop.boxed?('1').should be_true
end

it "returns false for strings with two bytes" do
Truffle::Interop.boxed?('12').should be_false
end

end
36 changes: 36 additions & 0 deletions spec/truffle/specs/truffle/interop/executable_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
# code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
#
# Eclipse Public License version 1.0
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

require_relative '../../../../ruby/spec_helper'

describe "Truffle::Interop.executable?" do

def test_method
end

it "returns true for methods" do
Truffle::Interop.executable?(method(:test_method)).should be_true
end

it "returns true for procs" do
Truffle::Interop.executable?(proc { }).should be_true
end

it "returns true for lambdas" do
Truffle::Interop.executable?(lambda { }).should be_true
end

it "returns false for nil" do
Truffle::Interop.executable?(nil).should be_false
end

it "returns false for strings" do
Truffle::Interop.executable?('hello').should be_false
end

end
37 changes: 37 additions & 0 deletions spec/truffle/specs/truffle/interop/execute_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
# code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
#
# Eclipse Public License version 1.0
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

require_relative '../../../../ruby/spec_helper'

describe "Truffle::Interop.execute" do

def add(a, b)
a + b
end

it "calls methods" do
Truffle::Interop.execute(method(:add), 14, 2).should == 16
end

it "calls procs" do
Truffle::Interop.execute(proc { |a, b| a + b }, 14, 2).should == 16
end

it "calls lambdas" do
Truffle::Interop.execute(lambda { |a, b| a + b }, 14, 2).should == 16
end

it "doesn't call nil" do
lambda { Truffle::Interop.execute(nil) }.should raise_error(RubyTruffleError)
end

it "doesn't call strings" do
lambda { Truffle::Interop.execute('hello') }.should raise_error(RubyTruffleError)
end

end
29 changes: 29 additions & 0 deletions spec/truffle/specs/truffle/interop/invoke_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
# code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
#
# Eclipse Public License version 1.0
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

require_relative '../../../../ruby/spec_helper'

describe "Truffle::Interop.invoke" do

class InvokeTestClass

def add(a, b)
a + b
end

end

it "invokes methods using symbols" do
Truffle::Interop.invoke(InvokeTestClass.new, :add, 14, 2).should == 16
end

it "invokes methods using strings" do
Truffle::Interop.invoke(InvokeTestClass.new, 'add', 14, 2).should == 16
end

end
29 changes: 29 additions & 0 deletions spec/truffle/specs/truffle/interop/null_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
# code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
#
# Eclipse Public License version 1.0
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

require_relative '../../../../ruby/spec_helper'

describe "Truffle::Interop.null?" do

it "returns true for nil" do
Truffle::Interop.null?(nil).should be_true
end

it "returns false for strings" do
Truffle::Interop.null?('').should be_false
end

it "returns false for zero" do
Truffle::Interop.null?(0).should be_false
end

it "returns false for false" do
Truffle::Interop.null?(false).should be_false
end

end
79 changes: 79 additions & 0 deletions spec/truffle/specs/truffle/interop/read_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
# code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
#
# Eclipse Public License version 1.0
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

require_relative '../../../../ruby/spec_helper'

describe "Truffle::Interop.read" do

class ReadInstanceVariable

def initialize
@foo = 14
end

end

class HasMethod

def foo
14
end

end

class HasIndex

def [](n)
14
end

end

it "reads a byte from a string" do
Truffle::Interop.read('123', 1).should == '2'.ord
end

describe "reads an instance variable if given an @name" do
it "as a symbol" do
Truffle::Interop.read(ReadInstanceVariable.new, :@foo).should == 14
end

it "as a string" do
Truffle::Interop.read(ReadInstanceVariable.new, '@foo').should == 14
end
end

describe "calls #[] if there isn't a method with the same name" do
it "as a symbol" do
Truffle::Interop.read(HasIndex.new, :foo).should == 14
end

it "as a string" do
Truffle::Interop.read(HasIndex.new, 'foo').should == 14
end
end

describe "calls a method if there is a method with the same name" do
it "as a symbol" do
Truffle::Interop.read(HasMethod.new, :foo).should == 14
end

it "as a string" do
Truffle::Interop.read(HasMethod.new, 'foo').should == 14
end
end

it "can be used to index an array" do
Truffle::Interop.read([1, 2, 3], 1).should == 2
end

it "can be used to index a hash" do
Truffle::Interop.read({1 => 2, 3 => 4, 5 => 6}, 3).should == 4
end

end
37 changes: 37 additions & 0 deletions spec/truffle/specs/truffle/interop/size_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
# code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
#
# Eclipse Public License version 1.0
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

require_relative '../../../../ruby/spec_helper'

describe "Truffle::Interop.size" do

class InteropSizeClass

def size
14
end

end

it "returns the size of an array" do
Truffle::Interop.size([1, 2, 3]).should == 3
end

it "returns the size of an array" do
Truffle::Interop.size({a: 1, b: 2, c: 3}).should == 3
end

it "returns the size of an string" do
Truffle::Interop.size('123').should == 3
end

it "returns the size of any object with a size method" do
Truffle::Interop.size(InteropSizeClass.new).should == 14
end

end
29 changes: 29 additions & 0 deletions spec/truffle/specs/truffle/interop/sizep_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
# code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
#
# Eclipse Public License version 1.0
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

require_relative '../../../../ruby/spec_helper'

describe "Truffle::Interop.size?" do

it "returns true for arrays" do
Truffle::Interop.size?([]).should be_true
end

it "returns true for hashes" do
Truffle::Interop.size?({}).should be_true
end

it "returns true for strings" do
Truffle::Interop.size?('').should be_true
end

it "returns false for nil" do
Truffle::Interop.size?(nil).should be_false
end

end
29 changes: 29 additions & 0 deletions spec/truffle/specs/truffle/interop/unbox_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
# code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
#
# Eclipse Public License version 1.0
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

require_relative '../../../../ruby/spec_helper'

describe "Truffle::Interop.unbox" do

it "doesn't work on empty strings" do
lambda { Truffle::Interop.unbox('') }.should raise_error(RubyTruffleError)
end

it "returns the first byte on strings with one byte" do
Truffle::Interop.unbox('1').should == '1'.ord
end

it "returns the first byte on strings with two bytes" do
Truffle::Interop.unbox('1').should == '1'.ord
end

it "returns nil for nil" do
Truffle::Interop.unbox(nil).should be_nil
end

end
Loading