rsl-stringex 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +74 -0
  3. data/Rakefile +28 -0
  4. data/init.rb +7 -0
  5. data/lib/lucky_sneaks/acts_as_url.rb +82 -0
  6. data/lib/lucky_sneaks/string_extensions.rb +165 -0
  7. data/lib/lucky_sneaks/unidecoder.rb +48 -0
  8. data/lib/lucky_sneaks/unidecoder_data/x00.yml +257 -0
  9. data/lib/lucky_sneaks/unidecoder_data/x01.yml +257 -0
  10. data/lib/lucky_sneaks/unidecoder_data/x02.yml +256 -0
  11. data/lib/lucky_sneaks/unidecoder_data/x03.yml +256 -0
  12. data/lib/lucky_sneaks/unidecoder_data/x04.yml +256 -0
  13. data/lib/lucky_sneaks/unidecoder_data/x05.yml +256 -0
  14. data/lib/lucky_sneaks/unidecoder_data/x06.yml +256 -0
  15. data/lib/lucky_sneaks/unidecoder_data/x07.yml +256 -0
  16. data/lib/lucky_sneaks/unidecoder_data/x09.yml +256 -0
  17. data/lib/lucky_sneaks/unidecoder_data/x0a.yml +256 -0
  18. data/lib/lucky_sneaks/unidecoder_data/x0b.yml +256 -0
  19. data/lib/lucky_sneaks/unidecoder_data/x0c.yml +256 -0
  20. data/lib/lucky_sneaks/unidecoder_data/x0d.yml +256 -0
  21. data/lib/lucky_sneaks/unidecoder_data/x0e.yml +256 -0
  22. data/lib/lucky_sneaks/unidecoder_data/x0f.yml +256 -0
  23. data/lib/lucky_sneaks/unidecoder_data/x10.yml +256 -0
  24. data/lib/lucky_sneaks/unidecoder_data/x11.yml +256 -0
  25. data/lib/lucky_sneaks/unidecoder_data/x12.yml +257 -0
  26. data/lib/lucky_sneaks/unidecoder_data/x13.yml +256 -0
  27. data/lib/lucky_sneaks/unidecoder_data/x14.yml +257 -0
  28. data/lib/lucky_sneaks/unidecoder_data/x15.yml +257 -0
  29. data/lib/lucky_sneaks/unidecoder_data/x16.yml +256 -0
  30. data/lib/lucky_sneaks/unidecoder_data/x17.yml +256 -0
  31. data/lib/lucky_sneaks/unidecoder_data/x18.yml +256 -0
  32. data/lib/lucky_sneaks/unidecoder_data/x1e.yml +256 -0
  33. data/lib/lucky_sneaks/unidecoder_data/x1f.yml +256 -0
  34. data/lib/lucky_sneaks/unidecoder_data/x20.yml +256 -0
  35. data/lib/lucky_sneaks/unidecoder_data/x21.yml +256 -0
  36. data/lib/lucky_sneaks/unidecoder_data/x22.yml +256 -0
  37. data/lib/lucky_sneaks/unidecoder_data/x23.yml +256 -0
  38. data/lib/lucky_sneaks/unidecoder_data/x24.yml +256 -0
  39. data/lib/lucky_sneaks/unidecoder_data/x25.yml +256 -0
  40. data/lib/lucky_sneaks/unidecoder_data/x26.yml +256 -0
  41. data/lib/lucky_sneaks/unidecoder_data/x27.yml +256 -0
  42. data/lib/lucky_sneaks/unidecoder_data/x28.yml +257 -0
  43. data/lib/lucky_sneaks/unidecoder_data/x2e.yml +256 -0
  44. data/lib/lucky_sneaks/unidecoder_data/x2f.yml +256 -0
  45. data/lib/lucky_sneaks/unidecoder_data/x30.yml +256 -0
  46. data/lib/lucky_sneaks/unidecoder_data/x31.yml +256 -0
  47. data/lib/lucky_sneaks/unidecoder_data/x32.yml +256 -0
  48. data/lib/lucky_sneaks/unidecoder_data/x33.yml +256 -0
  49. data/lib/lucky_sneaks/unidecoder_data/x4d.yml +256 -0
  50. data/lib/lucky_sneaks/unidecoder_data/x4e.yml +257 -0
  51. data/lib/lucky_sneaks/unidecoder_data/x4f.yml +257 -0
  52. data/lib/lucky_sneaks/unidecoder_data/x50.yml +257 -0
  53. data/lib/lucky_sneaks/unidecoder_data/x51.yml +257 -0
  54. data/lib/lucky_sneaks/unidecoder_data/x52.yml +257 -0
  55. data/lib/lucky_sneaks/unidecoder_data/x53.yml +257 -0
  56. data/lib/lucky_sneaks/unidecoder_data/x54.yml +257 -0
  57. data/lib/lucky_sneaks/unidecoder_data/x55.yml +257 -0
  58. data/lib/lucky_sneaks/unidecoder_data/x56.yml +257 -0
  59. data/lib/lucky_sneaks/unidecoder_data/x57.yml +257 -0
  60. data/lib/lucky_sneaks/unidecoder_data/x58.yml +257 -0
  61. data/lib/lucky_sneaks/unidecoder_data/x59.yml +257 -0
  62. data/lib/lucky_sneaks/unidecoder_data/x5a.yml +257 -0
  63. data/lib/lucky_sneaks/unidecoder_data/x5b.yml +257 -0
  64. data/lib/lucky_sneaks/unidecoder_data/x5c.yml +257 -0
  65. data/lib/lucky_sneaks/unidecoder_data/x5d.yml +257 -0
  66. data/lib/lucky_sneaks/unidecoder_data/x5e.yml +257 -0
  67. data/lib/lucky_sneaks/unidecoder_data/x5f.yml +257 -0
  68. data/lib/lucky_sneaks/unidecoder_data/x60.yml +257 -0
  69. data/lib/lucky_sneaks/unidecoder_data/x61.yml +257 -0
  70. data/lib/lucky_sneaks/unidecoder_data/x62.yml +257 -0
  71. data/lib/lucky_sneaks/unidecoder_data/x63.yml +257 -0
  72. data/lib/lucky_sneaks/unidecoder_data/x64.yml +257 -0
  73. data/lib/lucky_sneaks/unidecoder_data/x65.yml +257 -0
  74. data/lib/lucky_sneaks/unidecoder_data/x66.yml +257 -0
  75. data/lib/lucky_sneaks/unidecoder_data/x67.yml +257 -0
  76. data/lib/lucky_sneaks/unidecoder_data/x68.yml +257 -0
  77. data/lib/lucky_sneaks/unidecoder_data/x69.yml +257 -0
  78. data/lib/lucky_sneaks/unidecoder_data/x6a.yml +257 -0
  79. data/lib/lucky_sneaks/unidecoder_data/x6b.yml +257 -0
  80. data/lib/lucky_sneaks/unidecoder_data/x6c.yml +257 -0
  81. data/lib/lucky_sneaks/unidecoder_data/x6d.yml +257 -0
  82. data/lib/lucky_sneaks/unidecoder_data/x6e.yml +257 -0
  83. data/lib/lucky_sneaks/unidecoder_data/x6f.yml +257 -0
  84. data/lib/lucky_sneaks/unidecoder_data/x70.yml +257 -0
  85. data/lib/lucky_sneaks/unidecoder_data/x71.yml +257 -0
  86. data/lib/lucky_sneaks/unidecoder_data/x72.yml +257 -0
  87. data/lib/lucky_sneaks/unidecoder_data/x73.yml +257 -0
  88. data/lib/lucky_sneaks/unidecoder_data/x74.yml +257 -0
  89. data/lib/lucky_sneaks/unidecoder_data/x75.yml +257 -0
  90. data/lib/lucky_sneaks/unidecoder_data/x76.yml +257 -0
  91. data/lib/lucky_sneaks/unidecoder_data/x77.yml +257 -0
  92. data/lib/lucky_sneaks/unidecoder_data/x78.yml +257 -0
  93. data/lib/lucky_sneaks/unidecoder_data/x79.yml +257 -0
  94. data/lib/lucky_sneaks/unidecoder_data/x7a.yml +257 -0
  95. data/lib/lucky_sneaks/unidecoder_data/x7b.yml +257 -0
  96. data/lib/lucky_sneaks/unidecoder_data/x7c.yml +257 -0
  97. data/lib/lucky_sneaks/unidecoder_data/x7d.yml +257 -0
  98. data/lib/lucky_sneaks/unidecoder_data/x7e.yml +257 -0
  99. data/lib/lucky_sneaks/unidecoder_data/x7f.yml +257 -0
  100. data/lib/lucky_sneaks/unidecoder_data/x80.yml +257 -0
  101. data/lib/lucky_sneaks/unidecoder_data/x81.yml +257 -0
  102. data/lib/lucky_sneaks/unidecoder_data/x82.yml +257 -0
  103. data/lib/lucky_sneaks/unidecoder_data/x83.yml +257 -0
  104. data/lib/lucky_sneaks/unidecoder_data/x84.yml +257 -0
  105. data/lib/lucky_sneaks/unidecoder_data/x85.yml +257 -0
  106. data/lib/lucky_sneaks/unidecoder_data/x86.yml +257 -0
  107. data/lib/lucky_sneaks/unidecoder_data/x87.yml +257 -0
  108. data/lib/lucky_sneaks/unidecoder_data/x88.yml +257 -0
  109. data/lib/lucky_sneaks/unidecoder_data/x89.yml +257 -0
  110. data/lib/lucky_sneaks/unidecoder_data/x8a.yml +257 -0
  111. data/lib/lucky_sneaks/unidecoder_data/x8b.yml +257 -0
  112. data/lib/lucky_sneaks/unidecoder_data/x8c.yml +257 -0
  113. data/lib/lucky_sneaks/unidecoder_data/x8d.yml +257 -0
  114. data/lib/lucky_sneaks/unidecoder_data/x8e.yml +257 -0
  115. data/lib/lucky_sneaks/unidecoder_data/x8f.yml +257 -0
  116. data/lib/lucky_sneaks/unidecoder_data/x90.yml +257 -0
  117. data/lib/lucky_sneaks/unidecoder_data/x91.yml +257 -0
  118. data/lib/lucky_sneaks/unidecoder_data/x92.yml +257 -0
  119. data/lib/lucky_sneaks/unidecoder_data/x93.yml +257 -0
  120. data/lib/lucky_sneaks/unidecoder_data/x94.yml +257 -0
  121. data/lib/lucky_sneaks/unidecoder_data/x95.yml +257 -0
  122. data/lib/lucky_sneaks/unidecoder_data/x96.yml +257 -0
  123. data/lib/lucky_sneaks/unidecoder_data/x97.yml +257 -0
  124. data/lib/lucky_sneaks/unidecoder_data/x98.yml +257 -0
  125. data/lib/lucky_sneaks/unidecoder_data/x99.yml +257 -0
  126. data/lib/lucky_sneaks/unidecoder_data/x9a.yml +257 -0
  127. data/lib/lucky_sneaks/unidecoder_data/x9b.yml +257 -0
  128. data/lib/lucky_sneaks/unidecoder_data/x9c.yml +257 -0
  129. data/lib/lucky_sneaks/unidecoder_data/x9d.yml +257 -0
  130. data/lib/lucky_sneaks/unidecoder_data/x9e.yml +257 -0
  131. data/lib/lucky_sneaks/unidecoder_data/x9f.yml +256 -0
  132. data/lib/lucky_sneaks/unidecoder_data/xa0.yml +257 -0
  133. data/lib/lucky_sneaks/unidecoder_data/xa1.yml +257 -0
  134. data/lib/lucky_sneaks/unidecoder_data/xa2.yml +257 -0
  135. data/lib/lucky_sneaks/unidecoder_data/xa3.yml +257 -0
  136. data/lib/lucky_sneaks/unidecoder_data/xa4.yml +256 -0
  137. data/lib/lucky_sneaks/unidecoder_data/xac.yml +257 -0
  138. data/lib/lucky_sneaks/unidecoder_data/xad.yml +257 -0
  139. data/lib/lucky_sneaks/unidecoder_data/xae.yml +257 -0
  140. data/lib/lucky_sneaks/unidecoder_data/xaf.yml +257 -0
  141. data/lib/lucky_sneaks/unidecoder_data/xb0.yml +257 -0
  142. data/lib/lucky_sneaks/unidecoder_data/xb1.yml +257 -0
  143. data/lib/lucky_sneaks/unidecoder_data/xb2.yml +257 -0
  144. data/lib/lucky_sneaks/unidecoder_data/xb3.yml +257 -0
  145. data/lib/lucky_sneaks/unidecoder_data/xb4.yml +257 -0
  146. data/lib/lucky_sneaks/unidecoder_data/xb5.yml +257 -0
  147. data/lib/lucky_sneaks/unidecoder_data/xb6.yml +257 -0
  148. data/lib/lucky_sneaks/unidecoder_data/xb7.yml +257 -0
  149. data/lib/lucky_sneaks/unidecoder_data/xb8.yml +257 -0
  150. data/lib/lucky_sneaks/unidecoder_data/xb9.yml +257 -0
  151. data/lib/lucky_sneaks/unidecoder_data/xba.yml +257 -0
  152. data/lib/lucky_sneaks/unidecoder_data/xbb.yml +257 -0
  153. data/lib/lucky_sneaks/unidecoder_data/xbc.yml +257 -0
  154. data/lib/lucky_sneaks/unidecoder_data/xbd.yml +257 -0
  155. data/lib/lucky_sneaks/unidecoder_data/xbe.yml +257 -0
  156. data/lib/lucky_sneaks/unidecoder_data/xbf.yml +257 -0
  157. data/lib/lucky_sneaks/unidecoder_data/xc0.yml +257 -0
  158. data/lib/lucky_sneaks/unidecoder_data/xc1.yml +257 -0
  159. data/lib/lucky_sneaks/unidecoder_data/xc2.yml +257 -0
  160. data/lib/lucky_sneaks/unidecoder_data/xc3.yml +257 -0
  161. data/lib/lucky_sneaks/unidecoder_data/xc4.yml +257 -0
  162. data/lib/lucky_sneaks/unidecoder_data/xc5.yml +257 -0
  163. data/lib/lucky_sneaks/unidecoder_data/xc6.yml +257 -0
  164. data/lib/lucky_sneaks/unidecoder_data/xc7.yml +257 -0
  165. data/lib/lucky_sneaks/unidecoder_data/xc8.yml +257 -0
  166. data/lib/lucky_sneaks/unidecoder_data/xc9.yml +257 -0
  167. data/lib/lucky_sneaks/unidecoder_data/xca.yml +257 -0
  168. data/lib/lucky_sneaks/unidecoder_data/xcb.yml +257 -0
  169. data/lib/lucky_sneaks/unidecoder_data/xcc.yml +257 -0
  170. data/lib/lucky_sneaks/unidecoder_data/xcd.yml +257 -0
  171. data/lib/lucky_sneaks/unidecoder_data/xce.yml +257 -0
  172. data/lib/lucky_sneaks/unidecoder_data/xcf.yml +257 -0
  173. data/lib/lucky_sneaks/unidecoder_data/xd0.yml +257 -0
  174. data/lib/lucky_sneaks/unidecoder_data/xd1.yml +257 -0
  175. data/lib/lucky_sneaks/unidecoder_data/xd2.yml +257 -0
  176. data/lib/lucky_sneaks/unidecoder_data/xd3.yml +257 -0
  177. data/lib/lucky_sneaks/unidecoder_data/xd4.yml +257 -0
  178. data/lib/lucky_sneaks/unidecoder_data/xd5.yml +257 -0
  179. data/lib/lucky_sneaks/unidecoder_data/xd6.yml +257 -0
  180. data/lib/lucky_sneaks/unidecoder_data/xd7.yml +256 -0
  181. data/lib/lucky_sneaks/unidecoder_data/xf9.yml +257 -0
  182. data/lib/lucky_sneaks/unidecoder_data/xfa.yml +256 -0
  183. data/lib/lucky_sneaks/unidecoder_data/xfb.yml +257 -0
  184. data/lib/lucky_sneaks/unidecoder_data/xfc.yml +257 -0
  185. data/lib/lucky_sneaks/unidecoder_data/xfd.yml +256 -0
  186. data/lib/lucky_sneaks/unidecoder_data/xfe.yml +257 -0
  187. data/lib/lucky_sneaks/unidecoder_data/xff.yml +257 -0
  188. data/stringex.gemspec +208 -0
  189. data/test/acts_as_url_test.rb +140 -0
  190. data/test/string_extensions_test.rb +138 -0
  191. data/test/unidecoder_test.rb +68 -0
  192. metadata +245 -0
