ritter 0.0.87 → 0.0.88

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/spec/test_urls.rb ADDED
@@ -0,0 +1,80 @@
1
+ # encoding: utf-8
2
+
3
+ module TestUrls
4
+ VALID = [
5
+ "http://google.com",
6
+ "http://foobar.com/#",
7
+ "http://google.com/#foo",
8
+ "http://google.com/#search?q=iphone%20-filter%3Alinks",
9
+ "http://twitter.com/#search?q=iphone%20-filter%3Alinks",
10
+ "http://somedomain.com/index.php?path=/abc/def/",
11
+ "http://www.boingboing.net/2007/02/14/katamari_damacy_phon.html",
12
+ "http://somehost.com:3000",
13
+ "http://xo.com/~matthew+%-x",
14
+ "http://en.wikipedia.org/wiki/Primer_(film)",
15
+ "http://www.ams.org/bookstore-getitem/item=mbk-59",
16
+ "http://chilp.it/?77e8fd",
17
+ "http://tell.me/why",
18
+ "http://longtlds.info",
19
+ "http://✪df.ws/ejp",
20
+ "http://日本.com",
21
+ "http://search.twitter.com/search?q=avro&lang=en",
22
+ "http://mrs.domain-dash.biz",
23
+ "http://x.com/has/one/char/domain",
24
+ "http://t.co/nwcLTFF",
25
+ "http://sub_domain-dash.twitter.com",
26
+ "http://a.b.cd",
27
+ "http://a_b.c-d.com",
28
+ "http://a-b.b.com",
29
+ "http://twitter-dash.com",
30
+ "http://msdn.microsoft.com/ja-jp/library/system.net.httpwebrequest(v=VS.100).aspx",
31
+ "www.foobar.com",
32
+ "WWW.FOOBAR.COM",
33
+ "www.foobar.co.jp",
34
+ "http://t.co",
35
+ "t.co/nwcLTFF"
36
+ ] unless defined?(TestUrls::VALID)
37
+
38
+ INVALID = [
39
+ "http://no-tld",
40
+ "http://tld-too-short.x",
41
+ "http://-doman_dash.com",
42
+ "http://_leadingunderscore.twitter.com",
43
+ "http://trailingunderscore_.twitter.com",
44
+ "http://-leadingdash.twitter.com",
45
+ "http://trailingdash-.twitter.com",
46
+ "http://-leadingdash.com",
47
+ "http://trailingdash-.com",
48
+ "http://no_underscores.com",
49
+ "http://test.c_o_m",
50
+ "http://test.c-o-m",
51
+ "http://twitt#{[0x202A].pack('U')}er.com",
52
+ "http://twitt#{[0x202B].pack('U')}er.com",
53
+ "http://twitt#{[0x202C].pack('U')}er.com",
54
+ "http://twitt#{[0x202D].pack('U')}er.com",
55
+ "http://twitt#{[0x202E].pack('U')}er.com"
56
+ ] unless defined?(TestUrls::INVALID)
57
+
58
+ TCO = [
59
+ "http://t.co/P53cv5yO!",
60
+ "http://t.co/fQJmiPGg***",
61
+ "http://t.co/pbY2NfTZ's",
62
+ "http://t.co/2vYHpAc5;",
63
+ "http://t.co/ulYGBYSo:",
64
+ "http://t.co/GeT4bSiw=win",
65
+ "http://t.co/8MkmHU0k+fun",
66
+ "http://t.co/TKLp64dY.yes,",
67
+ "http://t.co/8vuO27cI$$",
68
+ "http://t.co/rPYTvdA8/",
69
+ "http://t.co/WvtMw5ku%",
70
+ "http://t.co/8t7G3ddS#",
71
+ "http://t.co/nfHNJDV2/#!",
72
+ "http://t.co/gK6NOXHs[good]",
73
+ "http://t.co/dMrT0o1Y]bad",
74
+ "http://t.co/FNkPfmii-",
75
+ "http://t.co/sMgS3pjI_oh",
76
+ "http://t.co/F8Dq3Plb~",
77
+ "http://t.co/ivvH58vC&help",
78
+ "http://t.co/iUBL15zD|NZ5KYLQ8"
79
+ ] unless defined?(TestUrls::TCO)
80
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ major, minor, patch = RUBY_VERSION.split('.')
5
+ if major.to_i == 1 && minor.to_i < 9
6
+ describe "base" do
7
+ before do
8
+ $KCODE = 'NONE'
9
+ end
10
+
11
+ after do
12
+ $KCODE = 'u'
13
+ end
14
+
15
+ it "should raise with invalid KCODE on Ruby < 1.9" do
16
+ lambda do
17
+ require 'twitter-text'
18
+ end.should raise_error
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ describe Twitter::Unicode do
5
+
6
+ it "should lazy-init constants" do
7
+ Twitter::Unicode.const_defined?(:UFEB6).should == false
8
+ Twitter::Unicode::UFEB6.should_not be_nil
9
+ Twitter::Unicode::UFEB6.should be_kind_of(String)
10
+ Twitter::Unicode.const_defined?(:UFEB6).should == true
11
+ end
12
+
13
+ it "should return corresponding character" do
14
+ Twitter::Unicode::UFEB6.should == [0xfeb6].pack('U')
15
+ end
16
+
17
+ it "should allow lowercase notation" do
18
+ Twitter::Unicode::Ufeb6.should == Twitter::Unicode::UFEB6
19
+ Twitter::Unicode::Ufeb6.should === Twitter::Unicode::UFEB6
20
+ end
21
+
22
+ it "should allow underscore notation" do
23
+ Twitter::Unicode::U_FEB6.should == Twitter::Unicode::UFEB6
24
+ Twitter::Unicode::U_FEB6.should === Twitter::Unicode::UFEB6
25
+ end
26
+
27
+ it "should raise on invalid codepoints" do
28
+ lambda { Twitter::Unicode::FFFFFF }.should raise_error(NameError)
29
+ end
30
+
31
+ end
@@ -0,0 +1,43 @@
1
+ # encoding: binary
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ class TestValidation
5
+ include Twitter::Validation
6
+ end
7
+
8
+ describe Twitter::Validation do
9
+
10
+ it "should disallow invalid BOM character" do
11
+ TestValidation.new.tweet_invalid?("Bom:#{Twitter::Unicode::UFFFE}").should == :invalid_characters
12
+ TestValidation.new.tweet_invalid?("Bom:#{Twitter::Unicode::UFEFF}").should == :invalid_characters
13
+ end
14
+
15
+ it "should disallow invalid U+FFFF character" do
16
+ TestValidation.new.tweet_invalid?("Bom:#{Twitter::Unicode::UFFFF}").should == :invalid_characters
17
+ end
18
+
19
+ it "should disallow direction change characters" do
20
+ [0x202A, 0x202B, 0x202C, 0x202D, 0x202E].map{|cp| [cp].pack('U') }.each do |char|
21
+ TestValidation.new.tweet_invalid?("Invalid:#{char}").should == :invalid_characters
22
+ end
23
+ end
24
+
25
+ it "should disallow non-Unicode" do
26
+ TestValidation.new.tweet_invalid?("not-Unicode:\xfff0").should == :invalid_characters
27
+ end
28
+
29
+ it "should allow <= 140 combined accent characters" do
30
+ char = [0x65, 0x0301].pack('U')
31
+ TestValidation.new.tweet_invalid?(char * 139).should == false
32
+ TestValidation.new.tweet_invalid?(char * 140).should == false
33
+ TestValidation.new.tweet_invalid?(char * 141).should == :too_long
34
+ end
35
+
36
+ it "should allow <= 140 multi-byte characters" do
37
+ char = [ 0x1d106 ].pack('U')
38
+ TestValidation.new.tweet_invalid?(char * 139).should == false
39
+ TestValidation.new.tweet_invalid?(char * 140).should == false
40
+ TestValidation.new.tweet_invalid?(char * 141).should == :too_long
41
+ end
42
+
43
+ end
@@ -0,0 +1,182 @@
1
+ require 'multi_json'
2
+ require 'nokogiri'
3
+ require 'test/unit'
4
+ require 'yaml'
5
+
6
+ # Ruby 1.8 encoding check
7
+ major, minor, patch = RUBY_VERSION.split('.')
8
+ if major.to_i == 1 && minor.to_i < 9
9
+ $KCODE='u'
10
+ end
11
+
12
+ require File.expand_path('../../lib/twitter-text', __FILE__)
13
+
14
+ class ConformanceTest < Test::Unit::TestCase
15
+ include Twitter::Extractor
16
+ include Twitter::Autolink
17
+ include Twitter::HitHighlighter
18
+ include Twitter::Validation
19
+
20
+ private
21
+
22
+ %w(description expected text json hits).each do |key|
23
+ define_method key.to_sym do
24
+ @test_info[key]
25
+ end
26
+ end
27
+
28
+ def assert_equal_without_attribute_order(expected, actual, failure_message = nil)
29
+ assert_block(build_message(failure_message, "<?> expected but was\n<?>", expected, actual)) do
30
+ equal_nodes?(Nokogiri::HTML(expected).root, Nokogiri::HTML(actual).root)
31
+ end
32
+ end
33
+
34
+ def equal_nodes?(expected, actual)
35
+ return false unless expected.name == actual.name
36
+ return false unless ordered_attributes(expected) == ordered_attributes(actual)
37
+ return false if expected.text? && actual.text? && expected.content != actual.content
38
+
39
+ expected.children.each_with_index do |child, index|
40
+ return false unless equal_nodes?(child, actual.children[index])
41
+ end
42
+
43
+ true
44
+ end
45
+
46
+ def ordered_attributes(element)
47
+ element.attribute_nodes.map{|attr| [attr.name, attr.value]}.sort
48
+ end
49
+
50
+ CONFORMANCE_DIR = ENV['CONFORMANCE_DIR'] || File.expand_path("../twitter-text-conformance", __FILE__)
51
+
52
+ def self.def_conformance_test(file, test_type, &block)
53
+ yaml = YAML.load_file(File.join(CONFORMANCE_DIR, file))
54
+ raise "No such test suite: #{test_type.to_s}" unless yaml["tests"][test_type.to_s]
55
+
56
+ yaml["tests"][test_type.to_s].each do |test_info|
57
+ name = :"test_#{test_type}_#{test_info['description']}"
58
+ define_method name do
59
+ @test_info = test_info
60
+ instance_eval(&block)
61
+ end
62
+ end
63
+ end
64
+
65
+ public
66
+
67
+ # Extractor Conformance
68
+ def_conformance_test("extract.yml", :replies) do
69
+ assert_equal expected, extract_reply_screen_name(text), description
70
+ end
71
+
72
+ def_conformance_test("extract.yml", :mentions) do
73
+ assert_equal expected, extract_mentioned_screen_names(text), description
74
+ end
75
+
76
+ def_conformance_test("extract.yml", :mentions_with_indices) do
77
+ e = expected.map{|elem| elem.inject({}){|h, (k,v)| h[k.to_sym] = v; h} }
78
+ assert_equal e, extract_mentioned_screen_names_with_indices(text), description
79
+ end
80
+
81
+ def_conformance_test("extract.yml", :mentions_or_lists_with_indices) do
82
+ e = expected.map{|elem| elem.inject({}){|h, (k,v)| h[k.to_sym] = v; h} }
83
+ assert_equal e, extract_mentions_or_lists_with_indices(text), description
84
+ end
85
+
86
+ def_conformance_test("extract.yml", :urls) do
87
+ assert_equal expected, extract_urls(text), description
88
+ expected.each do |expected_url|
89
+ assert_equal true, valid_url?(expected_url, true, false), "expected url [#{expected_url}] not valid"
90
+ end
91
+ end
92
+
93
+ def_conformance_test("extract.yml", :urls_with_indices) do
94
+ e = expected.map{|elem| elem.inject({}){|h, (k,v)| h[k.to_sym] = v; h} }
95
+ assert_equal e, extract_urls_with_indices(text), description
96
+ end
97
+
98
+ def_conformance_test("extract.yml", :hashtags) do
99
+ assert_equal expected, extract_hashtags(text), description
100
+ end
101
+
102
+ def_conformance_test("extract.yml", :hashtags_with_indices) do
103
+ e = expected.map{|elem| elem.inject({}){|h, (k,v)| h[k.to_sym] = v; h} }
104
+ assert_equal e, extract_hashtags_with_indices(text), description
105
+ end
106
+
107
+ def_conformance_test("extract.yml", :cashtags) do
108
+ assert_equal expected, extract_cashtags(text), description
109
+ end
110
+
111
+ def_conformance_test("extract.yml", :cashtags_with_indices) do
112
+ e = expected.map{|elem| elem.inject({}){|h, (k,v)| h[k.to_sym] = v; h} }
113
+ assert_equal e, extract_cashtags_with_indices(text), description
114
+ end
115
+
116
+ # Autolink Conformance
117
+ def_conformance_test("autolink.yml", :usernames) do
118
+ assert_equal_without_attribute_order expected, auto_link_usernames_or_lists(text, :suppress_no_follow => true), description
119
+ end
120
+
121
+ def_conformance_test("autolink.yml", :lists) do
122
+ assert_equal_without_attribute_order expected, auto_link_usernames_or_lists(text, :suppress_no_follow => true), description
123
+ end
124
+
125
+ def_conformance_test("autolink.yml", :urls) do
126
+ assert_equal_without_attribute_order expected, auto_link_urls(text, :suppress_no_follow => true), description
127
+ end
128
+
129
+ def_conformance_test("autolink.yml", :hashtags) do
130
+ assert_equal_without_attribute_order expected, auto_link_hashtags(text, :suppress_no_follow => true), description
131
+ end
132
+
133
+ def_conformance_test("autolink.yml", :cashtags) do
134
+ assert_equal_without_attribute_order expected, auto_link_cashtags(text, :suppress_no_follow => true), description
135
+ end
136
+
137
+ def_conformance_test("autolink.yml", :all) do
138
+ assert_equal_without_attribute_order expected, auto_link(text, :suppress_no_follow => true), description
139
+ end
140
+
141
+ def_conformance_test("autolink.yml", :json) do
142
+ assert_equal_without_attribute_order expected, auto_link_with_json(text, MultiJson.load(json), :suppress_no_follow => true), description
143
+ end
144
+
145
+ # HitHighlighter Conformance
146
+ def_conformance_test("hit_highlighting.yml", :plain_text) do
147
+ assert_equal expected, hit_highlight(text, hits), description
148
+ end
149
+
150
+ def_conformance_test("hit_highlighting.yml", :with_links) do
151
+ assert_equal expected, hit_highlight(text, hits), description
152
+ end
153
+
154
+ # Validation Conformance
155
+ def_conformance_test("validate.yml", :tweets) do
156
+ assert_equal expected, valid_tweet_text?(text), description
157
+ end
158
+
159
+ def_conformance_test("validate.yml", :usernames) do
160
+ assert_equal expected, valid_username?(text), description
161
+ end
162
+
163
+ def_conformance_test("validate.yml", :lists) do
164
+ assert_equal expected, valid_list?(text), description
165
+ end
166
+
167
+ def_conformance_test("validate.yml", :urls) do
168
+ assert_equal expected, valid_url?(text), description
169
+ end
170
+
171
+ def_conformance_test("validate.yml", :urls_without_protocol) do
172
+ assert_equal expected, valid_url?(text, true, false), description
173
+ end
174
+
175
+ def_conformance_test("validate.yml", :hashtags) do
176
+ assert_equal expected, valid_hashtag?(text), description
177
+ end
178
+
179
+ def_conformance_test("validate.yml", :lengths) do
180
+ assert_equal expected, tweet_length(text), description
181
+ end
182
+ end
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "ritter"
5
+ s.version = "0.0.88"
6
+ s.authors = ["Fernando Paladini", "Matt Sanford", "Patrick Ewing", "Ben Cherry", "Britt Selvitelle",
7
+ "Raffi Krikorian", "J.P. Cummins", "Yoshimasa Niwa", "Keita Fujii", "James Koval"]
8
+ s.email = ["fernando.paladini@techsempre.com","matt@twitter.com", "patrick.henry.ewing@gmail.com", "bcherry@gmail.com", "bs@brittspace.com",
9
+ "raffi@twitter.com", "jcummins@twitter.com", "niw@niw.at", "keita@twitter.com", "jkoval@twitter.com"]
10
+ s.homepage = "http://www.noise.com"
11
+ s.description = s.summary = "A edited gem that provides text handling for Twitter that parse any hashtag (except blank spaces)"
12
+
13
+ s.platform = Gem::Platform::RUBY
14
+ s.has_rdoc = true
15
+ s.summary = "Twitter text handling library"
16
+
17
+ s.add_development_dependency "multi_json", "~> 1.3"
18
+ s.add_development_dependency "nokogiri"
19
+ s.add_development_dependency "rake"
20
+ s.add_development_dependency "rdoc"
21
+ s.add_development_dependency "rspec"
22
+ s.add_development_dependency "simplecov"
23
+ s.add_runtime_dependency "unf", "~> 0.1.0"
24
+
25
+ s.files = `git ls-files`.split("\n")
26
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
27
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
28
+ s.require_paths = ["lib"]
29
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ritter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.87
4
+ version: 0.0.88
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fernando Paladini
@@ -17,7 +17,7 @@ authors:
17
17
  autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
