extlib 0.9.8 → 0.9.9

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.

Potentially problematic release.


This version of extlib might be problematic. Click here for more details.

Files changed (54) hide show
  1. data/History.txt +22 -0
  2. data/LICENSE +1 -1
  3. data/README +0 -0
  4. data/Rakefile +17 -12
  5. data/lib/extlib.rb +1 -1
  6. data/lib/extlib/blank.rb +51 -21
  7. data/lib/extlib/boolean.rb +1 -1
  8. data/lib/extlib/class.rb +12 -12
  9. data/lib/extlib/datetime.rb +20 -2
  10. data/lib/extlib/dictionary.rb +2 -2
  11. data/lib/extlib/hash.rb +57 -34
  12. data/lib/extlib/inflection.rb +0 -1
  13. data/lib/extlib/lazy_array.rb +327 -36
  14. data/lib/extlib/logger.rb +8 -8
  15. data/lib/extlib/mash.rb +45 -45
  16. data/lib/extlib/module.rb +1 -1
  17. data/lib/extlib/nil.rb +1 -1
  18. data/lib/extlib/numeric.rb +1 -1
  19. data/lib/extlib/object.rb +8 -21
  20. data/lib/extlib/object_space.rb +3 -3
  21. data/lib/extlib/pathname.rb +10 -0
  22. data/lib/extlib/pooling.rb +9 -17
  23. data/lib/extlib/rubygems.rb +7 -7
  24. data/lib/extlib/simple_set.rb +35 -8
  25. data/lib/extlib/string.rb +85 -42
  26. data/lib/extlib/struct.rb +10 -1
  27. data/lib/extlib/symbol.rb +11 -7
  28. data/lib/extlib/time.rb +31 -9
  29. data/lib/extlib/version.rb +1 -1
  30. data/lib/extlib/virtual_file.rb +1 -1
  31. data/spec/blank_spec.rb +85 -0
  32. data/spec/class_spec.rb +141 -0
  33. data/spec/datetime_spec.rb +22 -0
  34. data/spec/hash_spec.rb +537 -0
  35. data/spec/hook_spec.rb +1198 -0
  36. data/spec/inflection/plural_spec.rb +564 -0
  37. data/spec/inflection/singular_spec.rb +497 -0
  38. data/spec/inflection_extras_spec.rb +93 -0
  39. data/spec/lazy_array_spec.rb +1869 -0
  40. data/spec/mash_spec.rb +286 -0
  41. data/spec/module_spec.rb +58 -0
  42. data/spec/object_space_spec.rb +9 -0
  43. data/spec/object_spec.rb +114 -0
  44. data/spec/pooling_spec.rb +499 -0
  45. data/spec/simple_set_spec.rb +57 -0
  46. data/spec/spec_helper.rb +7 -0
  47. data/spec/string_spec.rb +220 -0
  48. data/spec/struct_spec.rb +12 -0
  49. data/spec/symbol_spec.rb +8 -0
  50. data/spec/time_spec.rb +22 -0
  51. data/spec/try_dup_spec.rb +45 -0
  52. data/spec/virtual_file_spec.rb +21 -0
  53. metadata +51 -26
  54. data/README.txt +0 -3
