Created
September 3, 2009 18:13
-
-
Save calavera/180433 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
From 6cd3c50ba52e50bcc577fe729a927718734ce3a6 Mon Sep 17 00:00:00 2001 | |
From: David Calavera <[email protected]> | |
Date: Thu, 3 Sep 2009 20:00:57 +0200 | |
Subject: [PATCH] Encoding specs for IO and FILE initialization | |
--- | |
core/file/initialize_spec.rb | 16 +++++++++++++ | |
core/io/initialize_spec.rb | 51 ++++++++++++++++++++++++++++++++++++++++++ | |
2 files changed, 67 insertions(+), 0 deletions(-) | |
diff --git a/core/file/initialize_spec.rb b/core/file/initialize_spec.rb | |
index 137b3f0..c45c004 100644 | |
--- a/core/file/initialize_spec.rb | |
+++ b/core/file/initialize_spec.rb | |
@@ -3,3 +3,19 @@ require File.dirname(__FILE__) + '/../../spec_helper' | |
describe "File#initialize" do | |
it "needs to be reviewed for spec completeness" | |
end | |
+ | |
+ruby_version_is '1.9' do | |
+ describe "File#initialize" do | |
+ it 'accepts encoding options into mode parameter' do | |
+ io = File.new(__FILE__, 'r:UTF-8:iso-8859-1') | |
+ io.external_encoding.to_s.should == 'UTF-8' | |
+ io.internal_encoding.to_s.should == 'ISO-8859-1' | |
+ end | |
+ | |
+ it 'accepts encoding options as a hash parameter' do | |
+ io = File.new(__FILE__, 'r', :encoding => 'UTF-8:iso-8859-1') | |
+ io.external_encoding.to_s.should == 'UTF-8' | |
+ io.internal_encoding.to_s.should == 'ISO-8859-1' | |
+ end | |
+ end | |
+end | |
diff --git a/core/io/initialize_spec.rb b/core/io/initialize_spec.rb | |
index 6af87f5..6ab2ca2 100644 | |
--- a/core/io/initialize_spec.rb | |
+++ b/core/io/initialize_spec.rb | |
@@ -32,4 +32,55 @@ describe "IO#initialize" do | |
it "raises an Errno::EBADF when given an invalid file descriptor" do | |
lambda { @io.send :initialize, -1, 'w' }.should raise_error(Errno::EBADF) | |
end | |
+ | |
+ ruby_version_is '1.9' do | |
+ it "success when it gets the external encoding within the mode parameter" do | |
+ io = IO.new(2, 'w:UTF-8') | |
+ io.external_encoding.to_s.should == 'UTF-8' | |
+ end | |
+ | |
+ it "success when it gets the external and the internal encoding within the mode parameter" do | |
+ io = IO.new(2, 'w:UTF-8:iso-8859-1') | |
+ io.external_encoding.to_s.should == 'UTF-8' | |
+ io.internal_encoding.to_s.should == 'ISO-8859-1' | |
+ end | |
+ | |
+ it "success when it gets the external encoding as an option" do | |
+ io = IO.new(2, 'w', {:external_encoding => 'UTF-8'}) | |
+ io.external_encoding.to_s.should == 'UTF-8' | |
+ end | |
+ | |
+ it "success when it gets the internal encoding as an option" do | |
+ io = IO.new(2, 'w', {:internal_encoding => 'ISO-8859-1'}) | |
+ io.internal_encoding.to_s.should == 'ISO-8859-1' | |
+ end | |
+ | |
+ it "success when it gets the encoding splitted with colon as an option" do | |
+ io = IO.new(2, 'w', {:encoding => 'UTF-8:iso-8859-1'}) | |
+ io.external_encoding.to_s.should == 'UTF-8' | |
+ io.internal_encoding.to_s.should == 'ISO-8859-1' | |
+ end | |
+ | |
+ it "ingores encoding option when external encoding option is present" do | |
+ io = IO.new(2, 'w', {:external_encoding => 'UTF-8', :encoding => 'iso-8859-1:iso-8859-1'}) | |
+ io.external_encoding.to_s.should == 'UTF-8' | |
+ end | |
+ | |
+ it "ingores encoding option when internal encoding option is present" do | |
+ io = IO.new(2, 'w', {:internal_encoding => 'ISO-8859-1', :encoding => 'iso-8859-1:iso-8859-1'}) | |
+ io.internal_encoding.to_s.should == 'ISO-8859-1' | |
+ end | |
+ | |
+ it "success when it gets the encoding within the mode option hash" do | |
+ io = IO.new(2, {:mode => 'w:UTF-8:iso-8859-1'}) | |
+ io.external_encoding.to_s.should == 'UTF-8' | |
+ io.internal_encoding.to_s.should == 'ISO-8859-1' | |
+ end | |
+ | |
+ it "should ignore internal encoding when is the same as external encoding" do | |
+ io = IO.new(2, 'w', {:internal_encoding => 'UTF-8'}) | |
+ io.external_encoding.to_s.should == 'UTF-8' | |
+ io.internal_encoding.to_s.should == '' | |
+ end | |
+ end | |
end | |
-- | |
1.6.0.3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment