Sha256: 535616748e3b4fd7d0b77ed33a2d2ea4d7a71ce1765048104cecd498a826d615

Contents?: true

Size: 1.52 KB

Versions: 25

Compression:

Stored size: 1.52 KB

Contents

#encoding: BINARY
require File.dirname(__FILE__) + '/spec_helper'

class TestValidation
  include Twitter::Validation
end

describe Twitter::Validation do

  it "should disallow invalid BOM character" do
    TestValidation.new.tweet_invalid?("Bom:#{Twitter::Unicode::UFFFE}").should == :invalid_characters
    TestValidation.new.tweet_invalid?("Bom:#{Twitter::Unicode::UFEFF}").should == :invalid_characters
  end

  it "should disallow invalid U+FFFF character" do
    TestValidation.new.tweet_invalid?("Bom:#{Twitter::Unicode::UFFFF}").should == :invalid_characters
  end

  it "should disallow direction change characters" do
    [0x202A, 0x202B, 0x202C, 0x202D, 0x202E].map{|cp| [cp].pack('U') }.each do |char|
      TestValidation.new.tweet_invalid?("Invalid:#{char}").should == :invalid_characters
    end
  end

  it "should disallow non-Unicode" do
    TestValidation.new.tweet_invalid?("not-Unicode:\xfff0").should == :invalid_characters
  end

  it "should allow <= 140 combined accent characters" do
    char = [0x65, 0x0301].pack('U')
    TestValidation.new.tweet_invalid?(char * 139).should == false
    TestValidation.new.tweet_invalid?(char * 140).should == false
    TestValidation.new.tweet_invalid?(char * 141).should == :too_long
  end

  it "should allow <= 140 multi-byte characters" do
    char = [ 0x1d106 ].pack('U')
    TestValidation.new.tweet_invalid?(char * 139).should == false
    TestValidation.new.tweet_invalid?(char * 140).should == false
    TestValidation.new.tweet_invalid?(char * 141).should == :too_long
  end

end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
twitter-text-1.4.11 spec/validation_spec.rb
twitter-text-1.4.10 spec/validation_spec.rb
twitter-text-1.4.9 spec/validation_spec.rb
twitter-text-1.4.8 spec/validation_spec.rb
twitter-text-1.4.7 spec/validation_spec.rb
twitter-text-1.4.6 spec/validation_spec.rb
twitter-text-1.4.5 spec/validation_spec.rb
twitter-text-1.3.4 spec/validation_spec.rb
twitter-text-1.3.3 spec/validation_spec.rb
twitter-text-1.3.2 spec/validation_spec.rb
twitter-text-1.4.2 spec/validation_spec.rb
twitter-text-1.4.1 spec/validation_spec.rb
twitter-text-1.3.1 spec/validation_spec.rb
twitter-text-1.3.0 spec/validation_spec.rb
twitter-text-1.2.5 spec/validation_spec.rb
twitter-text-1.2.4 spec/validation_spec.rb
twitter-text-1.2.3 spec/validation_spec.rb
twitter-text-1.2.2 spec/validation_spec.rb
twitter-text-1.2.1 spec/validation_spec.rb
twitter-text-1.2.0 spec/validation_spec.rb