@@ -0,0 +1,57 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Extlib::SimpleSet do
4
+
5
+ before do
6
+ @s = Extlib::SimpleSet.new("Initial")
7
+ end
8
+
9
+ describe "#initialize" do
10
+ it 'adds passed value to the set' do
11
+ @new_generation_vms = Extlib::SimpleSet.new(["Rubinius", "PyPy", "Parrot"])
12
+
13
+ @new_generation_vms.should have_key("Rubinius")
14
+ @new_generation_vms.should have_key("PyPy")
15
+ @new_generation_vms.should have_key("Parrot")
16
+ end
17
+ end
18
+
19
+ describe "#<<" do
20
+ it "adds value to the set" do
21
+ @s << "Hello"
22
+ @s.to_a.should include("Hello")
23
+ end
24
+
25
+ it 'sets true mark on the key' do
26
+ @s << "Fun"
27
+ @s["Fun"].should be(true)
28
+ end
29
+ end
30
+
31
+ describe "#merge(other)" do
32
+ it "preserves old values when values do not overlap" do
33
+ @s.should have_key("Initial")
34
+ end
35
+
36
+ it 'adds new values from merged set' do
37
+ @t = @s.merge(["Merged value"])
38
+ @t.should have_key("Merged value")
39
+ end
40
+
41
+ it 'returns a SimpleSet instance' do
42
+ @s.merge(["Merged value"]).should be_kind_of(Extlib::SimpleSet)
43
+ end
44
+ end
45
+
46
+ describe "#inspect" do
47
+ it "lists set values" do
48
+ @s.inspect.should == "#<SimpleSet: {\"Initial\"}>"
49
+ end
50
+ end
51
+
52
+ describe "#keys" do
53
+ it 'is aliased as to_a' do
54
+ @s.to_a.should === @s.keys
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,7 @@
1
+
2
+ $TESTING=true
3
+ require "rubygems"
4
+ require "spec"
5
+ require "yaml"
6
+
7
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'extlib')
@@ -0,0 +1,220 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
+
3
+ describe String, "#to_const_string" do
4
+ it "swaps slashes with ::" do
5
+ "foo/bar".to_const_string.should == "Foo::Bar"
6
+ end
7
+
8
+ it "replaces snake_case with CamelCase" do
9
+ "foo/bar/baz_bat".to_const_string.should == "Foo::Bar::BazBat"
10
+ end
11
+
12
+ it "leaves constant string as is" do
13
+ "Merb::Test".to_const_string.should == "Merb::Test"
14
+ end
15
+ end
16
+
17
+
18
+
19
+ describe String, "#to_const_path" do
20
+ it "swaps :: with slash" do
21
+ "Foo::Bar".to_const_path.should == "foo/bar"
22
+ end
23
+
24
+ it "snake_cases string" do
25
+ "Merb::Test::ViewHelper".to_const_path.should == "merb/test/view_helper"
26
+ end
27
+
28
+ it "leaves slash-separated snake case string as is" do
29
+ "merb/test/view_helper".to_const_path.should == "merb/test/view_helper"
30
+ end
31
+ end
32
+
33
+
34
+
35
+ describe String, "#camel_case" do
36
+ it "handles lowercase without underscore" do
37
+ "merb".camel_case.should == "Merb"
38
+ end
39
+
40
+ it "handles lowercase with 1 underscore" do
41
+ "merb_core".camel_case.should == "MerbCore"
42
+ end
43
+
44
+ it "handles lowercase with more than 1 underscore" do
45
+ "so_you_want_contribute_to_merb_core".camel_case.should == "SoYouWantContributeToMerbCore"
46
+ end
47
+
48
+ it "handles lowercase with more than 1 underscore in a row" do
49
+ "__python__is__like__this".camel_case.should == "PythonIsLikeThis"
50
+ end
51
+
52
+ it "handle first capital letter with underscores" do
53
+ "Python__Is__Like__This".camel_case.should == "PythonIsLikeThis"
54
+ end
55
+
56
+ it "leaves CamelCase as is" do
57
+ "TestController".camel_case.should == "TestController"
58
+ end
59
+ end
60
+
61
+
62
+
63
+ describe String, "#snake_case" do
64
+ it "lowercases one word CamelCase" do
65
+ "Merb".snake_case.should == "merb"
66
+ end
67
+
68
+ it "makes one underscore snake_case two word CamelCase" do
69
+ "MerbCore".snake_case.should == "merb_core"
70
+ end
71
+
72
+ it "handles CamelCase with more than 2 words" do
73
+ "SoYouWantContributeToMerbCore".snake_case.should == "so_you_want_contribute_to_merb_core"
74
+ end
75
+
76
+ it "handles CamelCase with more than 2 capital letter in a row" do
77
+ "CNN".snake_case.should == "cnn"
78
+ "CNNNews".snake_case.should == "cnn_news"
79
+ "HeadlineCNNNews".snake_case.should == "headline_cnn_news"
80
+ end
81
+
82
+ it "does NOT change one word lowercase" do
83
+ "merb".snake_case.should == "merb"
84
+ end
85
+
86
+ it "leaves snake_case as is" do
87
+ "merb_core".snake_case.should == "merb_core"
88
+ end
89
+ end
90
+
91
+
92
+
93
+ describe String, "#escape_regexp" do
94
+ it "escapes all * in a string" do
95
+ "*and*".escape_regexp.should == "\\*and\\*"
96
+ end
97
+
98
+ it "escapes all ? in a string" do
99
+ "?and?".escape_regexp.should == "\\?and\\?"
100
+ end
101
+
102
+ it "escapes all { in a string" do
103
+ "{and{".escape_regexp.should == "\\{and\\{"
104
+ end
105
+
106
+ it "escapes all } in a string" do
107
+ "}and}".escape_regexp.should == "\\}and\\}"
108
+ end
109
+
110
+ it "escapes all . in a string" do
111
+ ".and.".escape_regexp.should == "\\.and\\."
112
+ end
113
+
114
+ it "escapes all regexp special characters used in a string" do
115
+ "*?{}.".escape_regexp.should == "\\*\\?\\{\\}\\."
116
+ end
117
+ end
118
+
119
+
120
+
121
+ describe String, "#unescape_regexp" do
122
+ it "unescapes all \\* in a string" do
123
+ "\\*and\\*".unescape_regexp.should == "*and*"
124
+ end
125
+
126
+ it "unescapes all \\? in a string" do
127
+ "\\?and\\?".unescape_regexp.should == "?and?"
128
+ end
129
+
130
+ it "unescapes all \\{ in a string" do
131
+ "\\{and\\{".unescape_regexp.should == "{and{"
132
+ end
133
+
134
+ it "unescapes all \\} in a string" do
135
+ "\\}and\\}".unescape_regexp.should == "}and}"
136
+ end
137
+
138
+ it "unescapes all \\. in a string" do
139
+ "\\.and\\.".unescape_regexp.should == ".and."
140
+ end
141
+
142
+ it "unescapes all regexp special characters used in a string" do
143
+ "\\*\\?\\{\\}\\.".unescape_regexp.should == "*?{}."
144
+ end
145
+ end
146
+
147
+
148
+
149
+ describe String, "#/" do
150
+ it "concanates operands with File::SEPARATOR" do
151
+ ("merb" / "core").should == "merb#{File::SEPARATOR}core"
152
+ end
153
+ end
154
+
155
+
156
+ require 'rbconfig'
157
+ describe String, "#relative_path_from" do
158
+ it "uses other operand as base for path calculation" do
159
+ site_dir = Config::CONFIG["sitedir"]
160
+
161
+ two_levels_up = site_dir.split(File::SEPARATOR)
162
+ 2.times { two_levels_up.pop } # remove two deepest directories
163
+ two_levels_up = two_levels_up.join(File::SEPARATOR)
164
+
165
+ two_levels_up.relative_path_from(site_dir).should == "../.."
166
+ end
167
+ end
168
+
169
+
170
+ describe String, ".translate" do
171
+ before(:each) do
172
+ String.stub!(:translations).and_return({ "on snakes and rubies" => "a serpenti e rubini" })
173
+ end
174
+
175
+ it 'looks up for translation in translations dictionary' do
176
+ String.translate("on snakes and rubies").should == "a serpenti e rubini"
177
+ end
178
+
179
+ it 'returns string that has no translations as it is' do
180
+ String.translate("shapes").should == "shapes"
181
+ String.translate("kalopsia").should == "kalopsia"
182
+ String.translate("holding on to nothing").should == "holding on to nothing"
183
+ end
184
+ end
185
+
186
+ describe String, ".t" do
187
+ before(:each) do
188
+ String.stub!(:translations).and_return({ '%s must not be blank' => "%s moet ingevuld worden",
189
+ 'username' => 'gebruikersnaam',
190
+ '%s must be between %s and %s characters long' => '%s moet tussen %s en %s tekens lang zijn'})
191
+ end
192
+
193
+ it 'looks up for translation in translations dictionary and translates parameters as well' do
194
+ "%s must not be blank".t(:username).should == "gebruikersnaam moet ingevuld worden"
195
+ "%s must not be blank".t('username').should == "gebruikersnaam moet ingevuld worden"
196
+ "%s must be between %s and %s characters long".t(:password, 5, 9).should == "password moet tussen 5 en 9 tekens lang zijn"
197
+ end
198
+
199
+ it 'returns string that has no translations as it is' do
200
+ "password".t.should == "password"
201
+ end
202
+
203
+ it 'should not translate when freezed' do
204
+ "%s must not be blank".t('username'.freeze).should == "username moet ingevuld worden"
205
+ end
206
+ end
207
+
208
+ describe String, ".translations" do
209
+ before(:each) do
210
+
211
+ end
212
+
213
+ it 'returns empty hash by default' do
214
+ String.translations.should == {}
215
+ end
216
+
217
+ it 'returns @translations if set' do
218
+ pending "is it @translations on metaclass or @@translations? leaving it out for now"
219
+ end
220
+ end
@@ -0,0 +1,12 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
+
3
+ describe Struct do
4
+
5
+ it "should have attributes" do
6
+
7
+ s = Struct.new(:name).new('bob')
8
+ s.attributes.should == { :name => 'bob' }
9
+
10
+ end
11
+
12
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
+
3
+ describe Symbol, "#/" do
4
+ it "concanates operands with File::SEPARATOR" do
5
+ (:merb / "core").should == "merb#{File::SEPARATOR}core"
6
+ (:merb / :core).should == "merb#{File::SEPARATOR}core"
7
+ end
8
+ end
@@ -0,0 +1,22 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ require 'json'
3
+
4
+ describe Time, "#to_json" do
5
+
6
+ before do
7
+ @expected = "\"2008-03-28T22:54:20Z\""
8
+ end
9
+
10
+ it "should transform itself into a ISO 8601 compatible string" do
11
+ Time.utc(2008, 3, 28, 22, 54, 20).to_json.should == @expected
12
+ Time.xmlschema("2008-03-28T22:54:20Z").to_json.should == @expected
13
+ Time.xmlschema("2008-03-28T17:54:20-05:00").to_json.should == @expected
14
+ end
15
+ end
16
+
17
+ describe Time, "#to_time" do
18
+ it "should return a copy of its self" do
19
+ time = Time.now
20
+ time.to_time.should == time
21
+ end
22
+ end
@@ -0,0 +1,45 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
+
3
+ describe "try_dup" do
4
+ it "returns a duplicate version on regular objects" do
5
+ obj = Object.new
6
+ oth = obj.try_dup
7
+ obj.should_not === oth
8
+ end
9
+
10
+ it "returns self on Numerics" do
11
+ obj = 12
12
+ oth = obj.try_dup
13
+ obj.should === oth
14
+ end
15
+
16
+ it "returns self on Symbols" do
17
+ obj = :test
18
+ oth = obj.try_dup
19
+ obj.should === oth
20
+ end
21
+
22
+ it "returns self on true" do
23
+ obj = true
24
+ oth = obj.try_dup
25
+ obj.should === oth
26
+ end
27
+
28
+ it "returns self on false" do
29
+ obj = false
30
+ oth = obj.try_dup
31
+ obj.should === oth
32
+ end
33
+
34
+ it "returns self on nil" do
35
+ obj = nil
36
+ oth = obj.try_dup
37
+ obj.should === oth
38
+ end
39
+
40
+ it "returns self on modules" do
41
+ obj = Extlib
42
+ oth = obj.try_dup
43
+ obj.object_id.should == oth.object_id
44
+ end
45
+ end
@@ -0,0 +1,21 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
+
3
+ describe VirtualFile do
4
+ it 'inherits from StringIO' do
5
+ VirtualFile.superclass.should == StringIO
6
+ end
7
+
8
+ it 'has path reader' do
9
+ @vf = VirtualFile.new("virtual", "elvenpath")
10
+
11
+ # =~ /#{Dir::tmpdir}/ causes RegExp to fail with nested *?+ on 1.8.6
12
+ @vf.path.should == "elvenpath"
13
+ end
14
+
15
+ it 'has path writer' do
16
+ @vf = VirtualFile.new("virtual", "elvenpath")
17
+
18
+ @vf.path = "newbase"
19
+ @vf.path.should == "newbase"
20
+ end
21
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: extlib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8
4
+ version: 0.9.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Smoot
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-10-12 00:00:00 -06:00
12
+ date: 2008-12-07 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -21,42 +21,67 @@ extensions: []
21
21
 
