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: 78953adfa6b1
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7c664151bc1a
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on May 18, 2015

  1. Copy the full SHA
    c1b5543 View commit details
  2. Copy the full SHA
    7c66415 View commit details
35 changes: 35 additions & 0 deletions lib/ruby/truffle/truffle/digest/bubblebabble.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright (c) 2015 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 'digest'

module Digest

def bubblebabble(message)
Truffle::Digest.bubblebabble(message)
end

class Base

def bubblebabble(message=NO_MESSAGE)
Digest.bubblebabble(digest(message))
end

end

module BaseFunctions

def hexdigest(message)
digest = new
digest.update message
digest.bubblebabble
end

end

end
29 changes: 29 additions & 0 deletions spec/ruby/library/digest/bubblebabble_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require File.expand_path('../../../spec_helper', __FILE__)
require 'digest/bubblebabble'

describe "Digest.bubblebabble" do
it "returns a String" do
Digest.bubblebabble('').should be_an_instance_of(String)
end

it "returns a String in the The Bubble Babble Binary Data Encoding format" do
Digest.bubblebabble('').should == 'xexax'
Digest.bubblebabble('foo').should == 'xinik-zorox'
Digest.bubblebabble('bar').should == 'ximik-cosex'
Digest.bubblebabble('1234567890').should == 'xesef-disof-gytuf-katof-movif-baxux'
end

it "calls #to_str on an object and returns the bubble babble value of the result" do
obj = mock("to_str")
obj.should_receive(:to_str).and_return('foo')
Digest.bubblebabble(obj).should == 'xinik-zorox'
end

it "raises a TypeError when passed nil" do
lambda { Digest.bubblebabble(nil) }.should raise_error(TypeError)
end

it "raises a TypeError when passed a Fixnum" do
lambda { Digest.bubblebabble(9001) }.should raise_error(TypeError)
end
end
16 changes: 16 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/nodes/ext/DigestNodes.java
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.object.*;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.ext.digest.BubbleBabble;
import org.jruby.truffle.nodes.core.CoreClass;
import org.jruby.truffle.nodes.core.CoreMethod;
import org.jruby.truffle.nodes.core.CoreMethodArrayArgumentsNode;
@@ -223,4 +224,19 @@ public int digestLength(RubyBasicObject digestObject) {

}

@CoreMethod(names = "bubblebabble", isModuleFunction = true, required = 1)
public abstract static class BubbleBabbleNode extends CoreMethodArrayArgumentsNode {

public BubbleBabbleNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@CompilerDirectives.TruffleBoundary
@Specialization
public RubyString bubblebabble(RubyString message) {
return getContext().makeString(BubbleBabble.bubblebabble(message.getByteList().bytes()));
}

}

}