Sha256: f0f08ca3e4c317f0d76fdcd75ba7933d1f3409a254467e9d8bf33f8f04ef89cc

Contents?: true

Size: 1.52 KB

Versions: 31

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

31 entries across 31 versions & 5 rubygems

Version Path
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/twitter-text-1.13.0/spec/validation_spec.rb
twitter-text-1.13.0 spec/validation_spec.rb
twitter-text-1.12.0 spec/validation_spec.rb
twitter-text-1.11.0 spec/validation_spec.rb
twitter-text-1.10.0 spec/validation_spec.rb
twitter-text-1.9.2 spec/validation_spec.rb
twitter-text-1.9.1 spec/validation_spec.rb
twitter-text-1.9.0 spec/validation_spec.rb
twitter-text-1.8.0 spec/validation_spec.rb
twitter-text-1.7.0 spec/validation_spec.rb
twitter-text-1.6.4 spec/validation_spec.rb
twitter-text-relative-1.6.2.3 spec/validation_spec.rb
twitter-text-relative-1.6.2.pre.3 spec/validation_spec.rb
twitter-text-relative-1.6.2.2 spec/validation_spec.rb
twitter-text-relative-1.6.2.1 spec/validation_spec.rb
twitter-text-1.6.3 spec/validation_spec.rb
twitter-text-1.6.2 spec/validation_spec.rb
ritter-0.0.91 spec/validation_spec.rb
ritter-0.0.90 spec/validation_spec.rb
ritter-0.0.89 spec/validation_spec.rb