Sha256: 6b023823b077080b53af9663f33ff090ac408be7f8d7f201a0e2ef9d33c49491

Contents?: true

Size: 1.39 KB

Versions: 26

Compression:

Stored size: 1.39 KB

Contents

# encoding: UTF-8
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

module ICU
  describe Util do
    context "#is_utf8" do
      it "should recognise US-ASCII as a special case of UTF-8" do
        Util.is_utf8("Resume".encode("US-ASCII")).should be_true
      end

      it "should recognise UTF-8" do
        Util.is_utf8("Résumé").should be_true
        Util.is_utf8("δog").should be_true
      end

      it "should recognize other encodings as not being UTF-8" do
        Util.is_utf8("Résumé".encode("ISO-8859-1")).should be_false
        Util.is_utf8("€50".encode("Windows-1252")).should be_false
        Util.is_utf8("ひらがな".encode("Shift_JIS")).should be_false
        Util.is_utf8("\xa3").should be_false
      end
    end

    context "#to_utf8" do
      it "should convert to UTF-8" do
        Util.to_utf8("Resume").should == "Resume"
        Util.to_utf8("Resume".force_encoding("US-ASCII")).encoding.name.should == "UTF-8"
        Util.to_utf8("Résumé".encode("ISO-8859-1")).should == "Résumé"
        Util.to_utf8("Résumé".encode("Windows-1252")).should == "Résumé"
        Util.to_utf8("€50".encode("Windows-1252")).should == "€50"
        Util.to_utf8("\xa350".force_encoding("ASCII-8BIT")).should == "£50"
        Util.to_utf8("\xa350").should == "£50"
        Util.to_utf8("ひらがな".encode("Shift_JIS")).should == "ひらがな"
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
icu_name-1.0.16 spec/util_spec.rb
icu_name-1.0.15 spec/util_spec.rb
icu_name-1.0.14 spec/util_spec.rb
icu_name-1.0.13 spec/util_spec.rb
icu_name-1.0.12 spec/util_spec.rb
icu_name-1.0.11 spec/util_spec.rb
icu_name-1.0.10 spec/util_spec.rb
icu_name-1.0.9 spec/util_spec.rb
icu_name-1.0.8 spec/util_spec.rb
icu_name-1.0.7 spec/util_spec.rb
icu_name-1.0.6 spec/util_spec.rb
icu_name-1.0.5 spec/util_spec.rb
icu_name-1.0.4 spec/util_spec.rb
icu_name-1.0.3 spec/util_spec.rb
icu_name-1.0.2 spec/util_spec.rb
icu_name-1.0.1 spec/util_spec.rb
icu_name-1.0.0 spec/util_spec.rb
icu_name-0.1.4 spec/util_spec.rb
icu_name-0.1.3 spec/util_spec.rb
icu_name-0.1.2 spec/util_spec.rb