motion-support 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +1 -1
- data/README.md +231 -2
- data/Rakefile +3 -3
- data/app/app_delegate.rb +0 -2
- data/examples/Inflector/.gitignore +16 -0
- data/examples/Inflector/Gemfile +5 -0
- data/examples/Inflector/Rakefile +13 -0
- data/examples/Inflector/app/app_delegate.rb +8 -0
- data/examples/Inflector/app/inflections.rb +5 -0
- data/examples/Inflector/app/inflector_view_controller.rb +120 -0
- data/examples/Inflector/app/words_view_controller.rb +101 -0
- data/examples/Inflector/resources/Default-568h@2x.png +0 -0
- data/examples/Inflector/spec/main_spec.rb +9 -0
- data/lib/motion-support/core_ext/array.rb +13 -0
- data/lib/motion-support/core_ext/class.rb +8 -0
- data/lib/motion-support/core_ext/hash.rb +16 -0
- data/lib/motion-support/core_ext/integer.rb +9 -0
- data/lib/motion-support/core_ext/module.rb +14 -0
- data/lib/motion-support/core_ext/numeric.rb +8 -0
- data/lib/motion-support/core_ext/object.rb +14 -0
- data/lib/motion-support/core_ext/range.rb +8 -0
- data/lib/motion-support/core_ext/string.rb +14 -0
- data/lib/motion-support/core_ext/time.rb +19 -0
- data/lib/motion-support/core_ext.rb +3 -0
- data/lib/motion-support/inflector.rb +12 -156
- data/lib/motion-support.rb +5 -5
- data/motion/_stdlib/cgi.rb +22 -0
- data/motion/_stdlib/date.rb +77 -0
- data/motion/_stdlib/time.rb +19 -0
- data/motion/core_ext/array/access.rb +28 -0
- data/motion/core_ext/array/conversions.rb +86 -0
- data/motion/core_ext/array/extract_options.rb +11 -0
- data/motion/core_ext/array/grouping.rb +99 -0
- data/motion/core_ext/array/prepend_and_append.rb +7 -0
- data/motion/core_ext/array/wrap.rb +45 -0
- data/{lib/motion-support → motion/core_ext}/array.rb +0 -4
- data/motion/core_ext/class/attribute.rb +119 -0
- data/motion/core_ext/class/attribute_accessors.rb +168 -0
- data/motion/core_ext/date/acts_like.rb +8 -0
- data/motion/core_ext/date/calculations.rb +117 -0
- data/motion/core_ext/date/conversions.rb +56 -0
- data/motion/core_ext/date_and_time/calculations.rb +232 -0
- data/motion/core_ext/enumerable.rb +90 -0
- data/motion/core_ext/hash/deep_merge.rb +27 -0
- data/motion/core_ext/hash/except.rb +15 -0
- data/motion/core_ext/hash/indifferent_access.rb +19 -0
- data/motion/core_ext/hash/keys.rb +138 -0
- data/motion/core_ext/hash/reverse_merge.rb +22 -0
- data/motion/core_ext/hash/slice.rb +40 -0
- data/motion/core_ext/integer/inflections.rb +27 -0
- data/motion/core_ext/integer/multiple.rb +10 -0
- data/motion/core_ext/integer/time.rb +41 -0
- data/{lib/motion-support → motion/core_ext}/metaclass.rb +0 -0
- data/motion/core_ext/module/aliasing.rb +69 -0
- data/motion/core_ext/module/anonymous.rb +19 -0
- data/motion/core_ext/module/attr_internal.rb +38 -0
- data/motion/core_ext/module/attribute_accessors.rb +64 -0
- data/motion/core_ext/module/delegation.rb +175 -0
- data/motion/core_ext/module/introspection.rb +60 -0
- data/motion/core_ext/module/reachable.rb +5 -0
- data/motion/core_ext/module/remove_method.rb +12 -0
- data/motion/core_ext/ns_dictionary.rb +11 -0
- data/motion/core_ext/numeric/bytes.rb +44 -0
- data/motion/core_ext/numeric/conversions.rb +7 -0
- data/motion/core_ext/numeric/time.rb +75 -0
- data/motion/core_ext/object/acts_like.rb +10 -0
- data/motion/core_ext/object/blank.rb +105 -0
- data/motion/core_ext/object/deep_dup.rb +44 -0
- data/motion/core_ext/object/duplicable.rb +83 -0
- data/motion/core_ext/object/instance_variables.rb +28 -0
- data/motion/core_ext/object/to_param.rb +58 -0
- data/motion/core_ext/object/to_query.rb +26 -0
- data/motion/core_ext/object/try.rb +78 -0
- data/motion/core_ext/range/include_range.rb +23 -0
- data/motion/core_ext/range/overlaps.rb +8 -0
- data/motion/core_ext/regexp.rb +5 -0
- data/motion/core_ext/string/access.rb +104 -0
- data/motion/core_ext/string/behavior.rb +6 -0
- data/motion/core_ext/string/exclude.rb +11 -0
- data/motion/core_ext/string/filters.rb +55 -0
- data/motion/core_ext/string/indent.rb +43 -0
- data/motion/core_ext/string/inflections.rb +195 -0
- data/motion/core_ext/string/starts_ends_with.rb +4 -0
- data/motion/core_ext/string/strip.rb +24 -0
- data/motion/core_ext/time/acts_like.rb +8 -0
- data/motion/core_ext/time/calculations.rb +215 -0
- data/motion/core_ext/time/conversions.rb +52 -0
- data/motion/duration.rb +104 -0
- data/motion/hash_with_indifferent_access.rb +251 -0
- data/motion/inflections.rb +67 -0
- data/motion/inflector/inflections.rb +203 -0
- data/motion/inflector/methods.rb +321 -0
- data/{lib/motion-support → motion}/logger.rb +0 -0
- data/{lib/motion-support → motion}/version.rb +1 -1
- data/motion-support.gemspec +2 -2
- data/spec/motion-support/_helpers/constantize_test_cases.rb +75 -0
- data/spec/motion-support/_helpers/inflector_test_cases.rb +313 -0
- data/spec/motion-support/core_ext/array/access_spec.rb +29 -0
- data/spec/motion-support/core_ext/array/conversion_spec.rb +60 -0
- data/spec/motion-support/core_ext/array/extract_options_spec.rb +15 -0
- data/spec/motion-support/core_ext/array/grouping_spec.rb +85 -0
- data/spec/motion-support/core_ext/array/prepend_and_append_spec.rb +25 -0
- data/spec/motion-support/core_ext/array/wrap_spec.rb +19 -0
- data/spec/motion-support/{array_spec.rb → core_ext/array_spec.rb} +0 -5
- data/spec/motion-support/core_ext/class/attribute_accessor_spec.rb +127 -0
- data/spec/motion-support/core_ext/class/attribute_spec.rb +92 -0
- data/spec/motion-support/core_ext/date/acts_like_spec.rb +11 -0
- data/spec/motion-support/core_ext/date/calculation_spec.rb +186 -0
- data/spec/motion-support/core_ext/date/conversion_spec.rb +18 -0
- data/spec/motion-support/core_ext/date_and_time/calculation_spec.rb +336 -0
- data/spec/motion-support/core_ext/enumerable_spec.rb +130 -0
- data/spec/motion-support/core_ext/hash/deep_merge_spec.rb +32 -0
- data/spec/motion-support/core_ext/hash/except_spec.rb +43 -0
- data/spec/motion-support/core_ext/hash/key_spec.rb +230 -0
- data/spec/motion-support/core_ext/hash/reverse_merge_spec.rb +26 -0
- data/spec/motion-support/core_ext/hash/slice_spec.rb +61 -0
- data/spec/motion-support/core_ext/integer/inflection_spec.rb +23 -0
- data/spec/motion-support/core_ext/integer/multiple_spec.rb +19 -0
- data/spec/motion-support/{metaclass_spec.rb → core_ext/metaclass_spec.rb} +0 -0
- data/spec/motion-support/core_ext/module/aliasing_spec.rb +143 -0
- data/spec/motion-support/core_ext/module/anonymous_spec.rb +29 -0
- data/spec/motion-support/core_ext/module/attr_internal_spec.rb +104 -0
- data/spec/motion-support/core_ext/module/attribute_accessor_spec.rb +86 -0
- data/spec/motion-support/core_ext/module/delegation_spec.rb +136 -0
- data/spec/motion-support/core_ext/module/introspection_spec.rb +70 -0
- data/spec/motion-support/core_ext/module/reachable_spec.rb +61 -0
- data/spec/motion-support/core_ext/module/remove_method_spec.rb +25 -0
- data/spec/motion-support/core_ext/numeric/bytes_spec.rb +43 -0
- data/spec/motion-support/core_ext/object/acts_like_spec.rb +21 -0
- data/spec/motion-support/core_ext/object/blank_spec.rb +54 -0
- data/spec/motion-support/core_ext/object/deep_dup_spec.rb +54 -0
- data/spec/motion-support/core_ext/object/duplicable_spec.rb +31 -0
- data/spec/motion-support/core_ext/object/instance_variable_spec.rb +19 -0
- data/spec/motion-support/core_ext/object/to_param_spec.rb +75 -0
- data/spec/motion-support/core_ext/object/to_query_spec.rb +37 -0
- data/spec/motion-support/core_ext/object/try_spec.rb +92 -0
- data/spec/motion-support/core_ext/range/include_range_spec.rb +31 -0
- data/spec/motion-support/core_ext/range/overlap_spec.rb +43 -0
- data/spec/motion-support/core_ext/regexp_spec.rb +7 -0
- data/spec/motion-support/core_ext/string/access_spec.rb +53 -0
- data/spec/motion-support/core_ext/string/behavior_spec.rb +7 -0
- data/spec/motion-support/core_ext/string/exclude_spec.rb +8 -0
- data/spec/motion-support/core_ext/string/filter_spec.rb +48 -0
- data/spec/motion-support/core_ext/string/indent_spec.rb +56 -0
- data/spec/motion-support/core_ext/string/inflection_spec.rb +142 -0
- data/spec/motion-support/core_ext/string/starts_end_with_spec.rb +14 -0
- data/spec/motion-support/core_ext/string/strip_spec.rb +34 -0
- data/spec/motion-support/core_ext/string_spec.rb +88 -0
- data/spec/motion-support/core_ext/time/acts_like_spec.rb +11 -0
- data/spec/motion-support/core_ext/time/calculation_spec.rb +201 -0
- data/spec/motion-support/core_ext/time/conversion_spec.rb +54 -0
- data/spec/motion-support/duration_spec.rb +107 -0
- data/spec/motion-support/hash_with_indifferent_access_spec.rb +605 -0
- data/spec/motion-support/inflector_spec.rb +474 -35
- data/spec/motion-support/ns_dictionary_spec.rb +29 -0
- metadata +212 -35
- data/lib/motion-support/cattr_accessor.rb +0 -19
- data/lib/motion-support/class_inheritable_accessor.rb +0 -23
- data/lib/motion-support/class_inheritable_array.rb +0 -29
- data/lib/motion-support/hash.rb +0 -31
- data/lib/motion-support/nilclass.rb +0 -5
- data/lib/motion-support/object.rb +0 -17
- data/lib/motion-support/string.rb +0 -71
- data/spec/motion-support/cattr_accessor_spec.rb +0 -49
- data/spec/motion-support/class_inheritable_accessor_spec.rb +0 -49
- data/spec/motion-support/class_inheritable_array_spec.rb +0 -61
- data/spec/motion-support/hash_spec.rb +0 -31
- data/spec/motion-support/nilclass_spec.rb +0 -5
- data/spec/motion-support/object_spec.rb +0 -43
- data/spec/motion-support/string_spec.rb +0 -145
@@ -0,0 +1,313 @@
|
|
1
|
+
module InflectorTestCases
|
2
|
+
SingularToPlural = {
|
3
|
+
"search" => "searches",
|
4
|
+
"switch" => "switches",
|
5
|
+
"fix" => "fixes",
|
6
|
+
"box" => "boxes",
|
7
|
+
"process" => "processes",
|
8
|
+
"address" => "addresses",
|
9
|
+
"case" => "cases",
|
10
|
+
"stack" => "stacks",
|
11
|
+
"wish" => "wishes",
|
12
|
+
"fish" => "fish",
|
13
|
+
"jeans" => "jeans",
|
14
|
+
"funky jeans" => "funky jeans",
|
15
|
+
"my money" => "my money",
|
16
|
+
|
17
|
+
"category" => "categories",
|
18
|
+
"query" => "queries",
|
19
|
+
"ability" => "abilities",
|
20
|
+
"agency" => "agencies",
|
21
|
+
"movie" => "movies",
|
22
|
+
|
23
|
+
"archive" => "archives",
|
24
|
+
|
25
|
+
"index" => "indices",
|
26
|
+
|
27
|
+
"wife" => "wives",
|
28
|
+
"safe" => "saves",
|
29
|
+
"half" => "halves",
|
30
|
+
|
31
|
+
"move" => "moves",
|
32
|
+
|
33
|
+
"salesperson" => "salespeople",
|
34
|
+
"person" => "people",
|
35
|
+
|
36
|
+
"spokesman" => "spokesmen",
|
37
|
+
"man" => "men",
|
38
|
+
"woman" => "women",
|
39
|
+
|
40
|
+
"basis" => "bases",
|
41
|
+
"diagnosis" => "diagnoses",
|
42
|
+
"diagnosis_a" => "diagnosis_as",
|
43
|
+
|
44
|
+
"datum" => "data",
|
45
|
+
"medium" => "media",
|
46
|
+
"stadium" => "stadia",
|
47
|
+
"analysis" => "analyses",
|
48
|
+
"my_analysis" => "my_analyses",
|
49
|
+
|
50
|
+
"node_child" => "node_children",
|
51
|
+
"child" => "children",
|
52
|
+
|
53
|
+
"experience" => "experiences",
|
54
|
+
"day" => "days",
|
55
|
+
|
56
|
+
"comment" => "comments",
|
57
|
+
"foobar" => "foobars",
|
58
|
+
"newsletter" => "newsletters",
|
59
|
+
|
60
|
+
"old_news" => "old_news",
|
61
|
+
"news" => "news",
|
62
|
+
|
63
|
+
"series" => "series",
|
64
|
+
"species" => "species",
|
65
|
+
|
66
|
+
"quiz" => "quizzes",
|
67
|
+
|
68
|
+
"perspective" => "perspectives",
|
69
|
+
|
70
|
+
"ox" => "oxen",
|
71
|
+
"photo" => "photos",
|
72
|
+
"buffalo" => "buffaloes",
|
73
|
+
"tomato" => "tomatoes",
|
74
|
+
"dwarf" => "dwarves",
|
75
|
+
"elf" => "elves",
|
76
|
+
"information" => "information",
|
77
|
+
"equipment" => "equipment",
|
78
|
+
"bus" => "buses",
|
79
|
+
"status" => "statuses",
|
80
|
+
"status_code" => "status_codes",
|
81
|
+
"mouse" => "mice",
|
82
|
+
|
83
|
+
"louse" => "lice",
|
84
|
+
"house" => "houses",
|
85
|
+
"octopus" => "octopi",
|
86
|
+
"virus" => "viri",
|
87
|
+
"alias" => "aliases",
|
88
|
+
"portfolio" => "portfolios",
|
89
|
+
|
90
|
+
"vertex" => "vertices",
|
91
|
+
"matrix" => "matrices",
|
92
|
+
"matrix_fu" => "matrix_fus",
|
93
|
+
|
94
|
+
"axis" => "axes",
|
95
|
+
"taxi" => "taxis", # prevents regression
|
96
|
+
"testis" => "testes",
|
97
|
+
"crisis" => "crises",
|
98
|
+
|
99
|
+
"rice" => "rice",
|
100
|
+
"shoe" => "shoes",
|
101
|
+
|
102
|
+
"horse" => "horses",
|
103
|
+
"prize" => "prizes",
|
104
|
+
"edge" => "edges",
|
105
|
+
|
106
|
+
"cow" => "kine",
|
107
|
+
"database" => "databases",
|
108
|
+
|
109
|
+
# regression tests against improper inflection regexes
|
110
|
+
"|ice" => "|ices",
|
111
|
+
"|ouse" => "|ouses",
|
112
|
+
"slice" => "slices",
|
113
|
+
"police" => "police"
|
114
|
+
}
|
115
|
+
|
116
|
+
CamelToUnderscore = {
|
117
|
+
"Product" => "product",
|
118
|
+
"SpecialGuest" => "special_guest",
|
119
|
+
"ApplicationController" => "application_controller",
|
120
|
+
"Area51Controller" => "area51_controller"
|
121
|
+
}
|
122
|
+
|
123
|
+
UnderscoreToLowerCamel = {
|
124
|
+
"product" => "product",
|
125
|
+
"special_guest" => "specialGuest",
|
126
|
+
"application_controller" => "applicationController",
|
127
|
+
"area51_controller" => "area51Controller"
|
128
|
+
}
|
129
|
+
|
130
|
+
SymbolToLowerCamel = {
|
131
|
+
:product => 'product',
|
132
|
+
:special_guest => 'specialGuest',
|
133
|
+
:application_controller => 'applicationController',
|
134
|
+
:area51_controller => 'area51Controller'
|
135
|
+
}
|
136
|
+
|
137
|
+
CamelToUnderscoreWithoutReverse = {
|
138
|
+
"HTMLTidy" => "html_tidy",
|
139
|
+
"HTMLTidyGenerator" => "html_tidy_generator",
|
140
|
+
"FreeBSD" => "free_bsd",
|
141
|
+
"HTML" => "html",
|
142
|
+
}
|
143
|
+
|
144
|
+
CamelWithModuleToUnderscoreWithSlash = {
|
145
|
+
"Admin::Product" => "admin/product",
|
146
|
+
"Users::Commission::Department" => "users/commission/department",
|
147
|
+
"UsersSection::CommissionDepartment" => "users_section/commission_department",
|
148
|
+
}
|
149
|
+
|
150
|
+
ClassNameToForeignKeyWithUnderscore = {
|
151
|
+
"Person" => "person_id",
|
152
|
+
"MyApplication::Billing::Account" => "account_id"
|
153
|
+
}
|
154
|
+
|
155
|
+
ClassNameToForeignKeyWithoutUnderscore = {
|
156
|
+
"Person" => "personid",
|
157
|
+
"MyApplication::Billing::Account" => "accountid"
|
158
|
+
}
|
159
|
+
|
160
|
+
ClassNameToTableName = {
|
161
|
+
"PrimarySpokesman" => "primary_spokesmen",
|
162
|
+
"NodeChild" => "node_children"
|
163
|
+
}
|
164
|
+
|
165
|
+
StringToParameterized = {
|
166
|
+
"Donald E. Knuth" => "donald-e-knuth",
|
167
|
+
"Random text with *(bad)* characters" => "random-text-with-bad-characters",
|
168
|
+
"Allow_Under_Scores" => "allow_under_scores",
|
169
|
+
"Trailing bad characters!@#" => "trailing-bad-characters",
|
170
|
+
"!@#Leading bad characters" => "leading-bad-characters",
|
171
|
+
"Squeeze separators" => "squeeze-separators",
|
172
|
+
"Test with + sign" => "test-with-sign",
|
173
|
+
"Test with malformed utf8 \251" => "test-with-malformed-utf8"
|
174
|
+
}
|
175
|
+
|
176
|
+
StringToParameterizeWithNoSeparator = {
|
177
|
+
"Donald E. Knuth" => "donaldeknuth",
|
178
|
+
"With-some-dashes" => "with-some-dashes",
|
179
|
+
"Random text with *(bad)* characters" => "randomtextwithbadcharacters",
|
180
|
+
"Trailing bad characters!@#" => "trailingbadcharacters",
|
181
|
+
"!@#Leading bad characters" => "leadingbadcharacters",
|
182
|
+
"Squeeze separators" => "squeezeseparators",
|
183
|
+
"Test with + sign" => "testwithsign",
|
184
|
+
"Test with malformed utf8 \251" => "testwithmalformedutf8"
|
185
|
+
}
|
186
|
+
|
187
|
+
StringToParameterizeWithUnderscore = {
|
188
|
+
"Donald E. Knuth" => "donald_e_knuth",
|
189
|
+
"Random text with *(bad)* characters" => "random_text_with_bad_characters",
|
190
|
+
"With-some-dashes" => "with-some-dashes",
|
191
|
+
"Retain_underscore" => "retain_underscore",
|
192
|
+
"Trailing bad characters!@#" => "trailing_bad_characters",
|
193
|
+
"!@#Leading bad characters" => "leading_bad_characters",
|
194
|
+
"Squeeze separators" => "squeeze_separators",
|
195
|
+
"Test with + sign" => "test_with_sign",
|
196
|
+
"Test with malformed utf8 \251" => "test_with_malformed_utf8"
|
197
|
+
}
|
198
|
+
|
199
|
+
StringToParameterizedAndNormalized = {
|
200
|
+
"Malmö" => "malmo",
|
201
|
+
"Garçons" => "garcons",
|
202
|
+
"Ops\331" => "opsu",
|
203
|
+
"Ærøskøbing" => "aeroskobing",
|
204
|
+
"Aßlar" => "asslar",
|
205
|
+
"Japanese: 日本語" => "japanese"
|
206
|
+
}
|
207
|
+
|
208
|
+
UnderscoreToHuman = {
|
209
|
+
"employee_salary" => "Employee salary",
|
210
|
+
"employee_id" => "Employee",
|
211
|
+
"underground" => "Underground"
|
212
|
+
}
|
213
|
+
|
214
|
+
MixtureToTitleCase = {
|
215
|
+
'active_record' => 'Active Record',
|
216
|
+
'ActiveRecord' => 'Active Record',
|
217
|
+
'action web service' => 'Action Web Service',
|
218
|
+
'Action Web Service' => 'Action Web Service',
|
219
|
+
'Action web service' => 'Action Web Service',
|
220
|
+
'actionwebservice' => 'Actionwebservice',
|
221
|
+
'Actionwebservice' => 'Actionwebservice',
|
222
|
+
"david's code" => "David's Code",
|
223
|
+
"David's code" => "David's Code",
|
224
|
+
"david's Code" => "David's Code",
|
225
|
+
"sgt. pepper's" => "Sgt. Pepper's",
|
226
|
+
"i've just seen a face" => "I've Just Seen A Face",
|
227
|
+
"maybe you'll be there" => "Maybe You'll Be There",
|
228
|
+
"¿por qué?" => '¿Por Qué?',
|
229
|
+
"Fred’s" => "Fred’s",
|
230
|
+
"Fred`s" => "Fred`s"
|
231
|
+
}
|
232
|
+
|
233
|
+
OrdinalNumbers = {
|
234
|
+
"-1" => "-1st",
|
235
|
+
"-2" => "-2nd",
|
236
|
+
"-3" => "-3rd",
|
237
|
+
"-4" => "-4th",
|
238
|
+
"-5" => "-5th",
|
239
|
+
"-6" => "-6th",
|
240
|
+
"-7" => "-7th",
|
241
|
+
"-8" => "-8th",
|
242
|
+
"-9" => "-9th",
|
243
|
+
"-10" => "-10th",
|
244
|
+
"-11" => "-11th",
|
245
|
+
"-12" => "-12th",
|
246
|
+
"-13" => "-13th",
|
247
|
+
"-14" => "-14th",
|
248
|
+
"-20" => "-20th",
|
249
|
+
"-21" => "-21st",
|
250
|
+
"-22" => "-22nd",
|
251
|
+
"-23" => "-23rd",
|
252
|
+
"-24" => "-24th",
|
253
|
+
"-100" => "-100th",
|
254
|
+
"-101" => "-101st",
|
255
|
+
"-102" => "-102nd",
|
256
|
+
"-103" => "-103rd",
|
257
|
+
"-104" => "-104th",
|
258
|
+
"-110" => "-110th",
|
259
|
+
"-111" => "-111th",
|
260
|
+
"-112" => "-112th",
|
261
|
+
"-113" => "-113th",
|
262
|
+
"-1000" => "-1000th",
|
263
|
+
"-1001" => "-1001st",
|
264
|
+
"0" => "0th",
|
265
|
+
"1" => "1st",
|
266
|
+
"2" => "2nd",
|
267
|
+
"3" => "3rd",
|
268
|
+
"4" => "4th",
|
269
|
+
"5" => "5th",
|
270
|
+
"6" => "6th",
|
271
|
+
"7" => "7th",
|
272
|
+
"8" => "8th",
|
273
|
+
"9" => "9th",
|
274
|
+
"10" => "10th",
|
275
|
+
"11" => "11th",
|
276
|
+
"12" => "12th",
|
277
|
+
"13" => "13th",
|
278
|
+
"14" => "14th",
|
279
|
+
"20" => "20th",
|
280
|
+
"21" => "21st",
|
281
|
+
"22" => "22nd",
|
282
|
+
"23" => "23rd",
|
283
|
+
"24" => "24th",
|
284
|
+
"100" => "100th",
|
285
|
+
"101" => "101st",
|
286
|
+
"102" => "102nd",
|
287
|
+
"103" => "103rd",
|
288
|
+
"104" => "104th",
|
289
|
+
"110" => "110th",
|
290
|
+
"111" => "111th",
|
291
|
+
"112" => "112th",
|
292
|
+
"113" => "113th",
|
293
|
+
"1000" => "1000th",
|
294
|
+
"1001" => "1001st"
|
295
|
+
}
|
296
|
+
|
297
|
+
UnderscoresToDashes = {
|
298
|
+
"street" => "street",
|
299
|
+
"street_address" => "street-address",
|
300
|
+
"person_street_address" => "person-street-address"
|
301
|
+
}
|
302
|
+
|
303
|
+
Irregularities = {
|
304
|
+
'person' => 'people',
|
305
|
+
'man' => 'men',
|
306
|
+
'child' => 'children',
|
307
|
+
'sex' => 'sexes',
|
308
|
+
'move' => 'moves',
|
309
|
+
'cow' => 'kine',
|
310
|
+
'zombie' => 'zombies',
|
311
|
+
'genus' => 'genera'
|
312
|
+
}
|
313
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
describe 'array access' do
|
2
|
+
describe "from" do
|
3
|
+
it "should return the tail of an array from position" do
|
4
|
+
['a', 'b', 'c', 'd'].from(0).should == ["a", "b", "c", "d"]
|
5
|
+
['a', 'b', 'c', 'd'].from(2).should == ["c", "d"]
|
6
|
+
['a', 'b', 'c', 'd'].from(10).should == []
|
7
|
+
[].from(0).should == []
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "to" do
|
12
|
+
it "should return the head of an array up to position" do
|
13
|
+
['a', 'b', 'c', 'd'].to(0).should == ["a"]
|
14
|
+
['a', 'b', 'c', 'd'].to(2).should == ["a", "b", "c"]
|
15
|
+
['a', 'b', 'c', 'd'].to(10).should == ["a", "b", "c", "d"]
|
16
|
+
[].to(0).should == []
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "second" do
|
21
|
+
it "should return the second element in an array" do
|
22
|
+
['a', 'b', 'c', 'd'].second.should == 'b'
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return nil if there is no second element" do
|
26
|
+
[].second.should == nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
describe 'array' do
|
2
|
+
describe "to_sentence" do
|
3
|
+
it "should convert plain array" do
|
4
|
+
[].to_sentence.should == ""
|
5
|
+
['one'].to_sentence.should == "one"
|
6
|
+
['one', 'two'].to_sentence.should == "one and two"
|
7
|
+
['one', 'two', 'three'].to_sentence.should == "one, two, and three"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should convert sentence with words connector" do
|
11
|
+
['one', 'two', 'three'].to_sentence(:words_connector => ' ').should == "one two, and three"
|
12
|
+
['one', 'two', 'three'].to_sentence(:words_connector => ' & ').should == "one & two, and three"
|
13
|
+
['one', 'two', 'three'].to_sentence(:words_connector => nil).should == "onetwo, and three"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should convert sentence with last word connector" do
|
17
|
+
['one', 'two', 'three'].to_sentence(:last_word_connector => ', and also ').should == "one, two, and also three"
|
18
|
+
['one', 'two', 'three'].to_sentence(:last_word_connector => nil).should == "one, twothree"
|
19
|
+
['one', 'two', 'three'].to_sentence(:last_word_connector => ' ').should == "one, two three"
|
20
|
+
['one', 'two', 'three'].to_sentence(:last_word_connector => ' and ').should == "one, two and three"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should convert two-element array" do
|
24
|
+
['one', 'two'].to_sentence.should == "one and two"
|
25
|
+
['one', 'two'].to_sentence(:two_words_connector => ' ').should == "one two"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should convert one-element array" do
|
29
|
+
['one'].to_sentence.should == "one"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should create new object" do
|
33
|
+
elements = ["one"]
|
34
|
+
elements.to_sentence.object_id.should.not == elements[0].object_id
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should convert non-string element" do
|
38
|
+
[1].to_sentence.should == '1'
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should not modify given hash" do
|
42
|
+
options = { words_connector: ' ' }
|
43
|
+
['one', 'two', 'three'].to_sentence(options).should == "one two, and three"
|
44
|
+
options.should == { words_connector: ' ' }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "to_s" do
|
49
|
+
it "should convert to database format" do
|
50
|
+
collection = [
|
51
|
+
Class.new { def id() 1 end }.new,
|
52
|
+
Class.new { def id() 2 end }.new,
|
53
|
+
Class.new { def id() 3 end }.new
|
54
|
+
]
|
55
|
+
|
56
|
+
[].to_s(:db).should == "null"
|
57
|
+
collection.to_s(:db).should == "1,2,3"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
describe 'array options' do
|
2
|
+
describe "extract_options!" do
|
3
|
+
it "should extract an options hash from an array" do
|
4
|
+
[1, 2, :a => :b].extract_options!.should == { :a => :b }
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should return an empty hash if the last element is not a hash" do
|
8
|
+
[1, 2].extract_options!.should == {}
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return an empty hash on an empty array" do
|
12
|
+
[].extract_options!.should == {}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
describe 'array grouping' do
|
2
|
+
describe "in_groups_of" do
|
3
|
+
it "should group array and fill rest with nil" do
|
4
|
+
%w(1 2 3 4 5 6 7 8 9 10).in_groups_of(3).should == [
|
5
|
+
["1", "2", "3"],
|
6
|
+
["4", "5", "6"],
|
7
|
+
["7", "8", "9"],
|
8
|
+
["10", nil, nil]
|
9
|
+
]
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should group array and fill with specified filler" do
|
13
|
+
%w(1 2 3 4 5).in_groups_of(2, 'empty').should == [
|
14
|
+
["1", "2"],
|
15
|
+
["3", "4"],
|
16
|
+
["5", "empty"]
|
17
|
+
]
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should not fill the last group if turned off" do
|
21
|
+
%w(1 2 3 4 5).in_groups_of(2, false).should == [
|
22
|
+
["1", "2"],
|
23
|
+
["3", "4"],
|
24
|
+
["5"]
|
25
|
+
]
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should yield each slice to a block if given" do
|
29
|
+
result = []
|
30
|
+
%w(1 2 3 4 5 6 7 8 9 10).in_groups_of(3) { |group| result << ['foo'] + group + ['bar'] }
|
31
|
+
result.should == [
|
32
|
+
["foo", "1", "2", "3", "bar"],
|
33
|
+
["foo", "4", "5", "6", "bar"],
|
34
|
+
["foo", "7", "8", "9", "bar"],
|
35
|
+
["foo", "10", nil, nil, "bar"]
|
36
|
+
]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "in_groups" do
|
41
|
+
it "should group array and fill the rest with nil" do
|
42
|
+
%w(1 2 3 4 5 6 7 8 9 10).in_groups(3).should == [
|
43
|
+
["1", "2", "3", "4"],
|
44
|
+
["5", "6", "7", nil],
|
45
|
+
["8", "9", "10", nil]
|
46
|
+
]
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should group array and fill the result with specified filler" do
|
50
|
+
%w(1 2 3 4 5 6 7 8 9 10).in_groups(3, 'empty').should == [
|
51
|
+
["1", "2", "3", "4"],
|
52
|
+
["5", "6", "7", "empty"],
|
53
|
+
["8", "9", "10", "empty"]
|
54
|
+
]
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should not fill the last group if turned off" do
|
58
|
+
%w(1 2 3 4 5 6 7).in_groups(3, false).should == [
|
59
|
+
["1", "2", "3"],
|
60
|
+
["4", "5"],
|
61
|
+
["6", "7"]
|
62
|
+
]
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should yield each slice to a block if given" do
|
66
|
+
result = []
|
67
|
+
%w(1 2 3 4 5 6 7 8 9 10).in_groups(3) { |group| result << ['foo'] + group + ['bar'] }
|
68
|
+
result.should == [
|
69
|
+
["foo", "1", "2", "3", "4", "bar"],
|
70
|
+
["foo", "5", "6", "7", nil, "bar"],
|
71
|
+
["foo", "8", "9", "10", nil, "bar"]
|
72
|
+
]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "split" do
|
77
|
+
it "should split array based on delimiting value" do
|
78
|
+
[1, 2, 3, 4, 5].split(3).should == [[1, 2], [4, 5]]
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should split array based on block result" do
|
82
|
+
(1..10).to_a.split { |i| i % 3 == 0 }.should == [[1, 2], [4, 5], [7, 8], [10]]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
describe 'array' do
|
2
|
+
describe "prepend" do
|
3
|
+
it "should add an element to the front of the array" do
|
4
|
+
[1, 2, 3].prepend(0).should == [0, 1, 2, 3]
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should change the array" do
|
8
|
+
array = [1, 2, 3]
|
9
|
+
array.prepend(0)
|
10
|
+
array.should == [0, 1, 2, 3]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "append" do
|
15
|
+
it "should add an element to the back of the array" do
|
16
|
+
[1, 2, 3].append(4).should == [1, 2, 3, 4]
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should change the array" do
|
20
|
+
array = [1, 2, 3]
|
21
|
+
array.append(4)
|
22
|
+
array.should == [1, 2, 3, 4]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
describe 'array' do
|
2
|
+
describe "wrap" do
|
3
|
+
it "should return empty array for nil" do
|
4
|
+
Array.wrap(nil).should == []
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should return unchanged array for array" do
|
8
|
+
Array.wrap([1, 2, 3]).should == [1, 2, 3]
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should not flatten multidimensional array" do
|
12
|
+
Array.wrap([[1], [2], [3]]).should == [[1], [2], [3]]
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should turn simple object into array" do
|
16
|
+
Array.wrap(0).should == [0]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
class CAttrAccessorBase
|
2
|
+
cattr_accessor :empty_accessor
|
3
|
+
cattr_accessor :base_accessor, :derived_accessor
|
4
|
+
end
|
5
|
+
|
6
|
+
class CAttrAccessorDerived < CAttrAccessorBase
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "class" do
|
10
|
+
describe "attribute accessors" do
|
11
|
+
before do
|
12
|
+
@class = Class.new
|
13
|
+
@class.instance_eval do
|
14
|
+
cattr_accessor :foo
|
15
|
+
cattr_accessor :bar, :instance_writer => false
|
16
|
+
cattr_reader :shaq, :instance_reader => false
|
17
|
+
cattr_accessor :camp, :instance_accessor => false
|
18
|
+
end
|
19
|
+
@object = @class.new
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "reader" do
|
23
|
+
it "should return nil by default" do
|
24
|
+
@class.foo.should.be.nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "writer" do
|
29
|
+
it "should set value" do
|
30
|
+
@class.foo = :test
|
31
|
+
@class.foo.should == :test
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should set value through instance writer" do
|
35
|
+
@object.foo = :bar
|
36
|
+
@object.foo.should == :bar
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should set instance reader's value through module's writer" do
|
40
|
+
@class.foo = :test
|
41
|
+
@object.foo.should == :test
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should set module reader's value through instances's writer" do
|
45
|
+
@object.foo = :bar
|
46
|
+
@class.foo.should == :bar
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "instance_writer => false" do
|
51
|
+
it "should not create instance writer" do
|
52
|
+
@class.should.respond_to :foo
|
53
|
+
@class.should.respond_to :foo=
|
54
|
+
@object.should.respond_to :bar
|
55
|
+
@object.should.not.respond_to :bar=
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "instance_reader => false" do
|
60
|
+
it "should not create instance reader" do
|
61
|
+
@class.should.respond_to :shaq
|
62
|
+
@object.should.not.respond_to :shaq
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "instance_accessor => false" do
|
67
|
+
it "should not create reader or writer" do
|
68
|
+
@class.should.respond_to :camp
|
69
|
+
@object.should.not.respond_to :camp
|
70
|
+
@object.should.not.respond_to :camp=
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "invalid attribute accessors" do
|
76
|
+
it "should raise NameError when creating an invalid reader" do
|
77
|
+
lambda do
|
78
|
+
Class.new do
|
79
|
+
cattr_reader "invalid attribute name"
|
80
|
+
end
|
81
|
+
end.should.raise NameError
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should raise NameError when creating an invalid writer" do
|
85
|
+
lambda do
|
86
|
+
Class.new do
|
87
|
+
cattr_writer "invalid attribute name"
|
88
|
+
end
|
89
|
+
end.should.raise NameError
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "inheritance" do
|
94
|
+
it "should be accessible in the base class and the derived class" do
|
95
|
+
CAttrAccessorBase.respond_to?(:empty_accessor).should == true
|
96
|
+
CAttrAccessorDerived.respond_to?(:empty_accessor).should == true
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should return nil for an unset accessor in the base class" do
|
100
|
+
CAttrAccessorBase.empty_accessor.should == nil
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should return nil for an unset accessor in the derived class" do
|
104
|
+
CAttrAccessorDerived.empty_accessor.should == nil
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should return a value for an accessor set in the base class in the base class" do
|
108
|
+
CAttrAccessorBase.base_accessor = 10
|
109
|
+
CAttrAccessorBase.base_accessor.should == 10
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should return a value for an accessor set in the base class in the derived class" do
|
113
|
+
CAttrAccessorBase.base_accessor = 10
|
114
|
+
CAttrAccessorDerived.base_accessor.should == 10
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should return a value for the base class if set for the derived class" do
|
118
|
+
CAttrAccessorDerived.derived_accessor = 20
|
119
|
+
CAttrAccessorBase.derived_accessor.should == 20
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should return a value for an accessor set in the derived class in the derived class" do
|
123
|
+
CAttrAccessorDerived.derived_accessor = 20
|
124
|
+
CAttrAccessorDerived.derived_accessor.should == 20
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|