Sha256: 47913af3ec2cc4fb6d126d9a9aaf2e581cb63ebb6aafe64ab223a333513d2297

Contents?: true

Size: 1.27 KB

Versions: 7

Compression:

Stored size: 1.27 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

require 'dionysus/string'
describe String do
  it "should encode64s" do
    "abcde\240z405".encode64s.should == "YWJjZGWgejQwNQ=="
  end
  
  it "should encode64" do
    "abcde\240z405".encode64.should == "YWJjZGWgejQwNQ==\n"
  end
  
  it "should decode64" do
    "YWJjZGWgejQwNQ==".decode64.should == "abcde\240z405"
    "YWJjZGWgejQwNQ==\n".decode64.should == "abcde\240z405"
  end
  
  it "should encode_hex" do
    "abcde\240z405".encode_hex.should == "6162636465a07a343035"
    "abcde\240z405".encode_hexidecimal.should == "6162636465a07a343035"
  end
  
  it "should decode_hex" do
    '6162636465a07a343035'.decode_hex.should == "abcde\240z405"
    '6162636465a07a343035'.decode_hexidecimal.should == "abcde\240z405"
  end

  describe 'encoding detection' do
    it 'should return nil for blank' do
      ''.detect_encoding.should be_nil
    end
    
    it 'should match hex' do
      '6162636465a07a343035'.detect_encoding.should == :hex
    end
    
    it 'should match base64' do
      "YWJjZGWgejQwNQ==".detect_encoding.should == :base64
      "YWJjZGWgejQwNQ==\n".detect_encoding.should == :base64
    end
    
    it 'should default to binary' do
      "abcde\240z405".detect_encoding.should == :binary
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
dionysus-1.0.2 spec/string_spec.rb
dionysus-1.0.1 spec/string_spec.rb
dionysus-1.0.0 spec/string_spec.rb
dionysus-0.4.0 spec/string_spec.rb
dionysus-0.3.2 spec/string_spec.rb
dionysus-0.3.1 spec/string_spec.rb
dionysus-0.3.0 spec/string_spec.rb