@@ -0,0 +1,140 @@
1
+ require 'test/unit'
2
+
3
+ begin
4
+ require File.dirname(__FILE__) + '/../../../config/environment'
5
+ rescue LoadError
6
+ require 'rubygems'
7
+ gem 'activerecord'
8
+ require 'active_record'
9
+
10
+ RAILS_ROOT = File.dirname(__FILE__)
11
+ end
12
+
13
+ require File.join(File.dirname(__FILE__), '../init')
14
+
15
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => "acts_as_url.sqlite3")
16
+
17
+ ActiveRecord::Migration.verbose = false
18
+ ActiveRecord::Schema.define(:version => 1) do
19
+ create_table :documents, :force => true do |t|
20
+ t.string :title, :url, :other
21
+ end
22
+
23
+ create_table :mocuments, :force => true do |t|
24
+ t.string :title, :url, :other
25
+ end
26
+
27
+ create_table :permuments, :force => true do |t|
28
+ t.string :title, :permalink, :other
29
+ end
30
+
31
+ create_table :procuments, :force => true do |t|
32
+ t.string :title, :url, :other
33
+ end
34
+ end
35
+ ActiveRecord::Migration.verbose = true
36
+
37
+ class Document < ActiveRecord::Base
38
+ acts_as_url :title
39
+ end
40
+
41
+ class Mocument < ActiveRecord::Base
42
+ acts_as_url :title, :scope => :other, :sync_url => true
43
+ end
44
+
45
+ class Permument < ActiveRecord::Base
46
+ acts_as_url :title, :url_attribute => :permalink
47
+ end
48
+
49
+ class Procument < ActiveRecord::Base
50
+ acts_as_url :non_attribute_method
51
+
52
+ def non_attribute_method
53
+ "#{title} got massaged"
54
+ end
55
+ end
56
+
57
+ class ActsAsUrlTest < Test::Unit::TestCase
58
+ def test_should_create_url
59
+ @doc = Document.create(:title => "Let's Make a Test Title, <em>Okay</em>?")
60
+ assert_equal "lets-make-a-test-title-okay", @doc.url
61
+ end
62
+
63
+ def test_should_create_unique_url
64
+ @doc = Document.create!(:title => "Unique")
65
+ @other_doc = Document.create!(:title => "Unique")
66
+ assert_equal "unique-1", @other_doc.url
67
+ end
68
+
69
+ def test_should_not_succ_on_repeated_saves
70
+ @doc = Document.new(:title => "Continuous or Constant")
71
+ 5.times do
72
+ @doc.save!
73
+ assert_equal "continuous-or-constant", @doc.url
74
+ end
75
+ end
76
+
77
+ def test_should_scope_uniqueness
78
+ @moc = Mocument.create!(:title => "Mocumentary", :other => "I dunno why but I don't care if I'm unique")
79
+ @other_moc = Mocument.create!(:title => "Mocumentary")
80
+ assert_equal @moc.url, @other_moc.url
81
+ end
82
+
83
+ def test_should_still_create_unique_if_in_same_scope
84
+ @moc = Mocument.create!(:title => "Mocumentary", :other => "Suddenly, I care if I'm unique")
85
+ @other_moc = Mocument.create!(:title => "Mocumentary", :other => "Suddenly, I care if I'm unique")
86
+ assert_not_equal @moc.url, @other_moc.url
87
+ end
88
+
89
+ def test_should_use_alternate_field_name
90
+ @perm = Permument.create!(:title => "Anything at This Point")
91
+ assert_equal "anything-at-this-point", @perm.permalink
92
+ end
93
+
94
+ def test_should_not_update_url_by_default
95
+ @doc = Document.create!(:title => "Stable as Stone")
96
+ @original_url = @doc.url
97
+ @doc.update_attributes :title => "New Unstable Madness"
98
+ assert_equal @original_url, @doc.url
99
+ end
100
+
101
+ def test_should_update_url_if_asked
102
+ @moc = Mocument.create!(:title => "Original")
103
+ @original_url = @moc.url
104
+ @moc.update_attributes :title => "New and Improved"
105
+ assert_not_equal @original_url, @moc.url
106
+ end
107
+
108
+ def test_should_mass_initialize_urls
109
+ @doc_1 = Document.create!(:title => "Initial")
110
+ @doc_2 = Document.create!(:title => "Subsequent")
111
+ @doc_1.update_attribute :url, nil
112
+ @doc_2.update_attribute :url, nil
113
+ assert_nil @doc_1.url
114
+ assert_nil @doc_2.url
115
+ Document.initialize_urls
116
+ @doc_1.reload
117
+ @doc_2.reload
118
+ assert_equal "initial", @doc_1.url
119
+ assert_equal "subsequent", @doc_2.url
120
+ end
121
+
122
+ def test_should_mass_initialize_urls_with_custom_url_attribute
123
+ @doc_1 = Permument.create!(:title => "Initial")
124
+ @doc_2 = Permument.create!(:title => "Subsequent")
125
+ @doc_1.update_attribute :permalink, nil
126
+ @doc_2.update_attribute :permalink, nil
127
+ assert_nil @doc_1.permalink
128
+ assert_nil @doc_2.permalink
129
+ Permument.initialize_urls
130
+ @doc_1.reload
131
+ @doc_2.reload
132
+ assert_equal "initial", @doc_1.permalink
133
+ assert_equal "subsequent", @doc_2.permalink
134
+ end
135
+
136
+ def test_should_utilize_block_if_given
137
+ @doc = Procument.create!(:title => "Title String")
138
+ assert_equal "title-string-got-massaged", @doc.url
139
+ end
140
+ end
@@ -0,0 +1,138 @@
1
+ require "test/unit"
2
+
3
+ require File.join(File.dirname(__FILE__), "../init")
4
+
5
+ class StringExtensionsTest < Test::Unit::TestCase
6
+ def test_to_html
7
+ require "rubygems"
8
+ require "RedCloth"
9
+ {
10
+ "h1. A Solution" => "<h1>A Solution</h1>",
11
+ "I hated wrapping textilize around a string.\n\nIt always felt dirty." =>
12
+ "<p>I hated wrapping textilize around a string.</p>\n<p>It always felt dirty.</p>",
13
+ "I think _this_ is awesome" => "<p>I think <em>this</em> is awesome</p>",
14
+ "Um... _*really*_, man" => "<p>Um&#8230; <em><strong>really</strong></em>, man</p>"
15
+ }.each do |plain, html|
16
+ assert_equal html, plain.to_html
17
+ end
18
+ rescue MissingSourceFile
19
+ puts "\n>> Could not load RedCloth. String#to_html was not tested.\n>> Please gem install RedCloth if you'd like to use this functionality."
20
+ end
21
+
22
+ def test_to_html_lite
23
+ require "rubygems"
24
+ require "RedCloth"
25
+ {
26
+ "I have no pee on me" => "I have no pee on me",
27
+ "But I _do_ get Textile!" => "But I <em>do</em> get Textile!"
28
+ }.each do |plain, html|
29
+ assert_equal html, plain.to_html(:lite)
30
+ end
31
+ rescue MissingSourceFile
32
+ puts "\n>> Could not load RedCloth. String#to_html (with :lite argument) was not tested.\n>> Please gem install RedCloth if you'd like to use this functionality."
33
+ end
34
+
35
+ def test_to_url
36
+ {
37
+ "<p>This has 100% too much <em>formatting</em></p>" =>
38
+ "this-has-100-percent-too-much-formatting",
39
+ "Tea &amp; crumpets &amp; <strong>cr&ecirc;pes</strong> for me!" =>
40
+ "tea-and-crumpets-and-crepes-for-me",
41
+ "The Suspense... Is... Killing Me" =>
42
+ "the-suspense-dot-dot-dot-is-dot-dot-dot-killing-me",
43
+ "How to use attr_accessible and attr_protected" =>
44
+ "how-to-use-attr-accessible-and-attr-protected",
45
+ "I'm just making sure there's nothing wrong with things!" =>
46
+ "im-just-making-sure-theres-nothing-wrong-with-things"
47
+ }.each do |html, plain|
48
+ assert_equal plain, html.to_url
49
+ end
50
+ end
51
+
52
+ def test_remove_formatting
53
+ {
54
+ "<p>This has 100% too much <em>formatting</em></p>" =>
55
+ "This has 100 percent too much formatting",
56
+ "Tea &amp; crumpets &amp; <strong>cr&ecirc;pes</strong> for me!" =>
57
+ "Tea and crumpets and crepes for me"
58
+ }.each do |html, plain|
59
+ assert_equal plain, html.remove_formatting
60
+ end
61
+ end
62
+
63
+ def test_strip_html_tags
64
+ {
65
+ "<h1><em>This</em> is good but <strong>that</strong> is better</h1>" =>
66
+ "This is good but that is better",
67
+ "<p>This is invalid XHTML but valid HTML, right?" =>
68
+ "This is invalid XHTML but valid HTML, right?",
69
+ "<p class='foo'>Everything goes!</p>" => "Everything goes!",
70
+ "<ol>This is completely invalid and just plain wrong</p>" =>
71
+ "This is completely invalid and just plain wrong"
72
+ }.each do |html, plain|
73
+ assert_equal plain, html.strip_html_tags
74
+ end
75
+ end
76
+
77
+ def test_convert_accented_entities
78
+ {
79
+ "&aring;" => "a",
80
+ "&egrave;" => "e",
81
+ "&icirc;" => "i",
82
+ "&Oslash;" => "O",
83
+ "&uuml;" => "u",
84
+ "&Ntilde;" => "N",
85
+ "&ccedil;" => "c"
86
+ }.each do |entitied, plain|
87
+ assert_equal plain, entitied.convert_accented_entities
88
+ end
89
+ end
90
+
91
+ def test_convert_misc_entities
92
+ {
93
+ "America&#8482;" => "America(tm)",
94
+ "Tea &amp; Sympathy" => "Tea and Sympathy",
95
+ "To be continued&#8230;" => "To be continued...",
96
+ "Foo&nbsp;Bar" => "Foo Bar",
97
+ "100&#163;" => "100 pound",
98
+ "&frac12; a dollar" => "half a dollar",
99
+ "35&deg;" => "35 degrees"
100
+ }.each do |entitied, plain|
101
+ assert_equal plain, entitied.convert_misc_entities
102
+ end
103
+ end
104
+
105
+ def test_convert_misc_characters
106
+ {
107
+ "Foo & bar make foobar" => "Foo and bar make foobar",
108
+ "Breakdown #9" => "Breakdown number 9",
109
+ "foo@bar.com" => "foo at bar dot com",
110
+ "100% of yr love" => "100 percent of yr love"
111
+ }.each do |misc, plain|
112
+ assert_equal plain, misc.convert_misc_characters
113
+ end
114
+ end
115
+
116
+ def test_replace_whitespace
117
+ {
118
+ "this has too much space" => "this has too much space",
119
+ "\t\tThis is merely formatted with superfluous whitespace\n" =>
120
+ " This is merely formatted with superfluous whitespace "
121
+ }.each do |whitespaced, plain|
122
+ assert_equal plain, whitespaced.replace_whitespace
123
+ end
124
+
125
+ assert_equal "now-with-more-hyphens", "now with more hyphens".replace_whitespace("-")
126
+ end
127
+
128
+ def test_collapse
129
+ {
130
+ "too much space" => "too much space",
131
+ " at the beginning" => "at the beginning"
132
+ }.each do |uncollapsed, plain|
133
+ assert_equal plain, uncollapsed.collapse
134
+ end
135
+
136
+ assert_equal "now-with-hyphens", "----now---------with-hyphens--------".collapse("-")
137
+ end
138
+ end
@@ -0,0 +1,68 @@
1
+ require "test/unit"
2
+
3
+ require File.join(File.dirname(__FILE__), "../init")
4
+
5
+ class UnidecoderTest < Test::Unit::TestCase
6
+ # Silly phrases courtesy of Frank da Cruz
7
+ # http://www.columbia.edu/kermit/utf8.html
8
+ DONT_CONVERT = [
9
+ "Vitrum edere possum; mihi non nocet.", # Latin
10
+ "Je puis mangier del voirre. Ne me nuit.", # Old French
11
+ "Kristala jan dezaket, ez dit minik ematen.", # Basque
12
+ "Kaya kong kumain nang bubog at hindi ako masaktan.", # Tagalog
13
+ "Ich kann Glas essen, ohne mir weh zu tun.", # German
14
+ "I can eat glass and it doesn't hurt me.", # English
15
+ ]
16
+ CONVERT_PAIRS = {
17
+ "Je peux manger du verre, ça ne me fait pas de mal." => # French
18
+ "Je peux manger du verre, ca ne me fait pas de mal.",
19
+ "Pot să mănânc sticlă și ea nu mă rănește." => # Romanian
20
+ "Pot sa mananc sticla si ea nu ma raneste.",
21
+ "Ég get etið gler án þess að meiða mig." => # Icelandic
22
+ "Eg get etid gler an thess ad meida mig.",
23
+ "Unë mund të ha qelq dhe nuk më gjen gjë." => # Albanian
24
+ "Une mund te ha qelq dhe nuk me gjen gje.",
25
+ "Mogę jeść szkło i mi nie szkodzi." => # Polish
26
+ "Moge jesc szklo i mi nie szkodzi.",
27
+ "Я могу есть стекло, оно мне не вредит." => # Russian
28
+ "Ia moghu iest' stieklo, ono mnie nie vriedit.",
29
+ "Мога да ям стъкло, то не ми вреди." => # Bulgarian
30
+ "Mogha da iam stklo, to nie mi vriedi.",
31
+ "ᛁᚳ᛫ᛗᚨᚷ᛫ᚷᛚᚨᛋ᛫ᛖᚩᛏᚪᚾ᛫ᚩᚾᛞ᛫ᚻᛁᛏ᛫ᚾᛖ᛫ᚻᛖᚪᚱᛗᛁᚪᚧ᛫ᛗᛖ᛬" => # Anglo-Saxon
32
+ "ic.mag.glas.eotacn.ond.hit.ne.heacrmiacth.me:",
33
+ "ὕαλον ϕαγεῖν δύναμαι· τοῦτο οὔ με βλάπτει" => # Classical Greek
34
+ "ualon phagein dunamai; touto ou me blaptei",
35
+ "मैं काँच खा सकता हूँ और मुझे उससे कोई चोट नहीं पहुंचती" => # Hindi
36
+ "maiN kaaNc khaa sktaa huuN aur mujhe usse koii cott nhiiN phuNctii",
37
+ "من می توانم بدونِ احساس درد شيشه بخورم" => # Persian
38
+ "mn my twnm bdwni Hss drd shyshh bkhwrm",
39
+ "أنا قادر على أكل الزجاج و هذا لا يؤلمن" => # Arabic
40
+ "'n qdr `l~ 'kl lzjj w hdh l yw'lmn",
41
+ "אני יכול לאכול זכוכית וזה לא מזיק לי" => # Hebrew
42
+ "ny ykvl lkvl zkvkyt vzh l mzyq ly",
43
+ "ฉันกินกระจกได้ แต่มันไม่ทำให้ฉันเจ็บ" => # Thai
44
+ "chankinkracchkaid aetmanaimthamaihchanecchb",
45
+ "我能吞下玻璃而不伤身体。" => # Chinese
46
+ "Wo Neng Tun Xia Bo Li Er Bu Shang Shen Ti . ",
47
+ "私はガラスを食べられます。それは私を傷つけません。" => # Japanese
48
+ "Si hagarasuwoShi beraremasu. sorehaSi woShang tukemasen. ",
49
+ }
50
+
51
+ def test_unicode_decode
52
+ DONT_CONVERT.each do |ascii|
53
+ assert_equal ascii, LuckySneaks::Unidecoder::decode(ascii)
54
+ end
55
+ CONVERT_PAIRS.each do |unicode, ascii|
56
+ assert_equal ascii, LuckySneaks::Unidecoder::decode(unicode)
57
+ end
58
+ end
59
+
60
+ def test_to_ascii
61
+ DONT_CONVERT.each do |ascii|
62
+ assert_equal ascii, ascii.to_ascii
63
+ end
64
+ CONVERT_PAIRS.each do |unicode, ascii|
65
+ assert_equal ascii, unicode.to_ascii
66
+ end
67
+ end
68
+ end
metadata ADDED
@@ -0,0 +1,245 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rsl-stringex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Russell Norris
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-10-04 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: "Some [hopefully] useful extensions to Ruby\xE2\x80\x99s String class. Stringex is made up of three libraries: ActsAsUrl [permalink solution with better character translation], Unidecoder [Unicode to Ascii transliteration], and StringExtensions [miscellaneous helper methods for the String class]."
17
+ email: rsl@luckysneaks.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - init.rb
26
+ - MIT-LICENSE
27
+ - Rakefile
28
+ - README.rdoc
29
+ - stringex.gemspec
30
+ - lib/lucky_sneaks/acts_as_url.rb
31
+ - lib/lucky_sneaks/string_extensions.rb
32
+ - lib/lucky_sneaks/unidecoder.rb
33
+ - lib/lucky_sneaks/unidecoder_data/x00.yml
34
+ - lib/lucky_sneaks/unidecoder_data/x01.yml
35
+ - lib/lucky_sneaks/unidecoder_data/x02.yml
36
+ - lib/lucky_sneaks/unidecoder_data/x03.yml
37
+ - lib/lucky_sneaks/unidecoder_data/x04.yml
38
+ - lib/lucky_sneaks/unidecoder_data/x05.yml
39
+ - lib/lucky_sneaks/unidecoder_data/x06.yml
40
+ - lib/lucky_sneaks/unidecoder_data/x07.yml
41
+ - lib/lucky_sneaks/unidecoder_data/x09.yml
42
+ - lib/lucky_sneaks/unidecoder_data/x0a.yml
43
+ - lib/lucky_sneaks/unidecoder_data/x0b.yml
44
+ - lib/lucky_sneaks/unidecoder_data/x0c.yml
45
+ - lib/lucky_sneaks/unidecoder_data/x0d.yml
46
+ - lib/lucky_sneaks/unidecoder_data/x0e.yml
47
+ - lib/lucky_sneaks/unidecoder_data/x0f.yml
48
+ - lib/lucky_sneaks/unidecoder_data/x10.yml
49
+ - lib/lucky_sneaks/unidecoder_data/x11.yml
50
+ - lib/lucky_sneaks/unidecoder_data/x12.yml
51
+ - lib/lucky_sneaks/unidecoder_data/x13.yml
52
+ - lib/lucky_sneaks/unidecoder_data/x14.yml
53
+ - lib/lucky_sneaks/unidecoder_data/x15.yml
54
+ - lib/lucky_sneaks/unidecoder_data/x16.yml
55
+ - lib/lucky_sneaks/unidecoder_data/x17.yml
56
+ - lib/lucky_sneaks/unidecoder_data/x18.yml
57
+ - lib/lucky_sneaks/unidecoder_data/x1e.yml
58
+ - lib/lucky_sneaks/unidecoder_data/x1f.yml
59
+ - lib/lucky_sneaks/unidecoder_data/x20.yml
60
+ - lib/lucky_sneaks/unidecoder_data/x21.yml
61
+ - lib/lucky_sneaks/unidecoder_data/x22.yml
62
+ - lib/lucky_sneaks/unidecoder_data/x23.yml
63
+ - lib/lucky_sneaks/unidecoder_data/x24.yml
64
+ - lib/lucky_sneaks/unidecoder_data/x25.yml
65
+ - lib/lucky_sneaks/unidecoder_data/x26.yml
66
+ - lib/lucky_sneaks/unidecoder_data/x27.yml
67
+ - lib/lucky_sneaks/unidecoder_data/x28.yml
68
+ - lib/lucky_sneaks/unidecoder_data/x2e.yml
69
+ - lib/lucky_sneaks/unidecoder_data/x2f.yml
70
+ - lib/lucky_sneaks/unidecoder_data/x30.yml
71
+ - lib/lucky_sneaks/unidecoder_data/x31.yml
72
+ - lib/lucky_sneaks/unidecoder_data/x32.yml
73
+ - lib/lucky_sneaks/unidecoder_data/x33.yml
74
+ - lib/lucky_sneaks/unidecoder_data/x4d.yml
75
+ - lib/lucky_sneaks/unidecoder_data/x4e.yml
76
+ - lib/lucky_sneaks/unidecoder_data/x4f.yml
77
+ - lib/lucky_sneaks/unidecoder_data/x50.yml
78
+ - lib/lucky_sneaks/unidecoder_data/x51.yml
79
+ - lib/lucky_sneaks/unidecoder_data/x52.yml
80
+ - lib/lucky_sneaks/unidecoder_data/x53.yml
81
+ - lib/lucky_sneaks/unidecoder_data/x54.yml
82
+ - lib/lucky_sneaks/unidecoder_data/x55.yml
83
+ - lib/lucky_sneaks/unidecoder_data/x56.yml
84
+ - lib/lucky_sneaks/unidecoder_data/x57.yml
85
+ - lib/lucky_sneaks/unidecoder_data/x58.yml
86
+ - lib/lucky_sneaks/unidecoder_data/x59.yml
87
+ - lib/lucky_sneaks/unidecoder_data/x5a.yml
88
+ - lib/lucky_sneaks/unidecoder_data/x5b.yml
89
+ - lib/lucky_sneaks/unidecoder_data/x5c.yml
90
+ - lib/lucky_sneaks/unidecoder_data/x5d.yml
91
+ - lib/lucky_sneaks/unidecoder_data/x5e.yml
92
+ - lib/lucky_sneaks/unidecoder_data/x5f.yml
93
+ - lib/lucky_sneaks/unidecoder_data/x60.yml
94
+ - lib/lucky_sneaks/unidecoder_data/x61.yml
95
+ - lib/lucky_sneaks/unidecoder_data/x62.yml
96
+ - lib/lucky_sneaks/unidecoder_data/x63.yml
97
+ - lib/lucky_sneaks/unidecoder_data/x64.yml
98
+ - lib/lucky_sneaks/unidecoder_data/x65.yml
99
+ - lib/lucky_sneaks/unidecoder_data/x66.yml
100
+ - lib/lucky_sneaks/unidecoder_data/x67.yml
101
+ - lib/lucky_sneaks/unidecoder_data/x68.yml
102
+ - lib/lucky_sneaks/unidecoder_data/x69.yml
103
+ - lib/lucky_sneaks/unidecoder_data/x6a.yml
104
+ - lib/lucky_sneaks/unidecoder_data/x6b.yml
105
+ - lib/lucky_sneaks/unidecoder_data/x6c.yml
106
+ - lib/lucky_sneaks/unidecoder_data/x6d.yml
107
+ - lib/lucky_sneaks/unidecoder_data/x6e.yml
108
+ - lib/lucky_sneaks/unidecoder_data/x6f.yml
109
+ - lib/lucky_sneaks/unidecoder_data/x70.yml
110
+ - lib/lucky_sneaks/unidecoder_data/x71.yml
111
+ - lib/lucky_sneaks/unidecoder_data/x72.yml
112
+ - lib/lucky_sneaks/unidecoder_data/x73.yml
113
+ - lib/lucky_sneaks/unidecoder_data/x74.yml
114
+ - lib/lucky_sneaks/unidecoder_data/x75.yml
115
+ - lib/lucky_sneaks/unidecoder_data/x76.yml
116
+ - lib/lucky_sneaks/unidecoder_data/x77.yml
117
+ - lib/lucky_sneaks/unidecoder_data/x78.yml
118
+ - lib/lucky_sneaks/unidecoder_data/x79.yml
119
+ - lib/lucky_sneaks/unidecoder_data/x7a.yml
120
+ - lib/lucky_sneaks/unidecoder_data/x7b.yml
121
+ - lib/lucky_sneaks/unidecoder_data/x7c.yml
122
+ - lib/lucky_sneaks/unidecoder_data/x7d.yml
123
+ - lib/lucky_sneaks/unidecoder_data/x7e.yml
124
+ - lib/lucky_sneaks/unidecoder_data/x7f.yml
125
+ - lib/lucky_sneaks/unidecoder_data/x80.yml
126
+ - lib/lucky_sneaks/unidecoder_data/x81.yml
127
+ - lib/lucky_sneaks/unidecoder_data/x82.yml
128
+ - lib/lucky_sneaks/unidecoder_data/x83.yml
129
+ - lib/lucky_sneaks/unidecoder_data/x84.yml
130
+ - lib/lucky_sneaks/unidecoder_data/x85.yml
131
+ - lib/lucky_sneaks/unidecoder_data/x86.yml
132
+ - lib/lucky_sneaks/unidecoder_data/x87.yml
133
+ - lib/lucky_sneaks/unidecoder_data/x88.yml
134
+ - lib/lucky_sneaks/unidecoder_data/x89.yml
135
+ - lib/lucky_sneaks/unidecoder_data/x8a.yml
136
+ - lib/lucky_sneaks/unidecoder_data/x8b.yml
137
+ - lib/lucky_sneaks/unidecoder_data/x8c.yml
138
+ - lib/lucky_sneaks/unidecoder_data/x8d.yml
139
+ - lib/lucky_sneaks/unidecoder_data/x8e.yml
140
+ - lib/lucky_sneaks/unidecoder_data/x8f.yml
141
+ - lib/lucky_sneaks/unidecoder_data/x90.yml
142
+ - lib/lucky_sneaks/unidecoder_data/x91.yml
143
+ - lib/lucky_sneaks/unidecoder_data/x92.yml
144
+ - lib/lucky_sneaks/unidecoder_data/x93.yml
145
+ - lib/lucky_sneaks/unidecoder_data/x94.yml
146
+ - lib/lucky_sneaks/unidecoder_data/x95.yml
147
+ - lib/lucky_sneaks/unidecoder_data/x96.yml
148
+ - lib/lucky_sneaks/unidecoder_data/x97.yml
149
+ - lib/lucky_sneaks/unidecoder_data/x98.yml
150
+ - lib/lucky_sneaks/unidecoder_data/x99.yml
151
+ - lib/lucky_sneaks/unidecoder_data/x9a.yml
152
+ - lib/lucky_sneaks/unidecoder_data/x9b.yml
153
+ - lib/lucky_sneaks/unidecoder_data/x9c.yml
154
+ - lib/lucky_sneaks/unidecoder_data/x9d.yml
155
+ - lib/lucky_sneaks/unidecoder_data/x9e.yml
156
+ - lib/lucky_sneaks/unidecoder_data/x9f.yml
157
+ - lib/lucky_sneaks/unidecoder_data/xa0.yml
158
+ - lib/lucky_sneaks/unidecoder_data/xa1.yml
159
+ - lib/lucky_sneaks/unidecoder_data/xa2.yml
160
+ - lib/lucky_sneaks/unidecoder_data/xa3.yml
161
+ - lib/lucky_sneaks/unidecoder_data/xa4.yml
162
+ - lib/lucky_sneaks/unidecoder_data/xac.yml
163
+ - lib/lucky_sneaks/unidecoder_data/xad.yml
164
+ - lib/lucky_sneaks/unidecoder_data/xae.yml
165
+ - lib/lucky_sneaks/unidecoder_data/xaf.yml
166
+ - lib/lucky_sneaks/unidecoder_data/xb0.yml
167
+ - lib/lucky_sneaks/unidecoder_data/xb1.yml
168
+ - lib/lucky_sneaks/unidecoder_data/xb2.yml
169
+ - lib/lucky_sneaks/unidecoder_data/xb3.yml
170
+ - lib/lucky_sneaks/unidecoder_data/xb4.yml
171
+ - lib/lucky_sneaks/unidecoder_data/xb5.yml
172
+ - lib/lucky_sneaks/unidecoder_data/xb6.yml
173
+ - lib/lucky_sneaks/unidecoder_data/xb7.yml
174
+ - lib/lucky_sneaks/unidecoder_data/xb8.yml
175
+ - lib/lucky_sneaks/unidecoder_data/xb9.yml
176
+ - lib/lucky_sneaks/unidecoder_data/xba.yml
177
+ - lib/lucky_sneaks/unidecoder_data/xbb.yml
178
+ - lib/lucky_sneaks/unidecoder_data/xbc.yml
179
+ - lib/lucky_sneaks/unidecoder_data/xbd.yml
180
+ - lib/lucky_sneaks/unidecoder_data/xbe.yml
181
+ - lib/lucky_sneaks/unidecoder_data/xbf.yml
182
+ - lib/lucky_sneaks/unidecoder_data/xc0.yml
183
+ - lib/lucky_sneaks/unidecoder_data/xc1.yml
184
+ - lib/lucky_sneaks/unidecoder_data/xc2.yml
185
+ - lib/lucky_sneaks/unidecoder_data/xc3.yml
186
+ - lib/lucky_sneaks/unidecoder_data/xc4.yml
187
+ - lib/lucky_sneaks/unidecoder_data/xc5.yml
188
+ - lib/lucky_sneaks/unidecoder_data/xc6.yml
189
+ - lib/lucky_sneaks/unidecoder_data/xc7.yml
190
+ - lib/lucky_sneaks/unidecoder_data/xc8.yml
191
+ - lib/lucky_sneaks/unidecoder_data/xc9.yml
192
+ - lib/lucky_sneaks/unidecoder_data/xca.yml
193
+ - lib/lucky_sneaks/unidecoder_data/xcb.yml
194
+ - lib/lucky_sneaks/unidecoder_data/xcc.yml
195
+ - lib/lucky_sneaks/unidecoder_data/xcd.yml
196
+ - lib/lucky_sneaks/unidecoder_data/xce.yml
197
+ - lib/lucky_sneaks/unidecoder_data/xcf.yml
198
+ - lib/lucky_sneaks/unidecoder_data/xd0.yml
199
+ - lib/lucky_sneaks/unidecoder_data/xd1.yml
200
+ - lib/lucky_sneaks/unidecoder_data/xd2.yml
201
+ - lib/lucky_sneaks/unidecoder_data/xd3.yml
202
+ - lib/lucky_sneaks/unidecoder_data/xd4.yml
203
+ - lib/lucky_sneaks/unidecoder_data/xd5.yml
204
+ - lib/lucky_sneaks/unidecoder_data/xd6.yml
205
+ - lib/lucky_sneaks/unidecoder_data/xd7.yml
206
+ - lib/lucky_sneaks/unidecoder_data/xf9.yml
207
+ - lib/lucky_sneaks/unidecoder_data/xfa.yml
208
+ - lib/lucky_sneaks/unidecoder_data/xfb.yml
209
+ - lib/lucky_sneaks/unidecoder_data/xfc.yml
210
+ - lib/lucky_sneaks/unidecoder_data/xfd.yml
211
+ - lib/lucky_sneaks/unidecoder_data/xfe.yml
212
+ - lib/lucky_sneaks/unidecoder_data/xff.yml
213
+ has_rdoc: true
214
+ homepage: http://github.com/rsl/stringex
215
+ post_install_message:
216
+ rdoc_options:
217
+ - --main
218
+ - README.rdoc
219
+ - --line-numbers
220
+ require_paths:
221
+ - lib
222
+ required_ruby_version: !ruby/object:Gem::Requirement
223
+ requirements:
224
+ - - ">="
225
+ - !ruby/object:Gem::Version
226
+ version: "0"
227
+ version:
228
+ required_rubygems_version: !ruby/object:Gem::Requirement
229
+ requirements:
230
+ - - ">="
231
+ - !ruby/object:Gem::Version
232
+ version: "0"
233
+ version:
234
+ requirements: []
235
+
236
+ rubyforge_project:
237
+ rubygems_version: 1.2.0
238
+ signing_key:
239
+ specification_version: 2
240
+ summary: "Some [hopefully] useful extensions to Ruby\xE2\x80\x99s String class"
241
+ test_files:
242
+ - test/acts_as_url.sqlite3
243
+ - test/acts_as_url_test.rb
244
+ - test/string_extensions_test.rb
245
+ - test/unidecoder_test.rb