Sha256: b7345d18f36b988adb0358a036fa4a7948b4e110e10122733de82b3bb1312d87

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

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

OBJS = ["bla", 'бла', ['bla', 'бла'], nil]
H = {:bla => 'bla', 'бла' => 1}

describe "encoding-kawai" do

  if RUBY_VERSION < '1.9'
  
    %w{utf8 binary}.each do |enc|
      OBJS.each do |obj|
        it "should word for each object to code with #{enc} on obj: #{obj.inspect}" do
          obj.send("_#{enc}").should == obj
        end
      end
      
      it "should word for each object to code with #{enc} on obj: #{H.inspect}" do
        H.send("_#{enc}").should == H
      end                                
    end
    
  else
  
    %w{utf8 binary}.each do |enc|
      OBJS.each do |obj|
        it "should word for each object to code with #{enc} on obj: #{obj.inspect}" do
          obj.send("_#{enc}").should == obj
        end                                          
      end
      
      it "should word for each object to code with #{enc} on obj: #{H.inspect}" do
        str = enc == 'utf8' ? "бла".force_encoding('utf-8') : "бла".force_encoding('binary')
        H.send("_#{enc}").should == {:bla => 'bla', str => 1}
      end              
      
      it "should set encoding" do
        str = "бла"
        str.encoding.name.should == "UTF-8"
        str.send("_#{enc}")
        if enc == 'utf8'
          str.encoding.name.should == 'UTF-8'
        else
          str.encoding.name.should == 'ASCII-8BIT'
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
encoding-kawai-0.2 spec/encoding-kawai_spec.rb