forked from MacRuby/MacRuby
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update rubyspec to 79484fbb65f9d1d225825aab85507b2ae0832caa
- Loading branch information
1 parent
7148357
commit ab260e8
Showing
136 changed files
with
3,077 additions
and
1,231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# -*- encoding: ascii-8bit -*- | ||
require File.expand_path('../../../../spec_helper', __FILE__) | ||
|
||
with_feature :encoding do | ||
describe "Encoding::Converter.new" do | ||
it "accepts a String for the source encoding" do | ||
conv = Encoding::Converter.new("us-ascii", "utf-8") | ||
conv.source_encoding.should == Encoding::US_ASCII | ||
end | ||
|
||
it "accepts a String for the destination encoding" do | ||
conv = Encoding::Converter.new("us-ascii", "utf-8") | ||
conv.destination_encoding.should == Encoding::UTF_8 | ||
end | ||
|
||
it "accepts an Encoding object for the source encoding" do | ||
conv = Encoding::Converter.new(Encoding::US_ASCII, "utf-8") | ||
conv.source_encoding.should == Encoding::US_ASCII | ||
end | ||
|
||
it "accepts an Encoding object for the destination encoding" do | ||
conv = Encoding::Converter.new("us-ascii", Encoding::UTF_8) | ||
conv.destination_encoding.should == Encoding::UTF_8 | ||
end | ||
|
||
it "calls #to_str to convert the source encoding argument to an encoding name" do | ||
enc = mock("us-ascii") | ||
enc.should_receive(:to_str).and_return("us-ascii") | ||
conv = Encoding::Converter.new(enc, "utf-8") | ||
conv.source_encoding.should == Encoding::US_ASCII | ||
end | ||
|
||
it "calls #to_str to convert the destination encoding argument to an encoding name" do | ||
enc = mock("utf-8") | ||
enc.should_receive(:to_str).and_return("utf-8") | ||
conv = Encoding::Converter.new("us-ascii", enc) | ||
conv.destination_encoding.should == Encoding::UTF_8 | ||
end | ||
|
||
it "sets replacement from the options Hash" do | ||
conv = Encoding::Converter.new("us-ascii", "utf-8", :replace => "fubar") | ||
conv.replacement.should == "fubar" | ||
end | ||
|
||
it "calls #to_hash to convert the options argument to a Hash if not a Fixnum" do | ||
opts = mock("encoding converter options") | ||
opts.should_receive(:to_hash).and_return({ :replace => "fubar" }) | ||
conv = Encoding::Converter.new("us-ascii", "utf-8", opts) | ||
conv.replacement.should == "fubar" | ||
end | ||
|
||
it "calls #to_str to convert the replacement object to a String" do | ||
obj = mock("encoding converter replacement") | ||
obj.should_receive(:to_str).and_return("fubar") | ||
conv = Encoding::Converter.new("us-ascii", "utf-8", :replace => obj) | ||
conv.replacement.should == "fubar" | ||
end | ||
|
||
it "raises a TypeError if #to_str does not return a String" do | ||
obj = mock("encoding converter replacement") | ||
obj.should_receive(:to_str).and_return(1) | ||
|
||
lambda do | ||
Encoding::Converter.new("us-ascii", "utf-8", :replace => obj) | ||
end.should raise_error(TypeError) | ||
end | ||
|
||
it "raises a TypeError if passed true for the replacement object" do | ||
lambda do | ||
Encoding::Converter.new("us-ascii", "utf-8", :replace => true) | ||
end.should raise_error(TypeError) | ||
end | ||
|
||
it "raises a TypeError if passed false for the replacement object" do | ||
lambda do | ||
Encoding::Converter.new("us-ascii", "utf-8", :replace => false) | ||
end.should raise_error(TypeError) | ||
end | ||
|
||
it "raises a TypeError if passed a Fixnum for the replacement object" do | ||
lambda do | ||
Encoding::Converter.new("us-ascii", "utf-8", :replace => 1) | ||
end.should raise_error(TypeError) | ||
end | ||
|
||
it "accepts an empty String for the replacement object" do | ||
conv = Encoding::Converter.new("us-ascii", "utf-8", :replace => "") | ||
conv.replacement.should == "" | ||
end | ||
|
||
describe "when passed nil for the replacement object" do | ||
describe "when the destination encoding is not UTF-8" do | ||
it "sets the replacement String to '?'" do | ||
conv = Encoding::Converter.new("us-ascii", "ascii-8bit", :replace => nil) | ||
conv.replacement.should == "?" | ||
end | ||
|
||
it "sets the replacement String encoding to US-ASCII" do | ||
conv = Encoding::Converter.new("us-ascii", "ascii-8bit", :replace => nil) | ||
conv.replacement.encoding.should == Encoding::US_ASCII | ||
end | ||
|
||
it "sets the replacement String to '\\uFFFD'" do | ||
conv = Encoding::Converter.new("us-ascii", "utf-8", :replace => nil) | ||
conv.replacement.should == "\u{fffd}".force_encoding("utf-8") | ||
end | ||
|
||
it "sets the replacement String encoding to UTF-8" do | ||
conv = Encoding::Converter.new("us-ascii", "utf-8", :replace => nil) | ||
conv.replacement.encoding.should == Encoding::UTF_8 | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require File.expand_path('../../../spec_helper', __FILE__) | ||
|
||
ruby_version_is "1.9" do | ||
describe "ENV.assoc" do | ||
after(:each) do | ||
ENV.delete("foo") | ||
end | ||
|
||
it "returns an array of the key and value of the environment variable with the given key" do | ||
ENV["foo"] = "bar" | ||
ENV.assoc("foo").should == ["foo", "bar"] | ||
end | ||
|
||
it "returns nil if no environment variable with the given key exists" do | ||
ENV.assoc("foo").should == nil | ||
end | ||
|
||
it "returns the key element coerced with #to_str" do | ||
ENV["foo"] = "bar" | ||
k = mock('key') | ||
k.should_receive(:to_str).and_return("foo") | ||
ENV.assoc(k).should == ["foo", "bar"] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
require File.expand_path('../../../spec_helper', __FILE__) | ||
|
||
describe "ENV.delete" do | ||
it "removes the variable and return its value" do | ||
after(:each) do | ||
ENV.delete("foo") | ||
end | ||
|
||
it "removes the variable from the environment" do | ||
ENV["foo"] = "bar" | ||
ENV.delete("foo").should == "bar" | ||
ENV.delete("foo") | ||
ENV["foo"].should == nil | ||
end | ||
|
||
it "returns the previous value" do | ||
ENV["foo"] = "bar" | ||
ENV.delete("foo").should == "bar" | ||
end | ||
|
||
it "yields the name to the given block if the named environment variable does not exist" do | ||
ENV.delete("foo") { |name| ScratchPad.record name } | ||
ScratchPad.recorded.should == "foo" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require File.expand_path('../../../spec_helper', __FILE__) | ||
|
||
ruby_version_is "1.9" do | ||
describe "ENV.keep_if" do | ||
it "deletes pairs if the block returns false" do | ||
ENV["foo"] = "bar" | ||
ENV.keep_if { |k, v| k != "foo" } | ||
ENV["foo"].should == nil | ||
end | ||
|
||
it "returns ENV even if nothing deleted" do | ||
ENV.keep_if { true }.should_not == nil | ||
end | ||
|
||
it "returns an Enumerator if no block given" do | ||
ENV.keep_if.should be_an_instance_of(enumerator_class) | ||
end | ||
|
||
it "deletes pairs through enumerator" do | ||
ENV["foo"] = "bar" | ||
enum = ENV.keep_if | ||
enum.each { |k, v| k != "foo" } | ||
ENV["foo"].should == nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require File.expand_path('../../../spec_helper', __FILE__) | ||
|
||
ruby_version_is "1.9" do | ||
describe "ENV.rassoc" do | ||
after(:each) do | ||
ENV.delete("foo") | ||
end | ||
|
||
it "returns an array of the key and value of the environment variable with the given value" do | ||
ENV["foo"] = "bar" | ||
ENV.rassoc("bar").should == ["foo", "bar"] | ||
end | ||
|
||
it "returns nil if no environment variable with the given value exists" do | ||
ENV.rassoc("bar").should == nil | ||
end | ||
|
||
it "returns the value element coerced with #to_str" do | ||
ENV["foo"] = "bar" | ||
v = mock('value') | ||
v.should_receive(:to_str).and_return("bar") | ||
ENV.rassoc(v).should == ["foo", "bar"] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,70 @@ | ||
describe :env_store, :shared => true do | ||
after(:each) do | ||
ENV.delete("foo") | ||
end | ||
|
||
it "sets the environment variable to the given value" do | ||
ENV.send(@method, "foo", "bar") | ||
env.key?("foo").should be_true | ||
env.value?("bar").should be_true | ||
ENV.delete "foo" | ||
ENV["foo"].should be_nil | ||
ENV.store "foo", "bar" | ||
env.key?("foo").should be_true | ||
env.value?("bar").should be_true | ||
ENV.delete "foo" | ||
ENV["foo"].should == "bar" | ||
end | ||
|
||
it "returns the value" do | ||
value = "bar" | ||
ENV.send(@method, "foo", value).should equal(value) | ||
end | ||
|
||
it "deletes the environment variable when the value is nil" do | ||
ENV["foo"] = "bar" | ||
ENV.send(@method, "foo", nil) | ||
ENV.key?("foo").should be_false | ||
end | ||
|
||
it "coerces the key argument with #to_str" do | ||
k = mock("key") | ||
k.should_receive(:to_str).and_return("foo") | ||
ENV.send(@method, k, "bar") | ||
ENV["foo"].should == "bar" | ||
end | ||
|
||
it "coerces the value argument with #to_str" do | ||
v = mock("value") | ||
v.should_receive(:to_str).and_return("bar") | ||
ENV.send(@method, "foo", v) | ||
ENV["foo"].should == "bar" | ||
end | ||
|
||
it "deletes key if value is nil" do | ||
ENV.send(@method, 'foo', 'bar') | ||
ENV.has_key?('foo').should be_true | ||
ENV.send(@method, 'foo', nil) | ||
ENV.has_key?('foo').should be_false | ||
it "raises TypeError when the key is not coercible to String" do | ||
lambda { ENV.send(@method, Object.new, "bar") }.should raise_error(TypeError) | ||
end | ||
|
||
it "raises TypeError when the value is not coercible to String" do | ||
lambda { ENV.send(@method, "foo", Object.new) }.should raise_error(TypeError) | ||
end | ||
|
||
ruby_version_is ""..."1.9" do | ||
it "fails silently when the key contains the '=' character" do | ||
ENV.send(@method, "foo=", "bar") | ||
ENV.key?("foo=").should be_false | ||
end | ||
|
||
it "fails silently when the key is an empty string" do | ||
ENV.send(@method, "", "bar") | ||
ENV.key?("").should be_false | ||
end | ||
end | ||
|
||
ruby_version_is "1.9" do | ||
it "raises Errno::EINVAL when the key contains the '=' character" do | ||
lambda { ENV.send(@method, "foo=", "bar") }.should raise_error(Errno::EINVAL) | ||
end | ||
|
||
it "raises Errno::EINVAL when the key is an empty string" do | ||
lambda { ENV.send(@method, "", "bar") }.should raise_error(Errno::EINVAL) | ||
end | ||
end | ||
|
||
it "does nothing when the key is not a valid environment variable key and the value is nil" do | ||
ENV.send(@method, "foo=", nil) | ||
ENV.key?("foo=").should be_false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
describe :env_to_hash, :shared => true do | ||
it "returns the ENV as a hash" do | ||
ENV["foo"] = "bar" | ||
h = ENV.send(@method) | ||
h.should be_an_instance_of(Hash) | ||
h["foo"].should == "bar" | ||
ENV.delete "foo" | ||
end | ||
|
||
ruby_version_is "1.9" do | ||
it "uses the locale encoding for keys" do | ||
ENV.send(@method).keys.all? {|k| k.encoding == Encoding.find('locale') }.should be_true | ||
end | ||
|
||
it "uses the locale encoding for values" do | ||
ENV.send(@method).values.all? {|v| v.encoding == Encoding.find('locale') }.should be_true | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require File.expand_path('../../../spec_helper', __FILE__) | ||
require File.expand_path('../shared/to_hash.rb', __FILE__) | ||
|
||
ruby_version_is "2.0" do | ||
describe "ENV.to_hash" do | ||
it_behaves_like(:env_to_hash, :to_h) | ||
end | ||
end |
Oops, something went wrong.