- date: 2013-04-12 00:00:00.000000000 Z
20
+ date: 2013-05-17 00:00:00.000000000 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: multi_json
@@ -109,15 +109,16 @@ dependencies:
109
109
  requirements:
110
110
  - - ~>
111
111
  - !ruby/object:Gem::Version
112
- version: 0.0.5
112
+ version: 0.1.0
113
113
  type: :runtime
114
114
  prerelease: false
115
115
  version_requirements: !ruby/object:Gem::Requirement
116
116
  requirements:
117
117
  - - ~>
118
118
  - !ruby/object:Gem::Version
119
- version: 0.0.5
120
- description: A gem that provides text handling
119
+ version: 0.1.0
120
+ description: A edited gem that provides text handling for Twitter that parse any hashtag
121
+ (except blank spaces)
121
122
  email:
122
123
  - fernando.paladini@techsempre.com
123
124
  - matt@twitter.com
@@ -132,8 +133,41 @@ email:
132
133
  executables: []
133
134
  extensions: []
134
135
  extra_rdoc_files: []
135
- files: []
136
- homepage: http://instablah.herokuapp.com
136
+ files:
137
+ - .gemtest
138
+ - .gitignore
139
+ - .gitmodules
140
+ - .rspec
141
+ - .travis.yml
142
+ - Gemfile
143
+ - LICENSE
144
+ - README.rdoc
145
+ - Rakefile
146
+ - lib/twitter-text.rb
147
+ - lib/twitter-text/autolink.rb
148
+ - lib/twitter-text/deprecation.rb
149
+ - lib/twitter-text/extractor.rb
150
+ - lib/twitter-text/hash_helper.rb
151
+ - lib/twitter-text/hit_highlighter.rb
152
+ - lib/twitter-text/regex.rb
153
+ - lib/twitter-text/rewriter.rb
154
+ - lib/twitter-text/unicode.rb
155
+ - lib/twitter-text/validation.rb
156
+ - script/destroy
157
+ - script/generate
158
+ - spec/autolinking_spec.rb
159
+ - spec/extractor_spec.rb
160
+ - spec/hithighlighter_spec.rb
161
+ - spec/regex_spec.rb
162
+ - spec/rewriter_spec.rb
163
+ - spec/spec_helper.rb
164
+ - spec/test_urls.rb
165
+ - spec/twitter_text_spec.rb
166
+ - spec/unicode_spec.rb
167
+ - spec/validation_spec.rb
168
+ - test/conformance_test.rb
169
+ - twitter-text.gemspec
170
+ homepage: http://www.noise.com
137
171
  licenses: []
138
172
  metadata: {}
139
173
  post_install_message:
@@ -155,5 +189,5 @@ rubyforge_project:
155
189
  rubygems_version: 2.0.3
156
190
  signing_key:
157
191
  specification_version: 4
158
- summary: Text handling library
192
+ summary: Twitter text handling library
159
193
  test_files: []