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