[macruby-changes] [1525] MacRuby/branches/experimental/spec/frozen/core/encoding

source_changes at macosforge.org source_changes at macosforge.org
Sun May 3 07:36:06 PDT 2009


Revision: 1525
          http://trac.macosforge.org/projects/ruby/changeset/1525
Author:   eloy.de.enige at gmail.com
Date:     2009-05-03 07:36:04 -0700 (Sun, 03 May 2009)
Log Message:
-----------
Implemented a few Encoding specs. We need to think about how to handle the difference in the supported encodings between 1.9 and MacRuby.

Modified Paths:
--------------
    MacRuby/branches/experimental/spec/frozen/core/encoding/compatible_spec.rb
    MacRuby/branches/experimental/spec/frozen/core/encoding/dummy_spec.rb
    MacRuby/branches/experimental/spec/frozen/core/encoding/find_spec.rb

Modified: MacRuby/branches/experimental/spec/frozen/core/encoding/compatible_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/compatible_spec.rb	2009-05-03 13:28:36 UTC (rev 1524)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/compatible_spec.rb	2009-05-03 14:36:04 UTC (rev 1525)
@@ -1,5 +1,31 @@
+# encoding: utf-8
+
 require File.dirname(__FILE__) + '/../../spec_helper'
 
 describe "Encoding.compatible?" do
-  it "needs to be reviewed for spec completeness"
+  before :all do
+    @ascii1 = "ant"
+    @ascii2 = "bee"
+    @iso = "\xee"
+    @iso.force_encoding(Encoding::ISO_8859_1)
+    @utf = "δog"
+  end
+
+  it "returns an Encoding instance which will be compatible with both given strings" do
+    encoding = Encoding.compatible?(@ascii1, @ascii2)
+    encoding.should be_kind_of(Encoding)
+    encoding.name.should == "UTF-8"
+
+    encoding = Encoding.compatible?(@ascii1, @iso)
+    encoding.should be_kind_of(Encoding)
+    encoding.name.should == "ISO-8859-1"
+
+    encoding = Encoding.compatible?(@ascii1, @utf)
+    encoding.should be_kind_of(Encoding)
+    encoding.name.should == "UTF-8"
+  end
+
+  it "returns `nil' if no compatible Encoding for the two given strings exists" do
+    Encoding.compatible?(@iso, @utf).should be_nil
+  end
 end

Modified: MacRuby/branches/experimental/spec/frozen/core/encoding/dummy_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/dummy_spec.rb	2009-05-03 13:28:36 UTC (rev 1524)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/dummy_spec.rb	2009-05-03 14:36:04 UTC (rev 1525)
@@ -1,5 +1,40 @@
 require File.dirname(__FILE__) + '/../../spec_helper'
 
+# This will fail on MacRuby. How to properly spec this.
+
 describe "Encoding#dummy?" do
-  it "needs to be reviewed for spec completeness"
+  before :all do
+    @encodings = %w{
+      ASCII-8BIT
+      Big5
+      CP51932 CP850 CP852 CP855 CP949
+      EUC-JP EUC-KR EUC-TW Emacs-Mule eucJP-ms
+      GB12345 GB18030 GB1988 GB2312 GBK
+      IBM437 IBM737 IBM775 IBM852 IBM855 IBM857 IBM860 IBM861 IBM862 IBM863 IBM864 IBM865 IBM866 IBM869
+      ISO-2022-JP ISO-2022-JP-2 ISO-8859-1 ISO-8859-10 ISO-8859-11 ISO-8859-13 ISO-8859-14 ISO-8859-15
+      ISO-8859-16 ISO-8859-2 ISO-8859-3 ISO-8859-4 ISO-8859-5 ISO-8859-6 ISO-8859-7 ISO-8859-8 ISO-8859-9
+      KOI8-R KOI8-U
+      MacJapanese macCentEuro macCroatian macCyrillic macGreek macIceland macRoman macRomania macThai
+      macTurkish macUkraine
+      Shift_JIS stateless-ISO-2022-JP
+      TIS-620
+      US-ASCII UTF-16BE UTF-16LE UTF-32BE UTF-32LE UTF-7 UTF-8 UTF8-MAC
+      Windows-1250 Windows-1251 Windows-1252 Windows-1253 Windows-1254 Windows-1255 Windows-1256
+      Windows-1257 Windows-1258 Windows-31J Windows-874
+    }
+
+    @dummy_encodings = %w{ ISO-2022-JP ISO-2022-JP-2 UTF-7 }
+  end
+
+  it "returns `false' if an encoding can be handled correctly" do
+    (@encodings - @dummy_encodings).each do |name|
+      Encoding.find(name).dummy?.should be_false
+    end
+  end
+
+  it "returns `true' if an encoding is a placeholder which can't be handled correctly" do
+    @dummy_encodings.each do |name|
+      Encoding.find(name).dummy?.should be_true
+    end
+  end
 end

Modified: MacRuby/branches/experimental/spec/frozen/core/encoding/find_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/encoding/find_spec.rb	2009-05-03 13:28:36 UTC (rev 1524)
+++ MacRuby/branches/experimental/spec/frozen/core/encoding/find_spec.rb	2009-05-03 14:36:04 UTC (rev 1525)
@@ -1,5 +1,22 @@
 require File.dirname(__FILE__) + '/../../spec_helper'
 
 describe "Encoding.find" do
-  it "needs to be reviewed for spec completeness"
+  it "returns the Encoding instance for the given name" do
+    encoding = Encoding.find("UTF-8")
+    encoding.should be_kind_of(Encoding)
+    encoding.name.should == "UTF-8"
+  end
+
+  it "raises an ArgumentError if given a name for a non-existing Encoding" do
+    lambda {
+      Encoding.find("encoding-does-not-exist")
+    }.should raise_error(ArgumentError)
+  end
+
+  it "coerces any object to a String if it responds to #to_str" do
+    o = Object.new
+    def o.to_str; "UTF-8"; end
+
+    Encoding.find(o).name.should == "UTF-8"
+  end
 end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090503/d34ede23/attachment.html>


More information about the macruby-changes mailing list