22
22
  extra_rdoc_files:
23
23
  - LICENSE
24
- - README.txt
24
+ - README
25
+ - History.txt
25
26
  files:
26
27
  - LICENSE
27
- - README.txt
28
+ - README
28
29
  - Rakefile
29
- - lib/extlib.rb
30
+ - History.txt
30
31
  - lib/extlib
31
- - lib/extlib/dictionary.rb
32
- - lib/extlib/lazy_array.rb
33
- - lib/extlib/nil.rb
34
- - lib/extlib/class.rb
35
- - lib/extlib/rubygems.rb
36
- - lib/extlib/module.rb
37
- - lib/extlib/string.rb
38
- - lib/extlib/hook.rb
32
+ - lib/extlib/assertions.rb
39
33
  - lib/extlib/blank.rb
40
- - lib/extlib/logger.rb
34
+ - lib/extlib/boolean.rb
35
+ - lib/extlib/class.rb
41
36
  - lib/extlib/datetime.rb
42
- - lib/extlib/assertions.rb
37
+ - lib/extlib/dictionary.rb
38
+ - lib/extlib/hash.rb
39
+ - lib/extlib/hook.rb
43
40
  - lib/extlib/inflection.rb
44
- - lib/extlib/pathname.rb
45
- - lib/extlib/object_space.rb
41
+ - lib/extlib/lazy_array.rb
42
+ - lib/extlib/logger.rb
46
43
  - lib/extlib/mash.rb
47
- - lib/extlib/virtual_file.rb
48
- - lib/extlib/simple_set.rb
49
- - lib/extlib/object.rb
50
- - lib/extlib/hash.rb
51
- - lib/extlib/version.rb
52
- - lib/extlib/boolean.rb
53
- - lib/extlib/symbol.rb
44
+ - lib/extlib/module.rb
45
+ - lib/extlib/nil.rb
54
46
  - lib/extlib/numeric.rb
55
- - lib/extlib/struct.rb
47
+ - lib/extlib/object.rb
48
+ - lib/extlib/object_space.rb
49
+ - lib/extlib/pathname.rb
56
50
  - lib/extlib/pooling.rb
51
+ - lib/extlib/rubygems.rb
52
+ - lib/extlib/simple_set.rb
53
+ - lib/extlib/string.rb
54
+ - lib/extlib/struct.rb
55
+ - lib/extlib/symbol.rb
57
56
  - lib/extlib/tasks
58
57
  - lib/extlib/tasks/release.rb
59
58
  - lib/extlib/time.rb
59
+ - lib/extlib/version.rb
60
+ - lib/extlib/virtual_file.rb
61
+ - lib/extlib.rb
62
+ - spec/blank_spec.rb
63
+ - spec/class_spec.rb
64
+ - spec/datetime_spec.rb
65
+ - spec/hash_spec.rb
66
+ - spec/hook_spec.rb
67
+ - spec/inflection
68
+ - spec/inflection/plural_spec.rb
69
+ - spec/inflection/singular_spec.rb
70
+ - spec/inflection_extras_spec.rb
71
+ - spec/lazy_array_spec.rb
72
+ - spec/mash_spec.rb
73
+ - spec/module_spec.rb
74
+ - spec/object_space_spec.rb
75
+ - spec/object_spec.rb
76
+ - spec/pooling_spec.rb
77
+ - spec/simple_set_spec.rb
78
+ - spec/spec_helper.rb
79
+ - spec/string_spec.rb
80
+ - spec/struct_spec.rb
81
+ - spec/symbol_spec.rb
82
+ - spec/time_spec.rb
83
+ - spec/try_dup_spec.rb
84
+ - spec/virtual_file_spec.rb
60
85
  has_rdoc: false
61
86
  homepage: http://extlib.rubyforge.org
62
87
  post_install_message:
@@ -79,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
104
  requirements: []
80
105
 
81
106
  rubyforge_project:
82
- rubygems_version: 1.2.0
107
+ rubygems_version: 1.3.1
83
108
  signing_key:
84
109
  specification_version: 2
85
110
  summary: Support library for DataMapper and Merb.